19 package org.turro.publication.command;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.Date;
25 import java.util.HashMap;
26 import java.util.List;
27 import org.amic.util.date.CheckDate;
28 import org.turro.string.Strings;
29 import org.turro.action.EntitiesInfo;
30 import org.turro.action.EntityInfoType;
31 import org.turro.action.LinkType;
32 import org.turro.annotation.ExternalEvent;
33 import org.turro.elephant.context.Application;
34 import org.turro.elephant.db.WhereClause;
35 import org.turro.plugin.calendar.CalendarColor;
36 import org.turro.plugin.calendar.DefaultCalendarEvent;
37 import org.turro.plugin.calendar.ICalendarEvent;
38 import org.turro.plugin.calendar.ICalendarInfo;
39 import org.turro.publication.db.PublicationPU;
40 import org.turro.publication.entity.Publication;
41 import org.turro.publication.util.PublicationWrapper;
55 public Collection<ICalendarEvent>
execute(Date start, Date end, HashMap<String, String> args) {
56 return getEvents(start, end, args);
59 private Collection<ICalendarEvent> getEvents(Date start, Date end, HashMap<String, String> args) {
60 ArrayList<ICalendarEvent> events =
new ArrayList<>();
61 for(
Publication publication : getPublications(start, end, args)) {
62 checkPublication(events, publication, args);
67 private List<Publication> getPublications(Date start, Date end, HashMap<String, String> args) {
68 String publicationCategories = args.get(
"publicationCategories");
69 String publicationGroups = args.get(
"publicationGroups");
70 WhereClause wc =
new WhereClause();
71 wc.addClause(
"select p from Publication as p");
72 wc.addClause(
"where p.accepted = TRUE");
73 wc.addClause(
"and (p.date >= :start and p.date <= :end)");
74 wc.addNamedValue(
"start", start);
75 wc.addNamedValue(
"end", end);
76 boolean hasFilter =
false;
77 if(!Strings.isBlank(publicationCategories)) {
78 if(!
"all".equals(publicationCategories)) {
79 wc.addClause(
"and p.publicationCategory in (" + publicationCategories +
")");
83 if(!Strings.isBlank(publicationGroups)) {
84 if(!
"all".equals(publicationGroups)) {
85 wc.addClause(
"and p.publicationGroup in (" + publicationGroups +
")");
90 return new PublicationPU().getResultList(Publication.class, wc);
92 return Collections.EMPTY_LIST;
96 private void checkPublication(ArrayList<ICalendarEvent> events, Publication publication, HashMap<String, String> args) {
97 String target = args.get(
"target");
98 PublicationWrapper pw =
new PublicationWrapper(publication);
99 if(
"self".equals(target) && !(Application.getApplication().isInRole(
"publication:all") || pw.isAuthor())) {
102 if(publication.getDate() !=
null) {
103 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
104 calendarEvent.setLocked(
false);
105 calendarEvent.setDone(
false);
106 calendarEvent.setHeaderColor(CalendarColor.BLUE.getHeader());
107 calendarEvent.setContentColor(CalendarColor.BLUE.getContent());
108 calendarEvent.setBeginDate(
new CheckDate(publication.getDate()).setHour(8).setMinute(0).getDate());
109 calendarEvent.setEndDate(calendarEvent.getBeginDate());
110 calendarEvent.setPath(PublicationPU.getObjectPath(publication));
111 calendarEvent.setTitle(publication.getTitle());
112 calendarEvent.setContent(getContent(publication));
113 events.add(calendarEvent);
117 private String getContent(Publication publication) {
118 return EntitiesInfo.getString(publication,
new PublicationWrapper(publication),
"publication", EntityInfoType.SUMMARY, LinkType.NONE);
Collection< ICalendarEvent > execute(Date start, Date end, HashMap< String, String > args)