19 package org.turro.contacts.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.turro.string.Strings;
28 import org.turro.action.EntitiesInfo;
29 import org.turro.action.EntityInfoType;
30 import org.turro.action.LinkType;
31 import org.turro.annotation.ExternalEvent;
32 import org.turro.auth.Authentication;
33 import org.turro.contacts.Convocation;
34 import org.turro.contacts.db.ContactsPU;
35 import org.turro.elephant.context.Application;
36 import org.turro.elephant.db.WhereClause;
37 import org.turro.plugin.calendar.CalendarColor;
38 import org.turro.plugin.calendar.DefaultCalendarEvent;
39 import org.turro.plugin.calendar.ICalendarEvent;
40 import org.turro.plugin.calendar.ICalendarInfo;
41 import org.turro.zul.convocation.ConvocationWrapper;
51 public Collection<ICalendarEvent>
execute(Date start, Date end, HashMap<String, String> args) {
52 return getEvents(start, end, args);
55 private Collection<ICalendarEvent> getEvents(Date start, Date end, HashMap<String, String> args) {
56 ArrayList<ICalendarEvent> events =
new ArrayList<>();
57 for(
Convocation convocation : getConvocations(start, end, args)) {
58 checkConvocation(events, convocation, args);
63 private List<Convocation> getConvocations(Date start, Date end, HashMap<String, String> args) {
64 String convocationPath = args.get(
"convocationPaths");
65 WhereClause wc =
new WhereClause();
66 wc.addClause(
"select c from Convocation c");
67 wc.addClause(
"where c.callDate >= :start");
68 wc.addClause(
"and c.callDate <= :end");
69 wc.addNamedValue(
"start", start);
70 wc.addNamedValue(
"end", end);
71 if(!Strings.isBlank(convocationPath)) {
72 if(!
"all".equals(convocationPath)) {
73 wc.addClause(
"and c.entityPath like :path");
74 wc.addNamedValue(
"path", convocationPath +
"%");
76 return new ContactsPU().getResultList(Convocation.class, wc);
78 return Collections.EMPTY_LIST;
82 private void checkConvocation(ArrayList<ICalendarEvent> events, Convocation convocation, HashMap<String, String> args) {
83 String target = args.get(
"target");
84 if(!convocation.isPublishable() &&
"self".equals(target) &&
85 !(Application.getApplication().isInRole(
"convocation:all") || convocation.isAssistant(Authentication.getIContact()))) {
88 if(convocation.getCallDate()!=
null) {
89 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
90 calendarEvent.setLocked(
false);
91 calendarEvent.setDone(
false);
92 calendarEvent.setHeaderColor(CalendarColor.PURPLE.getHeader());
93 calendarEvent.setContentColor(CalendarColor.PURPLE.getContent());
94 calendarEvent.setBeginDate(convocation.getCallDate());
95 calendarEvent.setEndDate(convocation.getEndDate());
96 calendarEvent.setPath(ContactsPU.getObjectPath(convocation));
97 calendarEvent.setTitle(convocation.getName());
98 calendarEvent.setContent(getContent(convocation));
99 events.add(calendarEvent);
103 private String getContent(Convocation convocation) {
104 return EntitiesInfo.getString(convocation,
new ConvocationWrapper(convocation),
"convocation", EntityInfoType.SUMMARY, LinkType.NONE);