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.List;
27 import org.turro.string.Strings;
28 import org.turro.action.IElephantSendable;
29 import org.turro.action.IEntityCtrl;
30 import org.turro.action.queue.NotificationCategory;
31 import org.turro.action.queue.Notifications;
32 import org.turro.annotation.ElephantEntity;
33 import org.turro.attach.www.AttachCtrl;
34 import org.turro.collections.KeyValueMap;
35 import org.turro.command.LabelControl;
36 import org.turro.elephant.context.ElephantContext;
37 import org.turro.elephant.db.WhereClause;
38 import org.turro.file.util.FileAttach;
39 import org.turro.i18n.I_;
40 import org.turro.jpa.Dao;
41 import org.turro.path.Path;
42 import org.turro.plugin.contacts.IContact;
43 import org.turro.polls.PollsCtrl;
44 import org.turro.publication.db.PublicationPU;
45 import org.turro.publication.entity.Newsletter;
46 import org.turro.publication.entity.Publication;
47 import org.turro.publication.entity.PublicationCategory;
48 import org.turro.publication.zul.menu.PublicationMenu;
49 import org.turro.www.commentit.CommentItCtrl;
50 import org.turro.www.starit.StarItCtrl;
75 if(
null !=
path.getRoot())
switch (
path.getRoot()) {
116 String root =
path.getRoot();
117 if(
null != root)
switch (root) {
119 return I_.
get(
"Publication");
121 return I_.
get(
"Category");
123 return I_.
get(
"Newsletter");
124 case "mail-category":
125 return I_.
get(
"Category");
164 String root =
path.getRoot();
165 if(
null != root)
switch (root) {
167 return "/_zul/images/publication.png";
169 return "/_zul/images/group.png";
171 return "/_zul/images/newsletter.png";
172 case "mail-category":
173 return "/_zul/images/group.png";
213 return Collections.EMPTY_LIST;
271 public Collection
getEntitites(String search,
int maxResults, KeyValueMap kvm) {
272 ArrayList<Object> list =
new ArrayList<>();
273 list.addAll(searchPublications(search, maxResults, kvm));
274 list.addAll(searchCategories(search, maxResults, kvm));
275 list.addAll(searchNewsletters(search, maxResults, kvm));
280 public Collection
getEntitites(String root, String search,
int maxResults, KeyValueMap kvm) {
281 ArrayList<Object> list =
new ArrayList<>();
282 if(
null != root)
switch (root) {
284 list.addAll(searchPublications(search, maxResults, kvm));
287 list.addAll(searchCategories(search, maxResults, kvm));
290 list.addAll(searchNewsletters(search, maxResults, kvm));
301 String root =
path.getRoot();
302 if(
null != root)
switch (root) {
354 return "/" + publication.
getId() +
355 "/" + Strings.unpunctuate(publication.
getTitle()).toLowerCase();
358 return "/" + newsletter.
getId() +
359 "/" + Strings.unpunctuate(newsletter.
getTitle()).toLowerCase();
368 if(
path.getRoot().equals(
"publication")) {
370 }
else if(
path.getRoot().equals(
"newsletter")) {
371 return "/user/newsletter";
389 return Arrays.asList(
"publication",
"pub-category",
"newsletter",
"mail-category");
407 private List<Object> searchPublications(String search,
int maxResults, KeyValueMap kvm) {
409 wc.
addClause(
"select c from Publication c");
410 wc.
addClause(
"where c.title like :search");
413 return getDao().getResultList(wc, maxResults);
416 private List<Object> searchCategories(String search,
int maxResults, KeyValueMap kvm) {
417 WhereClause wc =
new WhereClause();
418 wc.addClause(
"select c from PublicationCategory c");
419 wc.addClause(
"where c.name like :search");
420 wc.addClause(
"order by c.name");
421 wc.addNamedValue(
"search",
"%" + search +
"%");
422 return getDao().getResultList(wc, maxResults);
425 private List<Object> searchNewsletters(String search,
int maxResults, KeyValueMap kvm) {
426 WhereClause wc =
new WhereClause();
427 wc.addClause(
"select c from Newsletter c");
428 wc.addClause(
"where c.title like :search");
429 wc.addClause(
"order by c.title");
430 wc.addNamedValue(
"search",
"%" + search +
"%");
431 return getDao().getResultList(wc, maxResults);
static NotificationCategory getCategory(String id)
void setPublicOnly(boolean publicOnly)
void setEntityPath(String entityPath)
static String getEntityWebContext(String path)
void addClause(String clause)
void addNamedValue(String name, Object value)
boolean isValidLongEntity()
static IElephantEntity getController(String path)
PublicationEntities(String entityPath)
boolean canEdit(IContact contact)
IElephantSendable getSendable()
IElephantEntity getParent()
boolean canPublish(IContact contact)
Collection getEntitites(String search, int maxResults, KeyValueMap kvm)
Object configureCtrl(Object ctrl, IContact contact)
List< IElephantEntity > getChildren()
boolean canShowInContext(IContact contact, Object relatedEntity)
Collection getEntitites(String root, String search, int maxResults, KeyValueMap kvm)
PublicationEntities(Object entity)
IElephantEntity createInstance(String entityPath)
boolean itsMine(Object entity)
Collection< String > getAllowedRoots()
String getExtendedWebPath()
IElephantEntity createInstance(Object entity)
String getHierarchicalPath()
static String get(String msg)
void setEntityPath(String entityPath)
static String getObjectPath(Object object)
boolean isInRole(String role)
void setEntityPath(String entityPath)
void setEntityPath(String entityPath)
static final String PATH_SEPARATOR