19 package org.turro.dossier.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.HashSet;
27 import java.util.List;
28 import org.amic.util.date.CheckDate;
29 import org.turro.string.Strings;
30 import org.turro.action.EntitiesInfo;
31 import org.turro.action.EntityInfoType;
32 import org.turro.action.LinkType;
33 import org.turro.annotation.ExternalEvent;
34 import org.turro.dossier.db.DossierPU;
35 import org.turro.dossier.entity.Issue;
36 import org.turro.dossier.issue.IssueWrapper;
37 import org.turro.dossier.search.CategoryResults;
38 import org.turro.elephant.context.Application;
39 import org.turro.elephant.db.WhereClause;
40 import org.turro.i18n.I_;
41 import org.turro.plugin.calendar.CalendarColor;
42 import org.turro.plugin.calendar.DefaultCalendarEvent;
43 import org.turro.plugin.calendar.ICalendarEvent;
44 import org.turro.plugin.calendar.ICalendarInfo;
45 import org.turro.www.describeit.DescribeItCtrl;
59 public Collection<ICalendarEvent>
execute(Date start, Date end, HashMap<String, String> args) {
60 return getEvents(start, end, args);
63 private Collection<ICalendarEvent> getEvents(Date start, Date end, HashMap<String, String> args) {
64 ArrayList<ICalendarEvent> events =
new ArrayList<>();
65 for(
Issue issue : getIssues(start, end, args)) {
71 private List<Issue> getIssues(Date start, Date end, HashMap<String, String> args) {
72 String dossierCategories = args.get(
"dossierCategories");
73 String required = args.get(
"required");
74 WhereClause wc =
new WhereClause();
75 wc.addClause(
"select distinct i from Issue as i");
76 wc.addClause(
"where i.publishable = TRUE");
77 wc.addClause(
"and (");
79 if(isRequired(
"S", required)) {
80 wc.addClause(join +
" (i.startDate >= :start and i.startDate <= :end)");
83 if(isRequired(
"C", required)) {
84 wc.addClause(join +
" (i.controlDate >= :start and i.controlDate <= :end)");
87 if(isRequired(
"D", required)) {
88 wc.addClause(join +
" (i.delivery >= :start and i.delivery <= :end)");
91 if(isRequired(
"R", required)) {
92 wc.addClause(join +
" (i.solvedDate >= :start and i.solvedDate <= :end)");
95 if(isRequired(
"I", required)) {
96 wc.addClause(join +
" (i.issueDate >= :start and i.issueDate <= :end)");
99 if(isRequired(
"M", required)) {
100 wc.addClause(join +
" (i.modification >= :start and i.modification <= :end)");
104 wc.addNamedValue(
"start", start);
105 wc.addNamedValue(
"end", end);
106 if(!Strings.isBlank(dossierCategories)) {
107 if(!
"all".equals(dossierCategories)) {
108 CategoryResults.addExistsCategoryAffiliance(wc, dossierCategories,
"i.dossier");
110 return new DossierPU().getResultList(Issue.class, wc);
112 return Collections.EMPTY_LIST;
116 private void checkIssue(ArrayList<ICalendarEvent> events, IssueWrapper iw, HashMap<String, String> args) {
117 String required = args.get(
"required");
118 String target = args.get(
"target");
119 if(
"self".equals(target) && !(Application.getApplication().isInRole(
"issue:all") || iw.isFullParticipant())) {
122 HashSet<Date> dates =
new HashSet<>();
123 if(iw.getBeginDate()!=
null && isRequired(
"S", required)) {
124 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
125 calendarEvent.setLocked(
false);
126 calendarEvent.setDone(iw.getIssue().getStatus().isFinished());
127 calendarEvent.setHeaderColor(CalendarColor.RED.getHeader());
128 calendarEvent.setContentColor(CalendarColor.RED.getContent());
129 calendarEvent.setBeginDate(iw.getBeginDate());
130 dates.add(calendarEvent.getBeginDate());
131 if(isRequired(
"D", required) &&
new CheckDate(iw.getBeginDate()).sameDay(iw.getEndDate())) {
132 calendarEvent.setEndDate(iw.getEndDate());
133 dates.add(iw.getEndDate());
135 calendarEvent.setEndDate(calendarEvent.getBeginDate());
137 calendarEvent.setPath(DossierPU.getObjectPath(iw.getIssue()));
138 calendarEvent.setTitle(iw.getIssue().getDescription());
139 calendarEvent.setContent(getContent(iw));
140 calendarEvent.setMotive(I_.get(
"Start date"));
141 events.add(calendarEvent);
143 if(iw.getEndDate()!=
null && !dates.contains(iw.getEndDate()) && isRequired(
"D", required)) {
144 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
145 calendarEvent.setLocked(
false);
146 calendarEvent.setDone(iw.getIssue().getStatus().isFinished());
147 calendarEvent.setHeaderColor(CalendarColor.RED.getHeader());
148 calendarEvent.setContentColor(CalendarColor.RED.getContent());
149 calendarEvent.setBeginDate(iw.getEndDate());
150 dates.add(calendarEvent.getBeginDate());
151 calendarEvent.setEndDate(calendarEvent.getBeginDate());
152 calendarEvent.setPath(DossierPU.getObjectPath(iw.getIssue()));
153 calendarEvent.setTitle(iw.getIssue().getDescription());
154 calendarEvent.setContent(getContent(iw));
155 calendarEvent.setMotive(I_.get(
"End date"));
156 events.add(calendarEvent);
158 if(iw.getControlDate() !=
null && !dates.contains(iw.getControlDate()) && isRequired(
"C", required)) {
159 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
160 calendarEvent.setLocked(
false);
161 calendarEvent.setDone(iw.getIssue().getStatus().isFinished());
162 calendarEvent.setHeaderColor(CalendarColor.RED.getHeader());
163 calendarEvent.setContentColor(CalendarColor.RED.getContent());
164 calendarEvent.setBeginDate(iw.getControlDate());
165 dates.add(calendarEvent.getBeginDate());
166 calendarEvent.setEndDate(calendarEvent.getBeginDate());
167 calendarEvent.setPath(DossierPU.getObjectPath(iw.getIssue()));
168 calendarEvent.setTitle(iw.getIssue().getDescription());
169 calendarEvent.setContent(getContent(iw));
170 calendarEvent.setMotive(I_.get(
"Control"));
171 events.add(calendarEvent);
173 if(iw.getIssue().getSolvedDate() !=
null && !dates.contains(iw.getIssue().getSolvedDate()) && isRequired(
"R", required)) {
174 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
175 calendarEvent.setLocked(
false);
176 calendarEvent.setDone(iw.getIssue().getStatus().isFinished());
177 calendarEvent.setHeaderColor(CalendarColor.RED.getHeader());
178 calendarEvent.setContentColor(CalendarColor.RED.getContent());
179 calendarEvent.setBeginDate(iw.getIssue().getSolvedDate());
180 dates.add(calendarEvent.getBeginDate());
181 calendarEvent.setEndDate(calendarEvent.getBeginDate());
182 calendarEvent.setPath(DossierPU.getObjectPath(iw.getIssue()));
183 calendarEvent.setTitle(iw.getIssue().getDescription());
184 calendarEvent.setContent(getContent(iw));
185 calendarEvent.setMotive(I_.get(
"Closing"));
186 events.add(calendarEvent);
188 if(iw.getIssue().getIssueDate() !=
null && !dates.contains(iw.getIssue().getIssueDate()) && isRequired(
"I", required)) {
189 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
190 calendarEvent.setLocked(
false);
191 calendarEvent.setDone(iw.getIssue().getStatus().isFinished());
192 calendarEvent.setHeaderColor(CalendarColor.RED.getHeader());
193 calendarEvent.setContentColor(CalendarColor.RED.getContent());
194 calendarEvent.setBeginDate(iw.getIssue().getIssueDate());
195 dates.add(calendarEvent.getBeginDate());
196 calendarEvent.setEndDate(calendarEvent.getBeginDate());
197 calendarEvent.setPath(DossierPU.getObjectPath(iw.getIssue()));
198 calendarEvent.setTitle(iw.getIssue().getDescription());
199 calendarEvent.setContent(getContent(iw));
200 calendarEvent.setMotive(I_.get(
"Creation"));
201 events.add(calendarEvent);
203 if(iw.getIssue().getModification() !=
null && !dates.contains(iw.getIssue().getModification()) && isRequired(
"M", required)) {
204 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
205 calendarEvent.setLocked(
false);
206 calendarEvent.setDone(iw.getIssue().getStatus().isFinished());
207 calendarEvent.setHeaderColor(CalendarColor.RED.getHeader());
208 calendarEvent.setContentColor(CalendarColor.RED.getContent());
209 calendarEvent.setBeginDate(iw.getIssue().getModification());
210 dates.add(calendarEvent.getBeginDate());
211 calendarEvent.setEndDate(calendarEvent.getBeginDate());
212 calendarEvent.setPath(DossierPU.getObjectPath(iw.getIssue()));
213 calendarEvent.setTitle(iw.getIssue().getDescription());
214 calendarEvent.setContent(getContent(iw));
215 calendarEvent.setMotive(I_.get(
"Modification"));
216 events.add(calendarEvent);
220 private String getContent(IssueWrapper iw) {
221 DescribeItCtrl dic =
new DescribeItCtrl(Application.getApplication().getConstructor());
222 dic.setEntityPath(DossierPU.getObjectPath(iw.getIssue()));
223 HashMap<String, Object> args =
new HashMap<>();
224 args.put(
"dic", dic);
225 return EntitiesInfo.getString(iw.getIssue(), iw,
"issue", EntityInfoType.SUMMARY, LinkType.NONE, args);
228 private boolean isRequired(String value, String param) {
229 if(!Strings.isBlank(value) && !Strings.isBlank(param)) {
230 return param.contains(value);
Collection< ICalendarEvent > execute(Date start, Date end, HashMap< String, String > args)