BrightSide Workbench Full Report + Source Code
ResolvePanel.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.issue.wizard;
20 
21 import java.util.Date;
22 import org.amic.util.date.CheckDate;
23 import org.turro.string.Strings;
24 import org.turro.auth.Authentication;
25 import org.turro.dossier.db.DossierPU;
26 import org.turro.dossier.entity.*;
27 import org.turro.dossier.issue.IssueMail;
28 import org.turro.dossier.issue.IssueWrapper;
29 import org.turro.dossier.zul.issue.IssueResolutionListbox;
30 import org.turro.dossier.zul.menu.DossierMenu;
31 import org.turro.elephant.context.Application;
32 import org.turro.entities.EntityCombobox;
33 import org.turro.i18n.I_;
34 import org.turro.jpa.Dao;
35 import org.turro.jpa.entity.EntityArray;
36 import org.turro.log.SystemLogType;
37 import org.turro.log.SystemLogger;
38 import org.turro.registry.ChangeCategory;
39 import org.turro.registry.EnumChange;
40 import org.turro.registry.StringChange;
41 import org.turro.related.RelatedItem;
42 import org.turro.related.Relateds;
43 import org.turro.zkoss.wizard.WizardPanelComposer;
44 import org.zkoss.zul.Checkbox;
45 import org.zkoss.zul.Hlayout;
46 import org.zkoss.zul.Radio;
47 import org.zkoss.zul.Radiogroup;
48 
53 public class ResolvePanel extends WizardPanelComposer {
54 
55  private Radiogroup action;
56  private Radio leaveAs, start, incomplete, resolve,
57  reopen, reunion, freeze, verify, close;
58  private Checkbox doClose, noEmail, show;
59  private Hlayout resolveBox;
60  private IssueResolutionListbox resolution;
61  private EntityCombobox duplicated;
62 
63  private IssueWizard iw;
64  private IssueWrapper wrapper;
65 
66  @Override
67  public boolean doEnter() {
69  iw = (IssueWizard) getObjectValue();
70  wrapper = new IssueWrapper(iw.issue);
71  leaveAs.setLabel(getLeaveAsLabel());
72  leaveAs.setChecked(true);
73  start.setVisible(getCanStart());
74  incomplete.setVisible(getCanMarkAsIncomplete());
75  resolveBox.setVisible(getCanResolve());
76  duplicated.setObjectValue(iw.issue.getDuplicated());
77  resolution.setObjectValue(IssueResolution.RESOLUTION_FIXED);
78  reopen.setVisible(getCanReopen());
79  freeze.setVisible(getCanFreeze());
80  verify.setVisible(getCanVerify());
81  close.setVisible(getCanClose());
82  doClose.setVisible(getCanCheckClose());
83  noEmail.setVisible(app.isInRole("issue:cancel-email"));
84  show.setLabel(I_.get("Show") + ": " + iw.issue.getFullDescription());
85  onSelect$resolution();
86  return true;
87  }
88 
89  @Override
90  public boolean doLeave(boolean forwards) {
91  ChangeCategory issueCat = new ChangeCategory(2, I_.get("Changes"));
92  iw = (IssueWizard) getObjectValue();
93 
94  IssueStatus status = iw.issue.getStatus();
95 
96  boolean couldResolve = getCanResolve();
97 
98  if(start.isChecked()) {
99  status = IssueStatus.STATUS_STARTED;
100  } else if(incomplete.isChecked()) {
102  } else if(resolve.isChecked()) {
103  if(resolution.getObjectValue().equals(IssueResolution.RESOLUTION_DUPLICATED) && duplicated.getObjectValue() == null) {
104  // throwm message exception
105  } else {
106  status = IssueStatus.STATUS_RESOLVED;
107  }
108  } else if(reopen.isChecked()) {
109  status = IssueStatus.STATUS_REOPENED;
110  } else if(reunion.isChecked()) {
111  status = IssueStatus.STATUS_REUNION;
112  } else if(freeze.isChecked()) {
113  status = IssueStatus.STATUS_FROZEN;
114  } else if(verify.isChecked()) {
115  status = IssueStatus.STATUS_VERIFIED;
116  } else if(close.isChecked()) {
117  status = IssueStatus.STATUS_CLOSED;
118  }
119 
120  iw.changes.addChange(new EnumChange(issueCat, I_.get("Status"), iw.issue.getStatus(), status, false));
121  iw.issue.setStatus(status, iw.date);
122  if(!(iw.issue.getStatus().isFinished())) {
124  iw.issue.setDuplicated(null);
125  } else if(couldResolve) {
126  iw.changes.addChange(new EnumChange(issueCat, I_.get("Resolution"),
127  iw.issue.getResolution(), resolution.getObjectValue(), false));
128  iw.issue.setResolution(resolution.getObjectValue());
130  iw.changes.addChange(new StringChange(issueCat, I_.get("Duplicated"),
131  iw.issue.getDuplicated() != null ? iw.issue.getDuplicated().getDescription() : "",
132  duplicated != null ? ((Issue) duplicated.getObjectValue()).getDescription() : ""));
133  iw.issue.setDuplicated((Issue) duplicated.getObjectValue());
134  } else {
135  iw.issue.setDuplicated(null);
136  }
137  }
138  if(doClose.isChecked()) {
139  iw.changes.addChange(new EnumChange(issueCat, I_.get("Status"),
140  iw.issue.getStatus(), IssueStatus.STATUS_CLOSED, false));
143  iw.changes.addChange(new EnumChange(issueCat, I_.get("Resolution"),
146  }
147  }
148  iw.issue.setModification(iw.date);
149  wrapper.clearEmpties();
150  iw.show = show.isChecked();
151  iw.cancelMail = noEmail.isChecked();
152 
153  ResolvePanel.saveIssue(iw, true);
154 
155  return !forwards || ( true );
156  }
157 
158  @Override
159  public boolean doFinish() {
160  ResolvePanel.saveIssue(iw, false);
161  ResolvePanel.array(iw);
162  return true;
163  }
164 
165  public void onSelect$resolution() {
166  duplicated.setVisible(resolution.getObjectValue().equals(IssueResolution.RESOLUTION_DUPLICATED));
167  if(!duplicated.isVisible()) {
168  duplicated.setObjectValue(null);
169  }
170  }
171 
172  public boolean isParticipant() {
173  return wrapper.isParticipant();
174  }
175 
176  public boolean isReporter() {
177  return wrapper.isReporter();
178  }
179 
180  public boolean isResponsible() {
181  return wrapper.isResponsible();
182  }
183 
184  public boolean isQA() {
185  return wrapper.isQA();
186  }
187 
188  public boolean isAssistant() {
189  return wrapper.isAssistant();
190  }
191 
192  public boolean hasQA() {
193  return wrapper.hasQA();
194  }
195 
196  public String getLeaveAsLabel() {
197  return wrapper.getLeaveAsLabel();
198  }
199 
200  public boolean getCanStart() {
201  return wrapper.getCanStart();
202  }
203 
204  public boolean getCanMarkAsIncomplete() {
205  return wrapper.getCanMarkAsIncomplete();
206  }
207 
208  public boolean getCanFreeze() {
209  return wrapper.getCanFreeze();
210  }
211 
212  public boolean getCanResolve() {
213  return wrapper.getCanResolve();
214  }
215 
216  public boolean getCanReopen() {
217  return wrapper.getCanReopen();
218  }
219 
220  public boolean getCanVerify() {
221  return wrapper.getCanVerify();
222  }
223 
224  public boolean getCanClose() {
225  return wrapper.getCanClose();
226  }
227 
228  public boolean getCanCheckClose() {
229  return wrapper.getCanCheckClose();
230  }
231 
232  public static void array(IssueWizard iw) {
233  if(iw.issue.getStartDate() == null) return;
234  if(!EntityArray.ARRAY_NO_REPEAT.equals(iw.repeat) && iw.repeatCount > 0) {
235  for(int i = 0; i < iw.repeatCount; i++) {
236  Issue clone = cloneFrom(iw.issue);
237  setDatesFor(clone, i + 1, iw);
238  Dao dao = new DossierPU();
239  dao.saveObject(clone);
240  }
241  }
242  }
243 
244  private static void setDatesFor(Issue clone, int count, IssueWizard iw) {
245  switch(iw.repeat) {
246  case ARRAY_EVERY_DAY:
247  clone.setStartDate(new CheckDate(iw.issue.getStartDate()).addDays(count).getDate());
248  if(iw.issue.getControlDate() != null) {
249  clone.setControlDate(new CheckDate(iw.issue.getControlDate()).addDays(count).getDate());
250  }
251  if(iw.issue.getDelivery()!= null) {
252  clone.setDelivery(new CheckDate(iw.issue.getDelivery()).addDays(count).getDate());
253  }
254  break;
255  case ARRAY_EVERY_WEEK:
256  clone.setStartDate(new CheckDate(iw.issue.getStartDate()).addWeeks(count).getDate());
257  if(iw.issue.getControlDate() != null) {
258  clone.setControlDate(new CheckDate(iw.issue.getControlDate()).addWeeks(count).getDate());
259  }
260  if(iw.issue.getDelivery()!= null) {
261  clone.setDelivery(new CheckDate(iw.issue.getDelivery()).addWeeks(count).getDate());
262  }
263  break;
264  case ARRAY_EVERY_MONTH:
265  clone.setStartDate(new CheckDate(iw.issue.getStartDate()).addMonths(count).getDate());
266  if(iw.issue.getControlDate() != null) {
267  clone.setControlDate(new CheckDate(iw.issue.getControlDate()).addMonths(count).getDate());
268  }
269  if(iw.issue.getDelivery()!= null) {
270  clone.setDelivery(new CheckDate(iw.issue.getDelivery()).addMonths(count).getDate());
271  }
272  break;
273  case ARRAY_EVERY_YEAR:
274  clone.setStartDate(new CheckDate(iw.issue.getStartDate()).addYears(count).getDate());
275  if(iw.issue.getControlDate() != null) {
276  clone.setControlDate(new CheckDate(iw.issue.getControlDate()).addYears(count).getDate());
277  }
278  if(iw.issue.getDelivery()!= null) {
279  clone.setDelivery(new CheckDate(iw.issue.getDelivery()).addYears(count).getDate());
280  }
281  break;
282  }
283  }
284 
285  public static Issue cloneFrom(Issue issue) {
286  Issue clone = new Issue();
287  clone.setDescription(issue.getDescription());
288  clone.setDossier(issue.getDossier());
289  clone.setExpenses(issue.getExpenses());
290  clone.setHours(issue.getHours());
291  clone.setIssueDate(issue.getIssueDate());
292  clone.setModification(new Date());
293  clone.setPrice(issue.getPrice());
294  clone.setPriority(issue.getPriority());
295  clone.setPublishable(issue.isPublishable());
296  clone.setStatus(issue.getStatus());
297  clone.setResolution(issue.getResolution());
298  clone.setType(issue.getType());
299  clone.setVersion(issue.getVersion());
300  for(IssueParticipant ip : issue.getParticipants()) {
302  nip.setIdContact(ip.getIdContact());
303  nip.setIssue(clone);
304  nip.setName(ip.getName());
305  nip.setRole(ip.getRole());
306  clone.getParticipants().add(nip);
307  }
308  IssueComment ic = new IssueComment();
310  ic.setComment("Clone #" + issue.getId());
311  ic.setIssue(clone);
312  ic.setModification(clone.getModification());
313  clone.getComments().add(ic);
314  return clone;
315  }
316 
317  public static void saveIssue(IssueWizard iw, boolean onlySave) {
318  if(iw.changes.isEmpty()) return;
319  Dao dao = new DossierPU();
320  RelatedItem rpi = iw.issue.getRelated();
321  if(iw.issue.getComments().isEmpty()) {
322  iw.issue.setIssueDate(iw.date);
323  }
324  if(!onlySave) {
325  if(iw.subtask != null) {
326  iw.subtask.save(dao, iw.issue);
327  }
328  iw.changes.clearEquals();
329  if(iw.changes.stringSize() > 0) {
330  String cloneString = "";
331  if(iw.issue.getStartDate() != null && !EntityArray.ARRAY_NO_REPEAT.equals(iw.repeat) && iw.repeatCount > 0) {
332  cloneString = "\n\n Clone: " + iw.repeatCount + " " + I_.byKey(iw.repeat.toString());
333  }
334  IssueComment ic = new IssueComment();
335  ic.setIssue(iw.issue);
336  ic.setModification(iw.date);
338  ic.setComment(iw.changes.getChangesString() + cloneString);
339  ic.setExpenses(iw.expenses);
340  ic.setHours(iw.hours);
341  ic.setPrice(iw.price);
342  ic.setProcessed(iw.expenses == 0 && iw.hours == 0 && iw.price == 0);
343  iw.issue.getComments().add(ic);
344  }
345  }
346  iw.issue = dao.saveObject(iw.issue);
347  if(!Strings.isBlank(rpi.getRelatedPath())) {
350  rpi.getDescription());
351  }
352  if(iw.issue.getDossier() != null && !iw.issue.getDossier().getStatus().equals(DossierStatus.DOSSIER_OPENED)) {
354  iw.issue.setDossier(dao.saveObject(iw.issue.getDossier()));
355  }
356  if(!onlySave) {
358  iw.issue.getId() + " - " + iw.issue.getDescription());
359  if(!iw.cancelMail) {
360  new IssueMail(iw.changes, iw.issue, iw.expenses, iw.hours, iw.price).sendMail();
361  }
362  iw.changes.clear();
363  if(iw.show) {
365  }
366  }
368  }
369 
370 }
static String getObjectPath(Object object)
Definition: DossierPU.java:66
void setStatus(DossierStatus status)
Definition: Dossier.java:195
void setProcessed(boolean processed)
void setModification(Date modification)
void setRole(IssueParticipantRole role)
void setPublishable(boolean publishable)
Definition: Issue.java:218
void setType(IssueType type)
Definition: Issue.java:295
IssueResolution getResolution()
Definition: Issue.java:226
IssuePriority getPriority()
Definition: Issue.java:206
void setResolution(IssueResolution resolution)
Definition: Issue.java:230
void setDescription(String description)
Definition: Issue.java:154
void setModification(Date modification)
Definition: Issue.java:202
void setVersion(DossierVersion version)
Definition: Issue.java:335
void setStatus(IssueStatus status)
Definition: Issue.java:246
void setDossier(Dossier dossier)
Definition: Issue.java:162
void setControlDate(Date controlDate)
Definition: Issue.java:138
void setPriority(IssuePriority priority)
Definition: Issue.java:210
Set< IssueComment > getComments()
Definition: Issue.java:122
void setDuplicated(Issue duplicated)
Definition: Issue.java:170
void setStartDate(Date startDate)
Definition: Issue.java:327
void setHours(double hours)
Definition: Issue.java:311
DossierVersion getVersion()
Definition: Issue.java:331
Set< IssueParticipant > getParticipants()
Definition: Issue.java:114
void setIssueDate(Date issueDate)
Definition: Issue.java:186
void setPrice(double price)
Definition: Issue.java:319
void setExpenses(double expenses)
Definition: Issue.java:303
void setDelivery(Date delivery)
Definition: Issue.java:146
static void checkPendingRevision(Issue issue)
IssuePredecessor save(Dao dao, Issue task)
Definition: Subtask.java:42
static String byKey(String key)
Definition: I_.java:83
static String get(String msg)
Definition: I_.java:41
static void saveIssue(IssueWizard iw, boolean onlySave)
boolean doLeave(boolean forwards)
static void array(IssueWizard iw)
static Issue cloneFrom(Issue issue)
static ISystemLogger getInstance()
static Relateds from(String entityPath)
Definition: Relateds.java:145
Related addDestination(String destination, String description)
Definition: Relateds.java:41
void doLog(SystemLogType type, Object entity, String comment, Serializable data)