19 package org.turro.contacts.relation;
21 import java.util.stream.Stream;
22 import org.turro.string.Strings;
23 import org.turro.contacts.BusinessRelation;
24 import org.turro.contacts.Contact;
25 import org.turro.contacts.ContactType;
26 import org.turro.contacts.Relation;
27 import org.turro.contacts.db.ContactsPU;
28 import org.turro.jpa.Dao;
29 import org.turro.jpa.DaoUtil;
39 if(migration.isNecessary()) {
45 private boolean isNecessary() {
50 private void start() {
52 try(Stream<Relation> relations =
new ContactsPU().stream(
Relation.class,
"select r from Relation r")) {
53 relations.forEach((relation) -> {
54 if(Strings.isBlank(relation.getRelationType()) || !relation.getRelationType().startsWith(
"$INT_")) {
55 BusinessRelation br = new BusinessRelation();
56 br.setId(relation.getId());
57 br.setContact(relation.getContact1());
58 br.setBusiness(relation.getContact2());
59 br.setRelationType(relation.getRelationType());
60 br.setDescription(relation.getDescription());
61 br.setPreferential(relation.isPreferential());
62 br.setValidated(true);
69 private static void qualifyCompanies() {
70 Dao dao =
new ContactsPU();
71 try(Stream<BusinessRelation> relations =
new ContactsPU().stream(BusinessRelation.class,
72 "select r from BusinessRelation r")) {
73 relations.forEach((relation) -> {
74 Contact business = relation.getBusiness();
75 if(ContactType.CONTACT_USER.equals(business.getType())) {
76 business.setType(ContactType.CONTACT_COMPANY);
77 dao.saveObject(business);
static boolean isEmpty(Dao dao, String table)