BrightSide Workbench Full Report + Source Code
FuzzyRelationTypes.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.contacts.relation;
20 
21 import org.turro.contacts.BusinessRelation;
22 import org.turro.contacts.ContactType;
23 import org.turro.contacts.organigram.RelationType;
24 import org.turro.elephant.db.WhereClause;
25 
30 public class FuzzyRelationTypes {
31 
32  public static boolean isWorker(BusinessRelation relation) {
33  return isProfessional(relation) || isEducator(relation);
34  }
35 
36  public static void isWorker(WhereClause wc, String separator, String relationField) {
37  wc.addClause(separator + " (");
38  isProfessional(wc, "", relationField);
39  isEducator(wc, "or", relationField);
40  wc.addClause(")");
41  }
42 
43  public static boolean isProfessional(BusinessRelation relation) {
44  return !relation.isEmpty() && ContactType.CONTACT_COMPANY.equals(relation.getBusiness().getType());
45  }
46 
47  public static void isProfessional(WhereClause wc, String separator, String relationField) {
48  wc.addClause(separator + " (");
49  wc.addClause(relationField + ".business.type = :wtype");
51  wc.addClause(")");
52  }
53 
54  public static boolean isEducator(BusinessRelation relation) {
55  return !relation.isEmpty() && (
56  (ContactType.CONTACT_LEARNINGCENTER.equals(relation.getBusiness().getType()) &&
57  !RelationType.REL_STAFF.getRelationKey().equals(relation.getRelationType())));
58  }
59 
60  public static void isEducator(WhereClause wc, String separator, String relationField) {
61  wc.addClause(separator + " (");
62  wc.addClause(relationField + ".business.type = :stype");
64  wc.addClause("and " + relationField +".relationType <> :brtype");
65  wc.addNamedValue("brtype", RelationType.REL_STAFF.getRelationKey());
66  wc.addClause(")");
67  }
68 
69  public static boolean isStudent(BusinessRelation relation) {
70  return !relation.isEmpty() &&
72  RelationType.REL_STAFF.getRelationKey().equals(relation.getRelationType());
73  }
74 
75  public static void isStudent(WhereClause wc, String separator, String relationField) {
76  wc.addClause(separator + " (");
77  wc.addClause(relationField + ".business.type = :stype");
79  wc.addClause("and " + relationField +".relationType = :brtype");
80  wc.addNamedValue("brtype", RelationType.REL_STAFF.getRelationKey());
81  wc.addClause(")");
82  }
83 
84  public static boolean isStaff(BusinessRelation relation) {
85  return !relation.isEmpty() &&
86  (ContactType.CONTACT_COMPANY.equals(relation.getBusiness().getType()) ||
87  ContactType.CONTACT_LEARNINGCENTER.equals(relation.getBusiness().getType())) &&
88  RelationType.REL_STAFF.getRelationKey().equals(relation.getRelationType());
89  }
90 
91  public static boolean isResponsible(BusinessRelation relation) {
92  return !relation.isEmpty() &&
93  (ContactType.CONTACT_COMPANY.equals(relation.getBusiness().getType()) ||
94  ContactType.CONTACT_LEARNINGCENTER.equals(relation.getBusiness().getType())) &&
95  !RelationType.REL_STAFF.getRelationKey().equals(relation.getRelationType());
96  }
97 
98  public static boolean isHHRR(BusinessRelation relation) {
99  return !relation.isEmpty() &&
100  (ContactType.CONTACT_COMPANY.equals(relation.getBusiness().getType()) ||
101  ContactType.CONTACT_LEARNINGCENTER.equals(relation.getBusiness().getType())) &&
102  RelationType.REL_HHRR.getRelationKey().equals(relation.getRelationType());
103  }
104 
105  public static void isHHRR(WhereClause wc, String separator, String relationField) {
106  wc.addClause(separator + " ((");
107  wc.addClause(relationField + ".business.type = :stype");
109  wc.addClause("or " + relationField + ".business.type = :ctype");
111  wc.addClause(")");
112  wc.addClause("and " + relationField +".relationType = :brtype");
113  wc.addNamedValue("brtype", RelationType.REL_HHRR.getRelationKey());
114  wc.addClause(")");
115  }
116 
117  public static void isSingleton(WhereClause wc, String separator, String contactField, String relationField) {
118  wc.addClause(separator + " (" + relationField + " is null");
119  wc.addClause("and (" + contactField + ".type = :sgtype or " + contactField + ".type = :sitype))");
120  wc.addNamedValue("sgtype", ContactType.CONTACT_USER);
122  }
123 
124  public static void isTyped(WhereClause wc, String separator, String relationField) {
125  wc.addClause(separator + " (");
126  wc.addClause(relationField + ".contact.type = :wtype");
128  wc.addClause("or");
129  wc.addClause(relationField + ".contact.type = :stype");
131  wc.addClause("or");
132  wc.addClause(relationField + ".business.type = :wtype");
133  wc.addClause("or");
134  wc.addClause(relationField + ".business.type = :stype");
135  wc.addClause(")");
136  }
137 
138  public static void isJuridical(WhereClause wc, String separator, String relationField) {
139  wc.addClause(separator + " (");
140  wc.addClause(relationField + ".type = :wtype");
142  wc.addClause("or");
143  wc.addClause(relationField + ".type = :stype");
145  wc.addClause(")");
146  }
147 
148  public static void isNatural(WhereClause wc, String separator, String relationField) {
149  wc.addClause(separator + " (");
150  wc.addClause(relationField + ".business.type = :wtype");
152  wc.addClause("or");
153  wc.addClause(relationField + ".business.type = :stype");
155  wc.addClause(")");
156  }
157 
158 }
static boolean isStudent(BusinessRelation relation)
static boolean isResponsible(BusinessRelation relation)
static boolean isStaff(BusinessRelation relation)
static void isWorker(WhereClause wc, String separator, String relationField)
static void isProfessional(WhereClause wc, String separator, String relationField)
static void isStudent(WhereClause wc, String separator, String relationField)
static boolean isEducator(BusinessRelation relation)
static void isTyped(WhereClause wc, String separator, String relationField)
static boolean isHHRR(BusinessRelation relation)
static void isJuridical(WhereClause wc, String separator, String relationField)
static void isHHRR(WhereClause wc, String separator, String relationField)
static void isNatural(WhereClause wc, String separator, String relationField)
static void isEducator(WhereClause wc, String separator, String relationField)
static void isSingleton(WhereClause wc, String separator, String contactField, String relationField)
static boolean isWorker(BusinessRelation relation)
static boolean isProfessional(BusinessRelation relation)
void addNamedValue(String name, Object value)