19 package org.turro.dossier.workload;
21 import java.util.Arrays;
22 import java.util.Collections;
23 import java.util.EnumSet;
25 import org.turro.string.Strings;
26 import org.turro.action.Contacts;
27 import org.turro.auth.Authentication;
28 import org.turro.dossier.db.DossierPU;
29 import org.turro.dossier.entity.Category;
30 import org.turro.dossier.entity.Dossier;
31 import org.turro.dossier.entity.DossierStatus;
32 import org.turro.dossier.entity.IssueParticipantRole;
33 import org.turro.dossier.entity.IssueResolution;
34 import org.turro.dossier.entity.IssueStatus;
35 import org.turro.dossier.entity.IssueType;
36 import org.turro.dossier.entity.ParticipantRole;
37 import org.turro.dossier.entity.Worksheet;
38 import org.turro.dossier.issue.IssueSet;
39 import org.turro.dossier.issue.IssueWrapper;
40 import org.turro.dossier.util.WorksheetUtil;
41 import org.turro.elephant.context.Application;
42 import org.turro.elephant.db.WhereClause;
43 import org.turro.jpa.Dao;
44 import org.turro.plugin.contacts.IContact;
45 import org.turro.util.Chars;
55 private String searchValue =
"*";
56 private IContact realParticipant, byParticipant;
57 private Long dossierId;
60 private EnumSet<IssueStatus> status = EnumSet.noneOf(
IssueStatus.class);
61 private EnumSet<IssueResolution> resolutions = EnumSet.noneOf(
IssueResolution.class);
62 private EnumSet<IssueType> types = EnumSet.noneOf(
IssueType.class);
72 realParticipant = contact;
77 private void resetToDefault() {
78 if(realParticipant ==
null) {
81 if(byParticipant ==
null) {
82 byParticipant = realParticipant;
84 roles.addAll(Arrays.asList(IssueParticipantRole.values()));
85 types.addAll(Arrays.asList(IssueType.values()));
86 status.addAll(Arrays.asList(IssueStatus.values()));
87 status.remove(IssueStatus.STATUS_CLOSED);
88 resolutions.addAll(Arrays.asList(IssueResolution.values()));
100 if(byParticipant ==
null) {
101 byParticipant = realParticipant;
104 if((Strings.isEmpty(searchValue) ||
"*".equals(searchValue)) &&
105 category ==
null && dossier ==
null && (dossierId ==
null || dossierId == 0)) {
125 return new IssueSet(dao.getResultList(wc),
false, byParticipant);
127 return Collections.EMPTY_SET;
136 this.category = category;
144 this.resolutions = EnumSet.copyOf(resolutions);
151 public void setRoles(Set<IssueParticipantRole> roles) {
152 this.roles = EnumSet.copyOf(roles);
160 this.status = EnumSet.copyOf(status);
168 this.subject = subject;
176 this.types = EnumSet.copyOf(types);
180 this.types = EnumSet.of(type);
184 boolean canSeeAll = app !=
null && app.
isInRole(
"issue:all");
187 wc.
addClause(
"select distinct issue from Issue as issue");
188 wc.
addClause(
"left outer join issue.participants participant");
189 wc.
addClause(
"left outer join issue.sources source");
190 if(!
"*".equals(searchValue)) {
191 wc.
addClause(
"left outer join issue.comments comment");
195 boolean asParticipant =
201 if(Strings.isEmpty(searchValue) || (!asParticipant && !canSeeAll)) {
205 if(byParticipant ==
null) {
206 byParticipant = realParticipant;
212 if(searchValue.startsWith(
"#") && canSeeAll) {
213 id = Long.valueOf(searchValue.substring(1));
220 id = Long.valueOf(searchValue);
226 }
catch(Exception ex) {}
228 if(searchValue.startsWith(
"#") && searchValue.length() > 2 && canSeeAll) {
232 }, searchValue.substring(1).replaceAll(
"\\*",
"%"));
236 if(!
"*".equals(searchValue)) {
240 }, (searchValue ==
null ?
"" : searchValue.replaceAll(
"\\*",
"%")));
249 wc.
addClause(
"and participant.idContact = :idContact");
252 wc.
addClause(
"and participant.role in (:roles)");
257 if(!status.containsAll(EnumSet.allOf(
IssueStatus.class))) {
258 wc.
addClause(
"and issue.status in (:status)");
263 wc.
addClause(
"and issue.resolution in (:resolutions)");
267 if(!types.containsAll(EnumSet.allOf(
IssueType.class))) {
268 wc.
addClause(
"and issue.type in (:types)");
272 if(subject !=
null) {
273 wc.
addClause(
"and exists ( select subject from Participant as subject");
274 wc.
addClause(
"where subject.dossier = issue.dossier");
275 wc.
addClause(
"and subject.idContact = :idSubject");
277 wc.
addClause(
"and subject.role = :roleSubject )");
281 if(dossier !=
null) {
282 wc.
addClause(
"and issue.dossier = :dossier");
284 }
else if(dossierId !=
null && dossierId > 0) {
285 wc.
addClause(
"and issue.dossier.id = :dossierId");
288 wc.
addClause(
"and issue.dossier.status = :dstatus");
292 if(category !=
null) {
294 wc.
addClause(
"issue.dossier.category.fullDescription = :fullCatDesc");
295 wc.
addClause(
"or issue.dossier.category.fullDescription like concat(:fullCatDesc, '" + Chars.backward().spaced() +
"%')");
300 if(!realParticipant.
getId().equals(byParticipant.
getId()) && !canSeeAll) {
304 wc.
addClause(
"select p from Participant as p");
305 wc.
addClause(
"where p.dossier = issue.dossier");
306 wc.
addClause(
"and p.idContact = :idObserver");
307 wc.
addClause(
"and p.showAllIssues = TRUE");
311 wc.
addClause(
"select cp from CategoryParticipant as cp");
312 wc.
addClause(
"where cp.idContact = :idObserver");
313 wc.
addClause(
"and cp.showAllIssues = TRUE");
315 wc.
addClause(
"cp.category.fullDescription = issue.dossier.category.fullDescription");
316 wc.
addClause(
"or issue.dossier.category.fullDescription like concat(cp.category.fullDescription, '" + Chars.backward().spaced() +
"%')");
332 this.dossier = dossier;
340 this.dossierId = dossierId;
348 this.searchValue = searchValue;
352 return byParticipant;
356 this.byParticipant = byParticipant;
static IContact getIContact()
String getFullDescription()
static boolean cleared(Worksheet worksheet, IContact contact)
static Collection< Worksheet > getWorksheet(String idContact)
Set< IssueStatus > getStatus()
Set< IssueWrapper > getResultSet()
void setDossier(Dossier dossier)
void setDossierId(Long dossierId)
void setResolutions(Set< IssueResolution > resolutions)
void setCategory(Category category)
void setStatus(Set< IssueStatus > status)
WhereClause createCriteria()
Set< IssueResolution > getResolutions()
WorkloadQuery(IContact contact)
void setType(IssueType type)
IContact getByParticipant()
void setByParticipantId(String id)
void setRoles(Set< IssueParticipantRole > roles)
Set< IssueType > getTypes()
void setSearchValue(String searchValue)
void setSubject(IContact subject)
Set< IssueParticipantRole > getRoles()
void setTypes(Set< IssueType > types)
void setByParticipant(IContact byParticipant)
void setApplication(Application app)
boolean inWorksheet(Long id)
boolean isInRole(String role)
static Application getApplication()
void setPrefix(String prefix)
void addClause(String clause)
void addLikeFields(String[] fields, String value)
void addNamedValue(String name, Object value)