19 package org.turro.entities;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.Date;
27 import java.util.List;
28 import org.turro.string.Strings;
29 import org.turro.action.IElephantSendable;
30 import org.turro.annotation.ElephantEntity;
31 import org.turro.collections.KeyValueMap;
32 import org.turro.contacts.CommentIt;
33 import org.turro.contacts.Contact;
34 import org.turro.contacts.ContactService;
35 import org.turro.contacts.ContactType;
36 import org.turro.contacts.Convocation;
37 import org.turro.contacts.GroupIt;
38 import org.turro.contacts.StarIt;
39 import org.turro.contacts.VoteIt;
40 import org.turro.contacts.db.ContactsPU;
41 import org.turro.contacts.relation.FuzzyRelationTypes;
42 import org.turro.contacts.service.ServiceSendable;
43 import org.turro.contacts.zul.label.ContactInfo;
44 import org.turro.contacts.zul.menu.ContactMenu;
45 import org.turro.elephant.db.WhereClause;
46 import static org.turro.entities.EntityRole.CHALLENGER;
47 import static org.turro.entities.EntityRole.DOCUMENTATION;
48 import org.turro.i18n.I_;
49 import org.turro.jpa.Dao;
50 import org.turro.path.Path;
51 import org.turro.plugin.contacts.IContact;
52 import org.turro.security.Permissions;
53 import org.turro.zul.convocation.ConvocationSendable;
77 if(
path.getSize() == 2) {
78 if(
null !=
path.getRoot())
switch (
path.getRoot()) {
119 String root =
path.getRoot();
120 if(
null != root)
switch (root) {
122 return I_.
get(
"Contact");
124 return I_.
get(
"Group");
126 return I_.
get(
"Convocation");
128 return I_.
get(
"Service");
130 if(
path.getSize() > 1)
switch(
path.getNode(1)) {
132 return I_.
get(
"Login");
134 return I_.
get(
"Logout");
136 return I_.
get(
"Login failed");
138 return I_.
get(
"Profile");
140 return I_.
get(
"Web site administration");
142 return I_.
get(
"Impersonate");
144 return I_.
get(
"Back to self");
178 String root =
path.getRoot();
179 if(
null != root)
switch (root) {
181 return "/_zul/images/contact.png";
183 return "/_zul/images/contacts.png";
185 return "/_zul/images/group.png";
187 return "/_zul/images/service.png";
234 return Collections.EMPTY_LIST;
302 public Collection
getEntitites(String search,
int maxResults, KeyValueMap kvm) {
303 ArrayList<Object> list =
new ArrayList<>();
304 list.addAll(searchContacts(search, maxResults, kvm));
305 list.addAll(searchConvocations(search, maxResults, kvm));
306 list.addAll(searchGroups(search, maxResults, kvm));
307 list.addAll(searchServices(search, maxResults, kvm));
312 public Collection
getEntitites(String root, String search,
int maxResults, KeyValueMap kvm) {
313 ArrayList<Object> list =
new ArrayList<>();
314 if(
null != root)
switch (root) {
316 list.addAll(searchContacts(search, maxResults, kvm));
319 list.addAll(searchConvocations(search, maxResults, kvm));
322 list.addAll(searchGroups(search, maxResults, kvm));
325 list.addAll(searchServices(search, maxResults, kvm));
336 String root =
path.getRoot();
337 if(
null != root)
switch (root) {
376 return super.itsMine(rootPath) ||
"log".equals(rootPath);
387 return Arrays.asList(
"contact",
"convocation",
"groupit",
"service");
429 private List<Object> searchContacts(String search,
int maxResults, KeyValueMap kvm) {
432 wc.
addClause(
"where (c.name like :search");
436 wc.
addClause(
"select cn from Connector as cn");
437 wc.
addClause(
"where (cn.description = 'TradeName' or cn.description = 'FiscalName')");
438 wc.
addClause(
"and cn.value like :search");
443 if(kvm.containsKey(
"role")) {
445 if(syndicationNames !=
null && !syndicationNames.isEmpty()) {
447 wc.
addClause(
"select syndication from Syndication as syndication");
448 wc.
addClause(
"where syndication.name in (:syndicationNames)");
450 wc.
addClause(
"and syndication.contact = c");
454 if(kvm.containsKey(
"syndication")) {
456 wc.
addClause(
"select syndication from Syndication as syndication");
457 wc.
addClause(
"where syndication.name in (:syndicationNames)");
458 wc.
addNamedValue(
"syndicationNames", kvm.get(
"syndication"));
459 wc.
addClause(
"and syndication.contact = c");
462 if(kvm.containsKey(
"type")) {
463 if(ContactType.getStudent().equals(kvm.get(
"type"))) {
467 wc.
addClause(
"select relation from BusinessRelation as relation");
468 FuzzyRelationTypes.isStudent(wc,
"where",
"relation");
469 wc.
addInRange(
"and",
"relation.startDate",
"relation.endDate",
"rdate",
new Date());
470 wc.
addClause(
"and relation.contact = c");
472 }
else if(ContactType.getWorker().equals(kvm.get(
"type"))) {
476 wc.
addClause(
"select relation from BusinessRelation as relation");
477 FuzzyRelationTypes.isWorker(wc,
"where",
"relation");
478 wc.
addInRange(
"and",
"relation.startDate",
"relation.endDate",
"rdate",
new Date());
479 wc.
addClause(
"and relation.contact = c");
481 }
else if(ContactType.getProfessional().equals(kvm.get(
"type"))) {
485 wc.
addClause(
"select relation from BusinessRelation as relation");
486 FuzzyRelationTypes.isProfessional(wc,
"where",
"relation");
487 wc.
addInRange(
"and",
"relation.startDate",
"relation.endDate",
"rdate",
new Date());
488 wc.
addClause(
"and relation.contact = c");
490 }
else if(ContactType.getEducator().equals(kvm.get(
"type"))) {
494 wc.
addClause(
"select relation from BusinessRelation as relation");
495 FuzzyRelationTypes.isEducator(wc,
"where",
"relation");
496 wc.
addInRange(
"and",
"relation.startDate",
"relation.endDate",
"rdate",
new Date());
497 wc.
addClause(
"and relation.contact = c");
499 }
else if(ContactType.getJuridical().equals(kvm.get(
"type"))) {
500 wc.
addClause(
"and (type = :type1 or type = :type2)");
502 wc.
addNamedValue(
"type2", ContactType.CONTACT_LEARNINGCENTER);
503 }
else if(ContactType.getCompany().equals(kvm.get(
"type"))) {
506 }
else if(ContactType.getCenter().equals(kvm.get(
"type"))) {
508 wc.
addNamedValue(
"type", ContactType.CONTACT_LEARNINGCENTER);
511 wc.
addNamedValue(
"type", ContactType.valueOf(kvm.get(
"type")));
517 return getDao().getResultList(wc, maxResults);
520 private List<Object> searchConvocations(String search,
int maxResults, KeyValueMap kvm) {
521 WhereClause wc =
new WhereClause();
522 wc.addClause(
"select c from Convocation c");
523 wc.addClause(
"where c.name like :search");
524 wc.addClause(
"order by c.name");
525 wc.addNamedValue(
"search",
"%" + search +
"%");
526 return getDao().getResultList(wc, maxResults);
529 private List<Object> searchGroups(String search,
int maxResults, KeyValueMap kvm) {
530 WhereClause wc =
new WhereClause();
531 wc.addClause(
"select g from GroupIt g");
532 wc.addClause(
"where g.name like :search");
533 wc.addClause(
"order by g.name");
534 wc.addNamedValue(
"search",
"%" + search +
"%");
535 return getDao().getResultList(wc, maxResults);
538 private List<Object> searchServices(String search,
int maxResults, KeyValueMap kvm) {
539 WhereClause wc =
new WhereClause();
540 wc.addClause(
"select s from ContactService s");
541 wc.addClause(
"where s.title like :search");
542 wc.addClause(
"order by s.title");
543 wc.addNamedValue(
"search",
"%" + search +
"%");
544 return getDao().getResultList(wc, maxResults);
void addInRange(String operator, String startField, String endField, String attribute, Date date)
void addClause(String clause)
void addNamedValue(String name, Object value)
boolean equals(Object obj)
static IElephantEntity getController(String path)
static String get(String msg)
boolean isInRole(String role)
static Set< String > getSecurityGroupIdsBy(String role)
static final String PATH_SEPARATOR
String getHierarchicalPath()