BrightSide Workbench Full Report + Source Code
IssueEdit.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.dossier.zul.issue;
19 
20 import java.math.BigDecimal;
21 import java.util.Date;
22 import java.util.EnumSet;
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.elephant.context.Application;
30 import org.turro.elephant.zkoss.ModalWindow;
31 import org.turro.i18n.I_;
32 import org.turro.jpa.Dao;
33 import org.turro.log.SystemLogType;
34 import org.turro.log.SystemLogger;
35 import org.turro.registry.*;
36 import org.turro.related.RelatedItem;
37 import org.turro.related.Relateds;
38 
43 @Deprecated
44 public class IssueEdit extends ModalWindow {
45 
46  private Issue issue;
47  private IssueWrapper wrapper;
48  private boolean closeIssue = false, cancelEmail = false;
49  private double expenses = 0, hours = 0, price = 0;
50  private Changes changesManager = new Changes();
51  private ChangeCategory issueCat, commentCat;
52 
53  public IssueEdit() throws InterruptedException {
54  super();
55  issueCat = new ChangeCategory(2, I_.get("Changes"));
56  commentCat = new ChangeCategory(5, I_.get("Comment"));
57  }
58 
59  public IssueEdit(String title, String border, boolean closable) throws InterruptedException {
60  super(title, border, closable);
61  issueCat = new ChangeCategory(2, I_.get("Changes"));
62  commentCat = new ChangeCategory(5, I_.get("Comment"));
63  }
64 
65  public Changes getChanges() {
66  return changesManager;
67  }
68 
69  public void doAction(String action) {
70  if("1".equals(action)) {
71  saveWithStatus(getIssue().getStatus());
72  } else if("2".equals(action)) {
73  saveWithStatus(IssueStatus.STATUS_STARTED);
74  } else if("3".equals(action)) {
75  saveWithStatus(IssueStatus.STATUS_INCOMPLETE);
76  } else if("4".equals(action)) {
77  if(issue.getResolution().equals(IssueResolution.RESOLUTION_DUPLICATED) && issue.getDuplicated() == null) {
78  // throwm message exception
79  } else {
80  saveWithStatus(IssueStatus.STATUS_RESOLVED);
81  }
82  } else if("5".equals(action)) {
83  saveWithStatus(IssueStatus.STATUS_REOPENED);
84  } else if("6".equals(action)) {
85  saveWithStatus(IssueStatus.STATUS_REUNION);
86  } else if("7".equals(action)) {
87  saveWithStatus(IssueStatus.STATUS_FROZEN);
88  } else if("8".equals(action)) {
89  saveWithStatus(IssueStatus.STATUS_VERIFIED);
90  } else if("9".equals(action)) {
91  saveWithStatus(IssueStatus.STATUS_CLOSED);
92  }
93  }
94 
95  public String getLeaveAsLabel() {
96  return I_.get("Leave issue as") + ": " + I_.byKey(getIssue().getStatus().toString()) +
97  (getIssue().getStatus().isFinished() ? " " + I_.byKey(getIssue().getResolution().toString()) : "");
98  }
99 
100  public boolean getCanStart() {
102  .contains(getIssue().getStatus()) && isResponsible();
103  }
104 
105  public boolean getCanMarkAsIncomplete() {
106  return EnumSet.of(IssueStatus.STATUS_NEW, IssueStatus.STATUS_STARTED,
108  .contains(getIssue().getStatus()) && isResponsible();
109  }
110 
111  public boolean getCanFreeze() {
112  return EnumSet.of(IssueStatus.STATUS_NEW, IssueStatus.STATUS_STARTED,
114  .contains(getIssue().getStatus()) && (isResponsible() || isReporter());
115  }
116 
117  public boolean getCanResolve() {
120  .contains(getIssue().getStatus()) && isResponsible();
121  }
122 
123  public boolean getCanReopen() {
127  .contains(getIssue().getStatus()) && isParticipant();
128  }
129 
130  public boolean getCanVerify() {
131  return EnumSet.of(IssueStatus.STATUS_RESOLVED)
132  .contains(getIssue().getStatus()) && hasQA() && isQA();
133  }
134 
135  public boolean getCanClose() {
136  return (EnumSet.of(IssueStatus.STATUS_RESOLVED)
137  .contains(getIssue().getStatus()) && !hasQA() && (isParticipant())) ||
138  (EnumSet.of(IssueStatus.STATUS_VERIFIED)
139  .contains(getIssue().getStatus()) && hasQA() && (isParticipant()));
140  }
141 
142  public boolean getCanCheckClose() {
145  .contains(getIssue().getStatus()) && !hasQA() && (issue.getId() == null || isReporter() || isResponsible()));
146  }
147 
148  public boolean isParticipant() {
149  return getWrapper().isParticipant();
150  }
151 
152  public boolean isReporter() {
153  return getWrapper().isReporter();
154  }
155 
156  public boolean isResponsible() {
157  return getWrapper().isResponsible();
158  }
159 
160  public boolean isQA() {
161  return getWrapper().isQA();
162  }
163 
164  public boolean isAssistant() {
165  return getWrapper().isAssistant();
166  }
167 
168  public boolean hasQA() {
169  return getWrapper().hasQA();
170  }
171 
172  public void setIssueDossier(Dossier newValue) {
173  changesManager.addChange(new StringChange(issueCat, I_.get("Dossier"),
174  getIssue().getDossier() != null ? getIssue().getDossier().getDescription() : "",
175  newValue != null ? newValue.getDescription() : ""));
176  getIssue().setDossier(newValue);
177  }
178 
179  public void setIssueDescription(String newValue) {
180  changesManager.addChange(new StringChange(issueCat, I_.get("Description"), getIssue().getDescription(), newValue));
181  getIssue().setDescription(newValue);
182  }
183 
184  public void setIssueVersion(DossierVersion newValue) {
185  changesManager.addChange(new StringChange(issueCat, I_.get("Version"),
186  getIssue().getVersion() == null ? null : getIssue().getVersion().getVersionId(),
187  newValue == null ? null : newValue.getVersionId()));
188  getIssue().setVersion(newValue);
189  }
190 
191  public void setIssuePublishable(boolean newValue) {
192  changesManager.addChange(new BooleanChange(issueCat, I_.get("Publishable"), getIssue().isPublishable(), newValue));
193  getIssue().setPublishable(newValue);
194  }
195 
196  public void setIssueType(String newValue) {
197  changesManager.addChange(new EnumChange(issueCat, I_.get("Type"), getIssue().getType(), IssueType.valueOf(newValue)));
198  getIssue().setType(IssueType.valueOf(newValue));
199  }
200 
201  public void setIssueResolution(String newValue) {
202  changesManager.addChange(new EnumChange(issueCat, I_.get("Resolution"), getIssue().getResolution(), IssueResolution.valueOf(newValue)));
203  getIssue().setResolution(IssueResolution.valueOf(newValue));
204  }
205 
206  public void setIssuePriority(String newValue) {
207  changesManager.addChange(new EnumChange(issueCat, I_.get("Priority"), getIssue().getPriority(), IssuePriority.valueOf(newValue)));
208  getIssue().setPriority(IssuePriority.valueOf(newValue));
209  }
210 
211  public void setIssueStartDate(Date newValue) {
212  changesManager.addChange(new DateChange(issueCat, I_.get("Start date"), getIssue().getStartDate(), newValue));
213  getIssue().setStartDate(newValue);
214  }
215 
216  public void setIssueDelivery(Date newValue) {
217  changesManager.addChange(new DateChange(issueCat, I_.get("Delivery"), getIssue().getDelivery(), newValue));
218  getIssue().setDelivery(newValue);
219  }
220 
221  public void setIssueControlDate(Date newValue) {
222  changesManager.addChange(new DateChange(issueCat, I_.get("Control"), getIssue().getControlDate(), newValue));
223  getIssue().setControlDate(newValue);
224  }
225 
226  public void setIssueComment(String newValue) {
227  changesManager.addComment(commentCat, newValue);
228  }
229 
230  public void setIssuePrevExpenses(BigDecimal newValue) {
231  changesManager.addChange(new NumberChange(issueCat, I_.get("Prevision") + "/" + I_.get("Expenses"), getIssue().getExpenses(), newValue));
232  getIssue().setExpenses(newValue.doubleValue());
233  }
234 
235  public void setIssuePrevHours(BigDecimal newValue) {
236  changesManager.addChange(new NumberChange(issueCat, I_.get("Prevision") + "/" + I_.get("Hours"), getIssue().getHours(), newValue));
237  getIssue().setHours(newValue.doubleValue());
238  }
239 
240  public void setIssuePrevPrice(BigDecimal newValue) {
241  changesManager.addChange(new NumberChange(issueCat, I_.get("Prevision") + "/" + I_.get("Price"), getIssue().getPrice(), newValue));
242  getIssue().setPrice(newValue.doubleValue());
243  }
244 
245  public void setIssueExpenses(BigDecimal newValue) {
246  changesManager.addChange(new UniqueNumber(issueCat, I_.get("Expenses"), newValue));
247  expenses = newValue.doubleValue();
248  }
249 
250  public void setIssueHours(BigDecimal newValue) {
251  changesManager.addChange(new UniqueNumber(issueCat, I_.get("Hours"), newValue));
252  hours = newValue.doubleValue();
253  }
254 
255  public void setIssuePrice(BigDecimal newValue) {
256  changesManager.addChange(new UniqueNumber(issueCat, I_.get("Price"), newValue));
257  price = newValue.doubleValue();
258  }
259 
260  public void setIssueDuplicated(Issue duplicated) {
261  if(issue.equals(duplicated)) {
262  duplicated = null;
263  }
264  changesManager.addChange(new StringChange(issueCat, I_.get("Duplicated"),
265  issue.getDuplicated() != null ? issue.getDuplicated().getDescription() : "",
266  duplicated != null ? duplicated.getDescription() : ""));
267  issue.setDuplicated(duplicated);
268  }
269 
270  public void setCloseIssue(boolean value) {
271  closeIssue = value;
272  }
273 
274  public void setCancelEmail(boolean value) {
275  cancelEmail = value;
276  }
277 
278  private Issue getIssue() {
279  if(issue == null) {
280  issue = (Issue) getPage().getZScriptVariable("issue");
281  wrapper = new IssueWrapper(issue);
282  if(!issue.getStatus().isFinished()) {
284  }
285  }
286  return issue;
287  }
288 
289  private IssueWrapper getWrapper() {
290  getIssue();
291  return wrapper;
292  }
293 
294  private void saveWithStatus(IssueStatus status) {
295  boolean doMail = false;
296  changesManager.addChange(new EnumChange(issueCat, I_.get("Status"), getIssue().getStatus(), status, true));
297  getIssue().setStatus(status);
298  if(!getIssue().getStatus().isFinished()) {
300  }
301  if(!(issue.getResolution().equals(IssueResolution.RESOLUTION_DUPLICATED))) {
302  issue.setDuplicated(null);
303  }
304  if(closeIssue) {
305  changesManager.addChange(new EnumChange(issueCat, I_.get("Status"), getIssue().getStatus(), IssueStatus.STATUS_CLOSED, true));
306  getIssue().setStatus(IssueStatus.STATUS_CLOSED);
307  if(getIssue().getResolution() == IssueResolution.RESOLUTION_NONE) {
308  changesManager.addChange(new EnumChange(issueCat, I_.get("Resolution"), getIssue().getResolution(), IssueResolution.RESOLUTION_FIXED));
310  }
311  }
312  if(!wrapper.hasReporter()) {
313  IssueParticipant ip = issue.addReporter(Authentication.getIContact());
314  if(changesManager != null) {
315  ChangeCategory cc = new ChangeCategory(4, I_.get("Participants"));
316  changesManager.addChange(new UniqueString(cc, I_.byKey(ip.getRole().toString()), ip.getName()));
317  }
318  }
319  if(!wrapper.hasResponsible()) {
320  IssueParticipant ip = null;
321  if(Application.getApplication().isInRole("issue:participants")) {
322  //if can see participants
323  ip = issue.addResponsible(Authentication.getIContact());
324  } else if(issue.getDossier() != null) {
325  // otherwise, assign responsible to the first owner encountered
326  ip = issue.addResponsible(issue.getDossier().getDefaultResponsible());
327  }
328  if(changesManager != null) {
329  ChangeCategory cc = new ChangeCategory(4, I_.get("Participants"));
330  changesManager.addChange(new UniqueString(cc, I_.byKey(ip.getRole().toString()), ip.getName()));
331  }
332  }
333  changesManager.clearEquals();
334  if(changesManager.size() > 0) {
335  IssueComment ic = new IssueComment();
336  ic.setIssue(getIssue());
337  ic.setModification(new Date());
338  ic.setParticipantName(Authentication.getIContact().getName());
339  ic.setComment(changesManager.getChangesString());
340  ic.setExpenses(expenses);
341  ic.setHours(hours);
342  ic.setPrice(price);
343  ic.setProcessed(expenses == 0 && hours == 0 && price == 0);
344  getIssue().getComments().add(ic);
345  doMail = true;
346  }
347  getIssue().setModification(new Date());
348  wrapper.clearEmpties();
349  Dao dao = new DossierPU();
350  RelatedItem rpi = getIssue().getRelated();
351  issue = dao.saveObject(getIssue());
352  if(!Strings.isBlank(rpi.getRelatedPath())) {
353  Relateds.from(rpi.getRelatedPath()).addDestination(
354  DossierPU.getObjectPath(issue),
355  rpi.getDescription());
356  }
357  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, issue, "saved",
358  issue.getId() + " - " + issue.getDescription());
359  if(issue.getDossier() != null && !issue.getDossier().getStatus().equals(DossierStatus.DOSSIER_OPENED)) {
361  dao.saveObject(issue.getDossier());
362  }
363  getDesktop().setAttribute("issueId", issue.getId());
364  setResult(1);
365  if(doMail && !cancelEmail) {
366  new IssueMail(changesManager, issue, expenses, hours, price).sendMail();
367  }
368  detach();
369  }
370 
371 // public static void addParticipantsComment(Issue issue) {
372 // IssueComment ic = new IssueComment();
373 // ic.setIssue(issue);
374 // ic.setModification(new Date());
375 // ic.setParticipantName(Framework.getRealIContact().getName());
376 // ic.setComment(IssueEdit.getParticipantsString(issue));
377 // ic.setExpenses(0);
378 // ic.setHours(0);
379 // ic.setPrice(0);
380 // issue.getComments().add(ic);
381 // issue.setModification(new Date());
382 // issue = new DossierPU().saveObject(issue);
383 // new IssueMail(null, ic.getComment(), issue, 0, 0, 0).sendMail();
384 // }
385 
386 // public static String getParticipantsString(Issue issue) {
387 // StringBuffer sb = new StringBuffer();
388 // sb.append("\n");
389 // for(IssueParticipant ip : issue.getParticipants()) {
390 // sb.append("\n");
391 // sb.append(ip.getName() + ": ");
392 // sb.append(Application.getString(ip.getRole().toString()));
393 // }
394 // return sb.toString();
395 // }
396 
397 // public static void addRelationsComment(Issue issue) {
398 // IssueComment ic = new IssueComment();
399 // ic.setIssue(issue);
400 // ic.setModification(new Date());
401 // ic.setParticipantName(Framework.getRealIContact().getName());
402 // ic.setComment(IssueEdit.getRelationsString(issue));
403 // ic.setExpenses(0);
404 // ic.setHours(0);
405 // ic.setPrice(0);
406 // issue.getComments().add(ic);
407 // issue.setModification(new Date());
408 // issue = new DossierPU().saveObject(issue);
409 // new IssueMail(null, ic.getComment(), issue, 0, 0, 0).sendMail();
410 // }
411 //
412 // public static String getRelationsString(Issue issue) {
413 // StringBuffer sb = new StringBuffer();
414 // IssueWrapper iw = new IssueWrapper(issue);
415 // for(IssuePredecessor ip : iw.getSources()) {
416 // sb.append("\n");
417 // sb.append("#" + ip.getTarget().getId());
418 // sb.append(" ");
419 // sb.append(ip.getTarget().getDescription());
420 // sb.append(" ");
421 // sb.append(Application.getString(ip.getType().toString()));
422 // sb.append(" ");
423 // sb.append("#" + ip.getSource().getId());
424 // sb.append(" ");
425 // sb.append(ip.getSource().getDescription());
426 // }
427 // for(IssuePredecessor ip : iw.getTargets()) {
428 // sb.append("\n");
429 // sb.append("#" + ip.getTarget().getId());
430 // sb.append(" ");
431 // sb.append(ip.getTarget().getDescription());
432 // sb.append(" ");
433 // sb.append(Application.getString(ip.getType().toString()));
434 // sb.append(" ");
435 // sb.append("#" + ip.getSource().getId());
436 // sb.append(" ");
437 // sb.append(ip.getSource().getDescription());
438 // }
439 // return sb.toString();
440 // }
441 
442 }
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 setParticipantName(String participantName)
void setPublishable(boolean publishable)
Definition: Issue.java:218
void setType(IssueType type)
Definition: Issue.java:295
IssueResolution getResolution()
Definition: Issue.java:226
void setResolution(IssueResolution resolution)
Definition: Issue.java:230
void setDescription(String description)
Definition: Issue.java:154
void setModification(Date modification)
Definition: Issue.java:202
IssueParticipant addReporter(Object contact)
Definition: Issue.java:397
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
IssueParticipant addResponsible(Object contact)
Definition: Issue.java:403
void setPrice(double price)
Definition: Issue.java:319
void setExpenses(double expenses)
Definition: Issue.java:303
void setDelivery(Date delivery)
Definition: Issue.java:146
void setIssuePrevHours(BigDecimal newValue)
Definition: IssueEdit.java:235
IssueEdit(String title, String border, boolean closable)
Definition: IssueEdit.java:59
void setIssueVersion(DossierVersion newValue)
Definition: IssueEdit.java:184
void setIssuePrevPrice(BigDecimal newValue)
Definition: IssueEdit.java:240
void setIssueDelivery(Date newValue)
Definition: IssueEdit.java:216
void setIssueControlDate(Date newValue)
Definition: IssueEdit.java:221
void setIssueComment(String newValue)
Definition: IssueEdit.java:226
void setIssuePrice(BigDecimal newValue)
Definition: IssueEdit.java:255
void setIssueStartDate(Date newValue)
Definition: IssueEdit.java:211
void setIssuePrevExpenses(BigDecimal newValue)
Definition: IssueEdit.java:230
void setIssueDuplicated(Issue duplicated)
Definition: IssueEdit.java:260
void setIssueExpenses(BigDecimal newValue)
Definition: IssueEdit.java:245
void setIssuePriority(String newValue)
Definition: IssueEdit.java:206
void setIssuePublishable(boolean newValue)
Definition: IssueEdit.java:191
void setIssueHours(BigDecimal newValue)
Definition: IssueEdit.java:250
void setIssueDossier(Dossier newValue)
Definition: IssueEdit.java:172
void setIssueType(String newValue)
Definition: IssueEdit.java:196
void setIssueDescription(String newValue)
Definition: IssueEdit.java:179
void setIssueResolution(String newValue)
Definition: IssueEdit.java:201
static String byKey(String key)
Definition: I_.java:83
static String get(String msg)
Definition: I_.java:41