19 package org.turro.script;
21 import java.lang.reflect.Method;
22 import java.util.List;
23 import java.util.stream.Collectors;
24 import org.turro.string.Strings;
25 import org.turro.dossier.db.DossierPU;
26 import org.turro.dossier.dossier.ParticipantSet;
27 import org.turro.dossier.entity.Category;
28 import org.turro.dossier.entity.Dossier;
29 import org.turro.dossier.entity.Issue;
30 import org.turro.dossier.entity.Participant;
31 import org.turro.dossier.entity.ParticipantRole;
32 import org.turro.elephant.db.WhereClause;
33 import org.turro.plugin.contacts.IContact;
34 import org.turro.reflection.Beans;
35 import org.turro.reflection.Reflections;
50 List<String> catList = Strings.csvToList(categories);
51 if(entity instanceof
Issue) {
52 return catList.contains(String.valueOf(((
Issue) entity).getDossier().getCategory().getId()));
53 }
else if(entity instanceof
Dossier) {
54 return catList.contains(String.valueOf(((
Dossier) entity).getCategory().getId()));
55 }
else if(entity instanceof
Category) {
56 return ((
Category) entity).getParent() !=
null && catList.contains(String.valueOf(((
Category) entity).getParent().getId()));
62 List<String> phaseList = Strings.csvToList(indexes);
63 if(entity instanceof
Issue) {
64 return phaseList.contains(Integer.toString(((
Issue) entity).getDossier().getProject().getPhase()));
65 }
else if(entity instanceof
Dossier) {
66 return phaseList.contains(Integer.toString(((
Dossier) entity).getProject().getPhase()));
72 List<String> typeList = Strings.csvToList(types);
73 if(entity instanceof
Issue) {
74 return ((
Issue) entity).getDossier().getProject().getPhaseDefinition().anyStringMatch(typeList);
75 }
else if(entity instanceof
Dossier) {
76 return ((
Dossier) entity).getProject().getPhaseDefinition().anyStringMatch(typeList);
81 public boolean anyOfRoles(Object dpl, Object user, String roles) {
82 List<String> roleList = Strings.csvToList(roles);
87 List<String> roleList = Strings.csvToList(roles);
88 return roleList.stream().anyMatch(r -> {
89 Method method = Reflections.of(
ParticipantSet.class).findMethod(Reflections.toBeanWay(
"is", r),
IContact.class);
90 return (Boolean) Beans.of(dpl).silentInvoke(method, (
IContact) user);
95 List<String> discriminatorList = Strings.csvToList(discriminators);
96 return discriminatorList.stream().anyMatch(d -> ((
ParticipantSet) dpl).isParticipantByDiscriminator((
IContact) user, d));
100 return !getParticipationsFrom((
IContact) user, roles,
null).isEmpty() ||
101 !getCategoryParticipationsFrom((
IContact) user, roles,
null).isEmpty();
105 return !getCategoryParticipationsFrom((
IContact) user, roles,
null).isEmpty();
109 return !getParticipationsFrom((
IContact) user,
null, roles).isEmpty() ||
110 !getCategoryParticipationsFrom((
IContact) user,
null, roles).isEmpty();
114 return !getParticipationsFrom((
IContact) user,
null,
null).isEmpty() ||
115 !getCategoryParticipationsFrom((
IContact) user,
null,
null).isEmpty();
119 return !getCategoryParticipationsFrom((
IContact) user,
null,
null).isEmpty();
122 private List<Participant> getParticipationsFrom(
IContact user, String roles, String extroles) {
124 wc.
addClause(
"select p from Participant p");
127 if(!Strings.isBlank(roles)) {
128 wc.
addIn(
"and",
"p.role", Strings.csvToList(roles).stream().map(r ->
ParticipantRole.valueOf(r)).collect(Collectors.toList()));
130 if(!Strings.isBlank(extroles)) {
131 Strings.csvToList(extroles).forEach(r -> {
135 return new DossierPU().getResultList(wc);
138 private List<Participant> getCategoryParticipationsFrom(IContact user, String roles, String extroles) {
139 WhereClause wc =
new WhereClause();
140 wc.addClause(
"select p from CategoryParticipant p");
141 wc.addClause(
"where p.idContact = :id");
142 wc.addNamedValue(
"id", user.getId());
143 if(!Strings.isBlank(roles)) {
144 wc.addIn(
"and",
"p.role", Strings.csvToList(roles).stream().map(r -> ParticipantRole.valueOf(r)).collect(Collectors.toList()));
146 if(!Strings.isBlank(extroles)) {
147 Strings.csvToList(extroles).forEach(r -> {
148 wc.addClause(
"and p." + r +
" = TRUE");
151 return new DossierPU().getResultList(wc);
void addClause(String clause)
void addIn(String operator, String field, List values)
void addNamedValue(String name, Object value)
void addFunctions(Script script)
boolean anyOfDiscriminators(Object dpl, Object user, String discriminators)
boolean anyOfCategoryRoles(Object user, String roles)
boolean anyOfExtRoles(Object user, String roles)
boolean anyOfPhaseTypes(Object entity, String types)
boolean anyOfRoles(Object user, String roles)
boolean anyOfRoles(Object dpl, Object user, String roles)
boolean anyOfCategories(Object entity, String categories)
boolean anyCategoryParticipation(Object user)
boolean anyParticipation(Object user)
boolean anyOfPhases(Object entity, String indexes)
boolean anyOfExtRoles(Object dpl, Object user, String roles)