19 package org.turro.entitites;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.List;
27 import org.turro.string.Strings;
28 import org.turro.action.IEntityCtrl;
29 import org.turro.annotation.ElephantEntity;
30 import org.turro.attach.entity.Attachment;
31 import org.turro.attach.www.AttachCtrl;
32 import org.turro.collections.KeyValueMap;
33 import org.turro.command.LabelControl;
34 import org.turro.contacts.VoteIt;
35 import org.turro.dossier.db.DossierPU;
36 import org.turro.dossier.entity.Category;
37 import org.turro.dossier.entity.Dossier;
38 import org.turro.dossier.entity.DossierType;
39 import org.turro.dossier.entity.DossierVersion;
40 import org.turro.dossier.entity.Issue;
41 import org.turro.dossier.entity.IssueComment;
42 import org.turro.dossier.entity.IssueParticipant;
43 import org.turro.dossier.entity.Participant;
44 import org.turro.dossier.entity.Project;
45 import org.turro.dossier.entity.ProjectGrant;
46 import org.turro.dossier.zul.menu.DossierMenu;
47 import org.turro.elephant.db.WhereClause;
48 import org.turro.entities.DefaultElephantEntity;
49 import org.turro.entities.Entities;
50 import org.turro.entities.EntityListAdapter;
51 import org.turro.entities.EntityRole;
52 import org.turro.entities.IElephantEntity;
53 import org.turro.file.util.FileAttach;
54 import org.turro.i18n.I_;
55 import org.turro.jpa.Dao;
56 import org.turro.path.Path;
57 import org.turro.plugin.contacts.ContactList;
58 import org.turro.plugin.contacts.IContact;
59 import org.turro.polls.PollsCtrl;
60 import org.turro.script.Script;
61 import org.turro.security.ConceptPermission;
62 import org.turro.util.Chars;
63 import org.turro.www.commentit.CommentItCtrl;
64 import org.turro.www.describeit.DescribeItCtrl;
65 import org.turro.www.starit.StarItCtrl;
66 import org.turro.www.voteit.VoteItCtrl;
91 if(
null !=
path.getRoot())
switch (
path.getRoot()) {
98 case "dossier-category":
101 case "project-grant":
121 return ((
Issue)
entity).getId() + Chars.forward().spaced().toString() + ((
Issue)
entity).getDescription() +
137 String root =
path.getRoot();
138 if(
null != root)
switch (root) {
140 return I_.
get(
"Dossier");
142 return I_.
get(
"Issue");
143 case "dossier-category":
144 return I_.
get(
"Category");
145 case "project-grant":
146 return I_.
get(
"Project grant");
148 return I_.
get(
"My issues");
150 return I_.
get(
"My dossiers");
162 return ((
Dossier)
entity).getLabeledPublishableDescription();
164 return ((
Issue)
entity).getDossier().getFullDescription(
false);
183 String root =
path.getRoot();
184 if(
null != root)
switch (root) {
186 return "/_zul/images/dossier.png";
188 return "/_zul/images/issue.png";
189 case "dossier-category":
190 return "/_zul/images/group.png";
191 case "project-grant":
192 return "/_zul/images/handshelp.png";
194 return "/_zul/images/issue.png";
196 return "/_zul/images/dossier.png";
244 return Collections.EMPTY_LIST;
260 String root =
path.getRoot();
261 if(
"myissues".
equals(root)) {
264 }
else if(
"mydossiers".
equals(root)) {
294 ((
Dossier)
entity).getFullParticipants().isParticipant(contact);
297 ((
Issue)
entity).getFullParticipants().isParticipant(contact);
309 return ((
Dossier)
entity).getFullParticipants().isParticipant(contact);
311 return ((
Issue)
entity).getFullParticipants().canShowIssue(contact);
313 return ((
Category)
entity).getFullParticipants().isParticipant(contact);
320 public Collection
getEntitites(String search,
int maxResults, KeyValueMap kvm) {
321 ArrayList<Object> list =
new ArrayList<>();
322 list.addAll(searchCategories(search, maxResults, kvm));
323 list.addAll(searchDossiers(search, maxResults, kvm));
324 list.addAll(searchIssues(search, maxResults, kvm));
329 public Collection
getEntitites(String root, String search,
int maxResults, KeyValueMap kvm) {
330 ArrayList<Object> list =
new ArrayList<>();
331 if(
null != root)
switch (root) {
333 list.addAll(searchDossiers(search, maxResults, kvm));
336 list.addAll(searchIssues(search, maxResults, kvm));
338 case "dossier-category":
339 list.addAll(searchCategories(search, maxResults, kvm));
424 if(relatedEntity instanceof
VoteIt) {
433 }
else if(relatedEntity instanceof
Attachment) {
477 return super.hasRelatedRole(role, contact);
486 "/" + dossier.
getId() +
487 "/" + Strings.unpunctuate(dossier.
getDescription()).toLowerCase();
490 return "/" + issue.
getId() +
500 String root =
path.getRoot();
501 if(
"dossier".
equals(root)) {
511 return super.getLinkRoot();
517 if(
path.getRoot().equals(
"project-grant")) {
518 return "/user/projectgrants";
531 return super.itsMine(rootPath) ||
532 "myissues".equals(rootPath) ||
"mydossiers".equals(rootPath);
543 return Arrays.asList(
"dossier",
"issue",
"dossier-category",
"project-grant");
563 Script script = super.getActorScript();
566 script.addVariable(
"category",
entity);
567 script.addVariable(
"dpl", ((
Category)
entity).getFullParticipants());
569 script.addVariable(
"dossier",
entity);
570 script.addVariable(
"dpl", ((
Dossier)
entity).getFullParticipants());
572 script.addVariable(
"issue",
entity);
573 script.addVariable(
"dpl", ((
Issue)
entity).getFullParticipants());
589 return super.getConceptPermission(name);
622 private List<Object> searchCategories(String search,
int maxResults, KeyValueMap kvm) {
624 wc.
addClause(
"select c from Category c");
625 wc.
addClause(
"where c.fullDescription like :search");
628 if(kvm.containsKey(
"dossier-categories")) {
631 for(String cat : convertToCategories(kvm.get(String.class,
"dossier-categories"),
true)) {
632 String parName = cat.replaceAll(
"\\/",
"p");
633 wc.
addClause(sep +
" c.uniquePath like :" + parName);
637 for(String cat : convertToCategories(kvm.get(String.class,
"dossier-categories"),
false)) {
638 String parName = cat.replaceAll(
"\\/",
"e");
639 wc.
addClause(sep +
" c.uniquePath like :" + parName);
646 wc.
addClause(
"order by c.fullDescription");
647 return getDao().getResultList(wc, maxResults);
650 private List<Object> searchDossiers(String search,
int maxResults, KeyValueMap kvm) {
651 WhereClause wc =
new WhereClause();
652 wc.addClause(
"select d from Dossier d");
653 wc.addClause(
"where d.description like :search");
654 wc.addNamedValue(
"search",
"%" + search +
"%");
656 if(kvm.containsKey(
"dossier-categories")) {
658 wc.addClause(
"and (");
659 for(String cat : convertToCategories(kvm.get(String.class,
"dossier-categories"),
true)) {
660 String parName = cat.replaceAll(
"\\/",
"p");
661 wc.addClause(sep +
" d.uniquePath like :" + parName);
662 wc.addNamedValue(parName,
"%" + cat +
"%");
667 if(kvm.get(Boolean.class,
"only-projects", Boolean.FALSE)) {
668 wc.addClause(
"and d.project is not null");
671 wc.addClause(
"order by d.description");
672 return getDao().getResultList(wc, maxResults);
675 private List<Object> searchIssues(String search,
int maxResults, KeyValueMap kvm) {
676 WhereClause wc =
new WhereClause();
677 wc.addClause(
"select i from Issue i");
678 wc.addClause(
"where i.description like :search");
679 wc.addClause(
"order by i.description");
680 wc.addNamedValue(
"search",
"%" + search +
"%");
681 return getDao().getResultList(wc, maxResults);
684 private List<String> convertToCategories(String categoryIds,
boolean addSlash) {
685 String cids[] = categoryIds.split(
"\\s*,\\s*");
686 ArrayList<String> cats =
new ArrayList<>();
687 for(String
id : cids) {
688 cats.add(
"/c" +
id + (addSlash ?
"/" :
""));
boolean canShowTo(IContact contact, HashSet< String > restrictedFolders)
void addRestrictedFolders(HashSet< String > restrictedFolders)
void setPublicOnly(boolean publicOnly)
void setEntityPath(String entityPath)
static String getObjectPath(Object object)
static String getObjectExtendedPath(Object object)
boolean canShowAllAttachments(IContact contact)
ParticipantSet< IDossierParticipant > getFullParticipants()
String getVersionString()
DossierStatus getStatus()
ParticipantSet< IDossierParticipant > getFullParticipants()
boolean isBranchAdmin(IContact contact)
ParticipantSet getFullParticipants()
PhaseDefinition getPhaseDefinition()
void addClause(String clause)
void addNamedValue(String name, Object value)
boolean isValidLongEntity()
IElephantEntity getController(String entityPath)
boolean equals(Object obj)
static IElephantEntity getController(String path)
boolean addAll(Collection entities)
Object getObject(Path entityPath)
boolean canShowInContext(IContact contact, Object relatedEntity)
Collection getEntitites(String search, int maxResults, KeyValueMap kvm)
IElephantEntity getMain(Object entity)
List< IElephantEntity > getChildren()
String getHierarchicalPath()
DossierEntities(Object entity)
IElephantEntity getParent()
ConceptPermission getConceptPermission(String name)
boolean itsMine(String rootPath)
boolean canPublish(IContact contact)
boolean itsMine(Object entity)
Collection< String > getAllowedRoots()
IElephantEntity createInstance(String entityPath)
boolean hasRelatedRole(EntityRole role, IContact contact)
IElephantEntity createInstance(Object entity)
Object configureCtrl(Object ctrl, IContact contact)
DossierEntities(String entityPath)
Collection getEntitites(String root, String search, int maxResults, KeyValueMap kvm)
String getExtendedWebPath()
boolean canEdit(IContact contact)
static String byKey(String key)
static String get(String msg)
ConceptPermission getPermission(String name, IElephantEntity iee)
void setEntityPath(String entityPath)
boolean isInRole(String role)
void setEntityPath(String entityPath)
void setEntityPath(String entityPath)
void setAllowed(ContactList allowed)
void setForbiden(boolean forbiden)
void setEntityPath(String entityPath)
void setForbid(boolean forbid)
void setEntityPath(String entityPath)
static final String PATH_SEPARATOR
boolean canPublish(IContact contact)