19 package org.turro.visual;
21 import java.util.HashSet;
22 import java.util.Objects;
23 import org.turro.string.Strings;
24 import org.turro.i18n.I_;
25 import org.turro.plugin.contacts.IContact;
26 import org.turro.script.Script;
27 import org.turro.script.Scripting;
28 import org.turro.util.CompareUtil;
36 private String name, label, role, eval;
38 private HashSet<String> syndications, groupings,
39 businessSyndications, businessGroupings;
40 private Boolean visitor, admin, worker, student, hhrr;
41 private F subElements;
43 private final transient F factory;
44 private transient V parent;
46 private transient Script script;
50 this.factory = factory;
82 return dve ==
null || dve.
check(entity, contact);
123 this.worker = worker;
128 this.student = student;
138 this.visitor = visitor;
143 if(syndications ==
null) {
144 syndications =
new HashSet<>();
146 syndications.add(syndication);
151 if(groupings ==
null) {
152 groupings =
new HashSet<>();
154 groupings.add(grouping);
159 if(businessSyndications ==
null) {
160 businessSyndications =
new HashSet<>();
162 businessSyndications.add(syndication);
167 if(businessGroupings ==
null) {
168 businessGroupings =
new HashSet<>();
170 businessGroupings.add(grouping);
175 if(subElements ==
null) {
176 subElements = (F) factory.createSubElements();
178 V v = (V) factory.createElement(name);
180 return subElements.add(v) ? v :
null;
189 business = (business !=
null && business.
isValid()) ? business :
null;
192 checkSyndications(contact) ||
193 checkGroupings(contact) ||
194 checkBusinessSyndications(business) ||
195 checkBusinessGroupings(business) ||
196 checkRoles(contact) ||
203 return eval ==
null && role ==
null && syndications ==
null && groupings ==
null &&
204 businessSyndications ==
null && businessGroupings ==
null &&
205 admin ==
null && worker ==
null && student ==
null && hhrr ==
null;
210 getScript().addVariable(
"user", contact);
216 private boolean checkSyndications(
IContact contact) {
217 if(syndications !=
null) {
219 if(syndications.contains(syndication)) {
227 private boolean checkGroupings(IContact contact) {
228 if(groupings !=
null) {
229 if(groupings.contains(contact.getGrouping())) {
236 private boolean checkBusinessSyndications(IContact business) {
237 if(business !=
null && businessSyndications !=
null) {
238 for(String syndication : business.getSyndications()) {
239 if(businessSyndications.contains(syndication)) {
247 private boolean checkBusinessGroupings(IContact business) {
248 if(business !=
null && businessGroupings !=
null) {
249 if(businessGroupings.contains(business.getGrouping())) {
256 private boolean checkRoles(IContact contact) {
268 return contact !=
null && contact.
isValid();
272 return value ==
null || value.equals(Boolean.FALSE);
282 return !Strings.isBlank(eval);
296 if(o ==
null)
return 0;
297 int result = CompareUtil.compare(this.order, o.order);
299 result = CompareUtil.compare(this.name, o.name);
307 hash = 97 * hash + Objects.hashCode(this.name);
308 hash = 97 * hash + this.order;
320 if (getClass() != obj.getClass()) {
324 if (this.order != other.order) {
327 if (!Objects.equals(
this.name, other.name)) {
static String get(String msg)
static String realScript(String script)
boolean isInRole(String role)
abstract boolean checkAllMatch(E entity, IContact contact)
V setAdmin(Boolean admin)
VisualElement getElement(String name)
boolean allows(String name, E entity, IContact contact)
boolean emptyConstraints()
boolean check(E entity, IContact contact)
V addSubElement(String name)
boolean equals(Object obj)
V setWorker(Boolean worker)
boolean checkContact(IContact contact)
boolean checkEval(E entity, IContact contact)
abstract boolean checkAnyMatch(E entity, IContact contact)
V setStudent(Boolean student)
V addBusinessGrouping(String grouping)
V addSyndication(String syndication)
V setVisitor(Boolean visitor)
boolean checkConstraints(E entity, IContact contact)
V addBusinessSyndication(String syndication)
V addGrouping(String grouping)
int compareTo(VisualElement o)
abstract boolean emptyEntityConstraints()
VisualElement(String name, F factory)
boolean isNullOrFalse(Boolean value)
VisualElement getElement(String name, E entity, IContact contact)
boolean isVisitor(E entity, IContact contact)