19 package org.turro.vcard;
21 import java.util.List;
22 import org.turro.contacts.BusinessRelation;
23 import org.turro.contacts.Contact;
24 import org.turro.contacts.db.ContactsPU;
25 import org.turro.csv.CSVEntry;
26 import org.turro.jpa.Dao;
34 private CSVEntry entry;
42 Contact main =
null, related =
null;
43 String header = entry.getList().getHeader().getHeader(
"GID-MAIN");
45 String value = entry.getField(header);
46 main = contactByGID(dao, value);
49 header = entry.getList().getHeader().getPrefixHeader(
"ID-MAIN");
51 String prefixValue =
null;
52 if(header.length() >
"ID-MAIN".length()) {
53 prefixValue = header.substring(
"ID-MAIN".length() + 1);
55 String value = prefixValue ==
null ? entry.getField(header) :
56 entry.getField(header).substring(prefixValue.length());
57 main = contactByConnector(dao,
"ID", value);
60 header = entry.getList().getHeader().getPrefixHeader(
"CONNECTOR-REL");
62 String connector =
null;
63 if(header.length() >
"CONNECTOR-REL".length()) {
64 connector = header.substring(
"CONNECTOR-REL".length() + 1);
66 String value = entry.getField(header);
67 related = contactByConnector(dao, connector, value);
69 if(main !=
null && related !=
null) {
70 header = entry.getList().getHeader().getHeader(
"RELATION");
72 String value = entry.getField(header);
77 dao.saveObject(relation);
82 private Contact contactByGID(
Dao dao, String value) {
83 List l = dao.getResultList(
84 "select c from Contact c where c.globalIdentifier = ?",
85 new Object[] { value });
86 if(l !=
null && l.size() > 0) {
87 return (Contact) l.iterator().next();
92 private Contact contactByConnector(Dao dao, String connector, String value) {
93 List l = dao.getResultList(
94 "select distinct c.contact from Connector c where c.description = ? and c.value = ?",
95 new Object[] { connector, value });
96 if(l !=
null && l.size() > 0) {
97 return (Contact) l.iterator().next();
CSVToRelation(CSVEntry v)