19 package org.turro.dossier.command;
21 import java.util.Collection;
22 import java.util.Date;
23 import java.util.EnumMap;
24 import java.util.HashMap;
25 import java.util.HashSet;
27 import org.amic.util.date.CheckDate;
28 import org.turro.string.ObjectString;
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.ElephantPlugin;
34 import org.turro.dossier.db.DossierPU;
35 import org.turro.dossier.entity.IssueParticipant;
36 import org.turro.dossier.entity.IssueParticipantRole;
37 import org.turro.dossier.issue.IssueWrapper;
38 import org.turro.dossier.search.IssueResults;
39 import org.turro.dossier.zul.issue.IssueStage;
40 import org.turro.elephant.context.Application;
41 import org.turro.elephant.db.WhereClause;
42 import org.turro.i18n.I_;
43 import org.turro.path.Path;
44 import org.turro.plugin.calendar.CalendarColor;
45 import org.turro.plugin.calendar.DefaultCalendarEvent;
46 import org.turro.plugin.command.CalendarPlugin;
47 import org.turro.www.describeit.DescribeItCtrl;
56 private Map<IssueStage, Integer> map;
57 private Collection<IssueWrapper> iwl;
74 calendarEvent.
setBeginDate(
new CheckDate(
new Date()).setHour(8).setMinute(0).getDate());
76 calendarEvent.
setPath(
"/myissues");
78 calendarEvent.
setContent(getMyIssuesContent());
85 private void pendingIssues() {
91 wc.
addClause(
"(issue.startDate >= :start and issue.startDate <= :end)");
92 wc.
addClause(
"or (issue.controlDate >= :start and issue.controlDate <= :end)");
93 wc.
addClause(
"or (issue.delivery >= :start and issue.delivery <= :end)");
94 wc.
addClause(
"or (issue.solvedDate >= :start and issue.solvedDate <= :end)");
95 wc.
addClause(
"or (issue.issueDate >= :start and issue.issueDate <= :end)");
96 wc.
addClause(
"or (issue.modification >= :start and issue.modification <= :end)");
98 wc.
addNamedValue(
"start",
new CheckDate().addMonths(-3).getDate());
99 wc.
addNamedValue(
"end",
new CheckDate().addMonths(1).getDate());
104 for(IssueWrapper iw : iwl) {
105 IssueStage is = getStage(iw);
106 Integer i = map.get(is);
117 private IssueStage getStage(IssueWrapper wissue) {
119 if(wissue.isUnrelated()) {
120 return IssueStage.ISSUE_STAGE_UNRELATED;
123 if(wissue.hasPassedNow()) {
124 return IssueStage.ISSUE_STAGE_DATE_SURPASSED;
127 if(!wissue.hasPassedStartDate() || !wissue.canStartBySources()) {
128 return IssueStage.ISSUE_STAGE_TO_COME;
131 int stage = wissue.getRelevanceOrderByContact();
134 case 1:
return IssueStage.ISSUE_STAGE_TO_DO;
135 case 2:
return IssueStage.ISSUE_STAGE_REUNION;
136 case 5:
return IssueStage.ISSUE_STAGE_FROZEN;
139 return IssueStage.ISSUE_STAGE_TO_MONITOR;
142 private void checkIssue(IssueWrapper iw) {
144 HashSet<Date> dates =
new HashSet<>();
145 if(iw.getBeginDate()!=
null) {
146 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
147 calendarEvent.setLocked(
false);
148 calendarEvent.setDone(iw.getIssue().getStatus().isFinished());
149 calendarEvent.setHeaderColor(CalendarColor.RED.getHeader());
150 calendarEvent.setContentColor(CalendarColor.RED.getContent());
151 calendarEvent.setBeginDate(iw.getBeginDate());
152 dates.add(calendarEvent.getBeginDate());
153 if(
new CheckDate(iw.getBeginDate()).sameDay(iw.getEndDate())) {
154 calendarEvent.setEndDate(iw.getEndDate());
155 dates.add(iw.getEndDate());
157 calendarEvent.setEndDate(calendarEvent.getBeginDate());
159 calendarEvent.setPath(DossierPU.getObjectPath(iw.getIssue()));
160 calendarEvent.setTitle(iw.getIssue().getDescription());
161 calendarEvent.setContent(getContent(iw));
162 calendarEvent.setMotive(I_.get(
"Start date"));
163 addAttandees(calendarEvent, iw);
164 calendarEvent.setEventId(Strings.identifier(
"ib" + iw.getId() +
165 ObjectString.formatObject(calendarEvent.getBeginDate(), ObjectString.COMPRESSED_DATE_PATTERN,
true)));
166 addResult(calendarEvent.getEventId(), calendarEvent);
168 if(iw.getEndDate()!=
null && !dates.contains(iw.getEndDate())) {
169 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
170 calendarEvent.setLocked(
false);
171 calendarEvent.setDone(iw.getIssue().getStatus().isFinished());
172 calendarEvent.setHeaderColor(CalendarColor.RED.getHeader());
173 calendarEvent.setContentColor(CalendarColor.RED.getContent());
174 calendarEvent.setBeginDate(iw.getEndDate());
175 dates.add(calendarEvent.getBeginDate());
176 calendarEvent.setEndDate(calendarEvent.getBeginDate());
177 calendarEvent.setPath(DossierPU.getObjectPath(iw.getIssue()));
178 calendarEvent.setTitle(iw.getIssue().getDescription());
179 calendarEvent.setContent(getContent(iw));
180 calendarEvent.setMotive(I_.get(
"End date"));
181 addAttandees(calendarEvent, iw);
182 calendarEvent.setEventId(Strings.identifier(
"ie" + iw.getId() +
183 ObjectString.formatObject(calendarEvent.getBeginDate(), ObjectString.COMPRESSED_DATE_PATTERN,
true)));
184 addResult(calendarEvent.getEventId(), calendarEvent);
186 if(iw.getControlDate() !=
null && !dates.contains(iw.getControlDate())) {
187 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
188 calendarEvent.setLocked(
false);
189 calendarEvent.setDone(iw.getIssue().getStatus().isFinished());
190 calendarEvent.setHeaderColor(CalendarColor.RED.getHeader());
191 calendarEvent.setContentColor(CalendarColor.RED.getContent());
192 calendarEvent.setBeginDate(iw.getControlDate());
193 dates.add(calendarEvent.getBeginDate());
194 calendarEvent.setEndDate(calendarEvent.getBeginDate());
195 calendarEvent.setPath(DossierPU.getObjectPath(iw.getIssue()));
196 calendarEvent.setTitle(iw.getIssue().getDescription());
197 calendarEvent.setContent(getContent(iw));
198 calendarEvent.setMotive(I_.get(
"Control"));
199 addAttandees(calendarEvent, iw);
200 calendarEvent.setEventId(Strings.identifier(
"ic" + iw.getId() +
201 ObjectString.formatObject(calendarEvent.getBeginDate(), ObjectString.COMPRESSED_DATE_PATTERN,
true)));
202 addResult(calendarEvent.getEventId(), calendarEvent);
204 if(iw.getIssue().getSolvedDate() !=
null && !dates.contains(iw.getIssue().getSolvedDate())) {
205 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
206 calendarEvent.setLocked(
false);
207 calendarEvent.setDone(iw.getIssue().getStatus().isFinished());
208 calendarEvent.setHeaderColor(CalendarColor.RED.getHeader());
209 calendarEvent.setContentColor(CalendarColor.RED.getContent());
210 calendarEvent.setBeginDate(iw.getIssue().getSolvedDate());
211 dates.add(calendarEvent.getBeginDate());
212 calendarEvent.setEndDate(calendarEvent.getBeginDate());
213 calendarEvent.setPath(DossierPU.getObjectPath(iw.getIssue()));
214 calendarEvent.setTitle(iw.getIssue().getDescription());
215 calendarEvent.setContent(getContent(iw));
216 calendarEvent.setMotive(I_.get(
"Closing"));
217 addAttandees(calendarEvent, iw);
218 calendarEvent.setEventId(Strings.identifier(
"ix" + iw.getId() +
219 ObjectString.formatObject(calendarEvent.getBeginDate(), ObjectString.COMPRESSED_DATE_PATTERN,
true)));
220 addResult(calendarEvent.getEventId(), calendarEvent);
222 if(iw.getIssue().getIssueDate() !=
null && !dates.contains(iw.getIssue().getIssueDate())) {
223 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
224 calendarEvent.setLocked(
false);
225 calendarEvent.setDone(iw.getIssue().getStatus().isFinished());
226 calendarEvent.setHeaderColor(CalendarColor.RED.getHeader());
227 calendarEvent.setContentColor(CalendarColor.RED.getContent());
228 calendarEvent.setBeginDate(iw.getIssue().getIssueDate());
229 dates.add(calendarEvent.getBeginDate());
230 calendarEvent.setEndDate(calendarEvent.getBeginDate());
231 calendarEvent.setPath(DossierPU.getObjectPath(iw.getIssue()));
232 calendarEvent.setTitle(iw.getIssue().getDescription());
233 calendarEvent.setContent(getContent(iw));
234 calendarEvent.setMotive(I_.get(
"Creation"));
235 addAttandees(calendarEvent, iw);
236 calendarEvent.setEventId(Strings.identifier(
"ir" + iw.getId() +
237 ObjectString.formatObject(calendarEvent.getBeginDate(), ObjectString.COMPRESSED_DATE_PATTERN,
true)));
238 addResult(calendarEvent.getEventId(), calendarEvent);
240 if(iw.getIssue().getModification()!=
null && !dates.contains(iw.getIssue().getModification())) {
241 DefaultCalendarEvent calendarEvent =
new DefaultCalendarEvent();
242 calendarEvent.setLocked(
false);
243 calendarEvent.setDone(iw.getIssue().getStatus().isFinished());
244 calendarEvent.setHeaderColor(CalendarColor.RED.getHeader());
245 calendarEvent.setContentColor(CalendarColor.RED.getContent());
246 calendarEvent.setBeginDate(iw.getIssue().getModification());
247 dates.add(calendarEvent.getBeginDate());
248 calendarEvent.setEndDate(calendarEvent.getBeginDate());
249 calendarEvent.setPath(DossierPU.getObjectPath(iw.getIssue()));
250 calendarEvent.setTitle(iw.getIssue().getDescription());
251 calendarEvent.setContent(getContent(iw));
252 calendarEvent.setMotive(I_.get(
"Modification"));
253 addAttandees(calendarEvent, iw);
254 calendarEvent.setEventId(Strings.identifier(
"im" + iw.getId() +
255 ObjectString.formatObject(calendarEvent.getBeginDate(), ObjectString.COMPRESSED_DATE_PATTERN,
true)));
256 addResult(calendarEvent.getEventId(), calendarEvent);
260 private String getContent(IssueWrapper iw) {
261 Path path =
new Path(DossierPU.getObjectPath(iw.getIssue()));
262 DescribeItCtrl dic =
new DescribeItCtrl(Application.getApplication().getConstructor());
263 dic.setEntityPath(path.getPath());
264 HashMap<String, Object> args =
new HashMap<>();
265 args.put(
"dic", dic);
266 return EntitiesInfo.getTextString(iw.getIssue(), iw,
"issue", EntityInfoType.SUMMARY, LinkType.NONE, args);
269 private void addAttandees(DefaultCalendarEvent calendarEvent, IssueWrapper iw) {
270 for(IssueParticipant ip : iw.getIssue().getParticipants()) {
271 if(calendarEvent.getOrganizer() ==
null && ip.getRole().equals(IssueParticipantRole.ISSUE_REPORTER)) {
272 calendarEvent.setOrganizer(ip.getIContact());
274 calendarEvent.addAttendee(ip.getIContact());
279 private String getMyIssuesContent() {
280 StringBuilder sb =
new StringBuilder();
281 for(IssueWrapper iw : iwl) {
282 sb.append(iw.getIssue().getDescription())
284 .append(I_.byKey(getStage(iw).toString()))
287 return sb.toString();
Object addResult(String key, Object value)
java.util.List< IssueWrapper > getIssueList()
void setByParticipant(IContact byParticipant)
void addClause(String clause)
void addNamedValue(String name, Object value)
static String get(String msg)
void setBeginDate(Date beginDate)
void setContentColor(String ccolor)
void setEventId(String eventId)
void setHeaderColor(String hcolor)
void setTitle(String title)
void setEndDate(Date endDate)
void setContent(String content)
void setLocked(boolean locked)
void setDone(boolean _done)
void setPath(String path)
ISSUE_STAGE_DATE_SURPASSED