19 package org.turro.contacts.profile;
21 import java.util.stream.Stream;
22 import org.turro.contacts.BusinessRelation;
23 import org.turro.contacts.Connector;
24 import org.turro.contacts.Contact;
25 import org.turro.contacts.db.ContactsPU;
26 import org.turro.jpa.Dao;
27 import org.turro.jpa.DaoUtil;
28 import org.turro.www.directory.EditDataControl;
38 if(migration.isNecessary()) {
43 private boolean isNecessary() {
51 private void start() {
53 try(Stream<Connector> connectors =
new ContactsPU().stream(
Connector.class,
"select c from Connector c")) {
54 connectors.forEach((connector) -> {
55 if(EditDataControl.PHONE_DIRECTORY.equals(connector.getDescription())) {
56 Connector con = new Connector();
57 con.setContact(connector.getContact());
58 con.setDescription(Profile.PHONE);
59 con.setValue(connector.getValue());
60 con.setOnlyOwner(false);
61 saveIfDontExists(dao, con);
62 }
else if(EditDataControl.NETWORK_DIRECTORY.equals(connector.getDescription())) {
63 Connector con = new Connector();
64 con.setContact(connector.getContact());
65 con.setDescription(Profile.NETWORK);
66 con.setValue(connector.getValue());
67 con.setOnlyOwner(false);
68 saveIfDontExists(dao, con);
69 }
else if(EditDataControl.POSITION_DIRECTORY.equals(connector.getDescription())) {
70 Contact c = connector.getContact();
71 if(c.getBusinessRelations().size() == 1) {
72 BusinessRelation br = c.getBusinessRelations().iterator().next();
73 br.setDescription(connector.getValue());
81 private void saveIfDontExists(Dao dao, Connector con) {
82 if(DaoUtil.isEmpty(dao,
"Connector",
"where x.description = ? and x.contact = ?", con.getDescription(), con.getContact())) {
static boolean isEmpty(Dao dao, String table)