19 package org.turro.contacts.duplicates;
21 import java.util.List;
22 import java.util.TreeSet;
23 import org.turro.string.Phrases;
24 import org.turro.contacts.Address;
25 import org.turro.contacts.Connector;
26 import org.turro.contacts.Contact;
27 import org.turro.contacts.db.ContactsPU;
28 import org.turro.i18n.I_;
29 import org.turro.jpa.Dao;
30 import org.turro.plugin.contacts.IContact;
31 import org.turro.sql.SqlClause;
32 import org.turro.string.Strings;
33 import org.turro.util.Cached;
44 this.contact = contact;
45 if(contact !=
null) performChecks();
52 private void performChecks() {
59 private void checkGlobalID() {
61 List<String> contacts = SqlClause.select(
"c.name").from(
"Contact c")
62 .where().notEqual(
"c.globalIdentifier",
null)
64 .startIf(!contact.
isNew())
65 .and().notEqual(
"c", contact)
68 .resultList(String.class);
69 if(!contacts.isEmpty()) {
70 Duplicated duplicated =
new Duplicated(Duplicated.DuplicatedType.STOPPER,
72 duplicated.setContacts(contacts);
77 private void checkName() {
78 List<String> contacts = SqlClause.select(
"c.name").from(
"Contact c")
79 .where().equal(
"c.name", contact.
getName())
80 .startIf(!contact.
isNew())
81 .and().notEqual(
"c", contact)
84 .resultList(String.class);
85 if(!contacts.isEmpty()) {
86 Duplicated duplicated =
new Duplicated(Duplicated.DuplicatedType.WARNING,
87 I_.get(
"Name"), contact.
getName());
88 duplicated.setConsequence(I_.get(
"These users will be difficult to spot"));
89 duplicated.setContacts(contacts);
94 private void checkConnectors() {
96 if(connector !=
null) {
97 List<String> contacts = SqlClause.select(
"c.contact.name").from(
"Connector c")
98 .where().equal(
"c.description", connector.getDescription())
99 .and().equal(
"c.value", connector.getValue())
100 .startIf(!contact.
isNew())
101 .and().notEqual(
"c.contact", contact)
104 .resultList(String.class);
105 if(!contacts.isEmpty()) {
106 if(connector.getDescription().equals(IContact.CONNECTOR_EMAIL)) {
107 Duplicated duplicated =
new Duplicated(Duplicated.DuplicatedType.WARNING,
108 Phrases.start(I_.get(
"Connector"),
":", connector.getDescription()).toString(),
109 connector.getValue());
110 duplicated.setConsequence(I_.get(
"These users wont be able to authenticate"));
111 duplicated.setContacts(contacts);
113 }
else if(connector.getDescription().equals(IContact.CONNECTOR_TRADE)) {
114 Duplicated duplicated =
new Duplicated(Duplicated.DuplicatedType.WARNING,
115 Phrases.start(I_.get(
"Connector"),
":", connector.getDescription()).toString(),
116 connector.getValue());
117 duplicated.setConsequence(I_.get(
"These users have the same trademark"));
118 duplicated.setContacts(contacts);
120 }
else if(connector.getDescription().equals(IContact.CONNECTOR_FISCAL)) {
121 Duplicated duplicated =
new Duplicated(Duplicated.DuplicatedType.WARNING,
122 Phrases.start(I_.get(
"Connector"),
":", connector.getDescription()).toString(),
123 connector.getValue());
124 duplicated.setConsequence(I_.get(
"These users have the same fiscal name"));
125 duplicated.setContacts(contacts);
128 Duplicated duplicated =
new Duplicated(Duplicated.DuplicatedType.SAFE,
129 Phrases.start(I_.get(
"Connector"),
":", connector.getDescription()).toString(),
130 connector.getValue());
131 duplicated.setContacts(contacts);
139 private void checkAddreses() {
141 if(address !=
null) {
142 List<String> contacts = SqlClause.select(
"c.contact.name").from(
"Address c")
143 .where().equal(
"c.street", address.getStreet())
144 .and().equal(
"c.zipCode", address.getZipCode())
145 .and().equal(
"c.city", address.getCity())
146 .startIf(!contact.
isNew())
147 .and().notEqual(
"c.contact", contact)
150 .resultList(String.class);
151 if(!contacts.isEmpty()) {
152 if(address.getDescription().equals(IContact.ADDRESS_FISCAL)) {
153 Duplicated duplicated =
new Duplicated(Duplicated.DuplicatedType.WARNING,
154 Phrases.start(I_.get(
"Address"),
":", address.getDescription()).toString(),
155 address.getAddressString());
156 duplicated.setConsequence(I_.get(
"These users have the same fiscal address"));
157 duplicated.setContacts(contacts);
160 Duplicated duplicated =
new Duplicated(Duplicated.DuplicatedType.SAFE,
161 Phrases.start(I_.get(
"Address"),
":", address.getDescription()).toString(),
162 address.getAddressString());
163 duplicated.setContacts(contacts);
171 private final Cached<Dao> dao = Cached.instance(() ->
new ContactsPU());
static String get(String msg)