19 package org.turro.contacts.importer;
21 import java.util.List;
23 import java.util.Objects;
24 import org.turro.contacts.Contact;
25 import org.turro.contacts.ContactType;
26 import org.turro.contacts.db.ContactsPU;
27 import org.turro.contacts.organigram.RelationType;
28 import org.turro.jpa.Dao;
29 import org.turro.plugin.contacts.IContact;
30 import org.turro.sql.SqlClause;
31 import org.turro.util.Cached;
39 private final String email, name, relatedTo;
40 private String position;
42 private Contact contact, possibleRelated;
43 private boolean duplicated;
45 public ImporterEntry(String email, String name, String relatedTo, String position) {
48 this.relatedTo = relatedTo;
49 this.position = position;
71 this.position = position;
91 this.contact = contact;
95 return possibleRelated;
99 this.possibleRelated = possibleRelated;
103 return contact ==
null ? name : contact.
getName();
112 private void solve() {
113 List<Contact> found = findEmail();
114 if(found.size() > 1) {
117 }
else if(found.size() == 1) {
118 contact = found.get(0);
120 List<Contact> related = findRelated();
121 if(!related.isEmpty()) {
122 possibleRelated = related.get(0);
126 private List<Contact> findEmail() {
127 return SqlClause.select(
"c.contact").from(
"Connector c")
128 .where().equal(
"c.value", email)
129 .and().equal(
"c.description", IContact.CONNECTOR_EMAIL)
131 .resultList(Contact.class);
134 private List<Contact> findRelated() {
135 return SqlClause.select(
"c").from(
"Contact c")
136 .where().equal(
"c.name", relatedTo)
137 .and().in(
"c.type", List.of(
138 ContactType.CONTACT_COMPANY,
139 ContactType.CONTACT_LEARNINGCENTER))
141 .resultList(Contact.class);
146 private final Cached<Dao> dao = Cached.instance(() ->
new ContactsPU());
151 return new ImporterEntry(values.get(
"email"), values.get(
"name"),
152 values.get(
"relatedTo"), values.get(
"position"));
160 hash = 53 * hash + Objects.hashCode(this.email);
172 if (getClass() != obj.getClass()) {
176 return Objects.
equals(this.email, other.email);
void setPossibleRelated(Contact possibleRelated)
void setType(RelationType type)
void setContact(Contact contact)
static ImporterEntry from(Map< String, String > values)
boolean equals(Object obj)
void setPosition(String position)
ImporterEntry(String email, String name, String relatedTo, String position)
Contact getPossibleRelated()