BrightSide Workbench Full Report + Source Code
org.turro.contacts.util.RelationUtil Class Reference

Static Public Member Functions

static void addRelation (Contact business, Contact contact, String relation)
 
static void addRelation (String business, String contact, String relation)
 
static void addRelations (Collection< BusinessRelation > relations)
 
static void killRelation (Contact business, Contact contact, String relation)
 
static void killRelation (String business, String contact, String relation)
 
static void killRelations (String like)
 
static void setPreferentialRelation ()
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 36 of file RelationUtil.java.

Member Function Documentation

◆ addRelation() [1/2]

static void org.turro.contacts.util.RelationUtil.addRelation ( Contact  business,
Contact  contact,
String  relation 
)
static

Definition at line 38 of file RelationUtil.java.

38  {
39  if(business != null && contact != null && !Strings.isBlank(relation)) {
40  Dao dao = new ContactsPU();
41  WhereClause wc = new WhereClause();
42  wc.addClause("select r from BusinessRelation as r");
43  wc.addClause("where r.contact = :c1");
44  wc.addNamedValue("c1", contact);
45  wc.addClause("and r.business = :c2");
46  wc.addNamedValue("c2", business);
47  wc.addClause("and r.relationType = :pr");
48  wc.addNamedValue("pr", relation);
49  List<BusinessRelation> relations = dao.getResultList(wc);
50  if(relations.isEmpty()) {
51  BusinessRelation r = new BusinessRelation();
52  r.setContact(contact);
53  r.setBusiness(business);
54  r.setRelationType(relation);
55  dao.saveObject(r);
56  }
57  }
58  }
Here is the call graph for this function:

◆ addRelation() [2/2]

static void org.turro.contacts.util.RelationUtil.addRelation ( String  business,
String  contact,
String  relation 
)
static

Definition at line 60 of file RelationUtil.java.

60  {
61  if(business != null && contact != null && !Strings.isBlank(relation)) {
62  Dao dao = new ContactsPU();
63  WhereClause wc = new WhereClause();
64  wc.addClause("select r from BusinessRelation as r");
65  wc.addClause("where r.contact.id = :c1");
66  wc.addNamedValue("c1", contact);
67  wc.addClause("and r.business.id = :c2");
68  wc.addNamedValue("c2", business);
69  wc.addClause("and r.relationType = :pr");
70  wc.addNamedValue("pr", relation);
71  List<BusinessRelation> relations = dao.getResultList(wc);
72  if(relations.isEmpty()) {
73  BusinessRelation r = new BusinessRelation();
74  r.setContact(dao.find(Contact.class, contact));
75  r.setBusiness(dao.find(Contact.class, business));
76  r.setRelationType(relation);
77  if(r.getContact() != null && r.getBusiness()!= null) {
78  dao.saveObject(r);
79  }
80  }
81  }
82  }
Here is the call graph for this function:

◆ addRelations()

static void org.turro.contacts.util.RelationUtil.addRelations ( Collection< BusinessRelation relations)
static

Definition at line 84 of file RelationUtil.java.

84  {
85  Dao dao = new ContactsPU();
86  dao.saveCollection(relations);
87  }
Here is the call graph for this function:

◆ killRelation() [1/2]

static void org.turro.contacts.util.RelationUtil.killRelation ( Contact  business,
Contact  contact,
String  relation 
)
static

Definition at line 89 of file RelationUtil.java.

89  {
90  if(business != null && contact != null && !Strings.isBlank(relation)) {
91  Dao dao = new ContactsPU();
92  WhereClause wc = new WhereClause();
93  wc.addClause("delete from BusinessRelation as r");
94  wc.addClause("where r.contact = :c1");
95  wc.addNamedValue("c1", contact);
96  wc.addClause("and r.business = :c2");
97  wc.addNamedValue("c2", business);
98  wc.addClause("and r.relationType = :pr");
99  wc.addNamedValue("pr", relation);
100  dao.executeUpdate(wc);
101  }
102  }
Here is the call graph for this function:

◆ killRelation() [2/2]

static void org.turro.contacts.util.RelationUtil.killRelation ( String  business,
String  contact,
String  relation 
)
static

Definition at line 104 of file RelationUtil.java.

104  {
105  if(business != null && contact != null && !Strings.isBlank(relation)) {
106  Dao dao = new ContactsPU();
107  WhereClause wc = new WhereClause();
108  wc.addClause("delete from BusinessRelation as r");
109  wc.addClause("where r.contact.id = :c1");
110  wc.addNamedValue("c1", contact);
111  wc.addClause("and r.business.id = :c2");
112  wc.addNamedValue("c2", business);
113  wc.addClause("and r.relationType = :pr");
114  wc.addNamedValue("pr", relation);
115  dao.executeUpdate(wc);
116  }
117  }
Here is the call graph for this function:

◆ killRelations()

static void org.turro.contacts.util.RelationUtil.killRelations ( String  like)
static

Definition at line 119 of file RelationUtil.java.

119  {
120  if(!Strings.isBlank(like)) {
121  Dao dao = new ContactsPU();
122  WhereClause wc = new WhereClause();
123  wc.addClause("delete from BusinessRelation as r");
124  wc.addClause("where r.relationType like :pr");
125  wc.addNamedValue("pr", like);
126  dao.executeUpdate(wc);
127  }
128  }
Here is the call graph for this function:

◆ setPreferentialRelation()

static void org.turro.contacts.util.RelationUtil.setPreferentialRelation ( )
static

Definition at line 130 of file RelationUtil.java.

130  {
131  try(Stream<Contact> contacts = new ContactsPU().stream(Contact.class, "select c from Contact c")) {
132  contacts.forEach((contact) -> {
133  if(contact.getBusiness() == null) {
134  for(BusinessRelation relation : contact.getBusinessRelations()) {
135  if(!Strings.isBlank(relation.getRelationType()) && relation.getRelationType().startsWith("$REL_")) {
136  new ContactsPU().executeUpdate(
137  "update BusinessRelation set preferential = TRUE where identifier = ?",
138  new Object[] { relation.getId() }
139  );
140  break;
141  }
142  }
143  }
144  });
145  }
146  }

The documentation for this class was generated from the following file: