BrightSide Workbench Full Report + Source Code
TaskStatusWrapper.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.erp.task;
20 
21 import java.util.Date;
22 import java.util.EnumSet;
23 import org.turro.erp.entity.*;
24 import org.turro.status.Status;
25 
30 public class TaskStatusWrapper extends Status<TaskStatus> {
31 
32  private Task task;
33 
34  public TaskStatusWrapper(Task task, Date now) {
35  super(task.getStatus());
36  this.task = task;
37  checkStatus(now);
38  }
39 
40  @Override
41  protected TaskStatus doCheckStatus(Date now) {
42  TaskStatus status = current;
43  boolean waiting = task.isWaiting();
44  if(TaskStatus.isReady(status)) {
45  for(RequiredUsage ru : task.getRequiredUsages()) {
46  if(ru.getStatus().hasMovement()) {
47  status = TaskStatus.TASK_ONWORK;
48  }
49  }
50  if(TaskStatus.isReady(status)) {
51  if(task.getStartDate() != null && task.getStartDate().after(now)) {
52  waiting = true;
53  } else {
54  waiting = false;
55  for(Predecessor p : task.getPredecessors()) {
56  Task tp = p.getPredecessor();
57  tp.checkStatus(now);
58  if(p.getType().equals(PredecessorType.START_WHEN_STARTS) && !TaskStatus.hasStarted(tp.getStatus())) {
59  waiting = true;
60  break;
61  } else if(p.getType().equals(PredecessorType.START_WHEN_ENDS) && !TaskStatus.isFinished(tp.getStatus())) {
62  waiting = true;
63  break;
64  }
65  }
66  }
67  }
68  }
69  if(TaskStatus.isOnWork(status) && !task.getRequiredUsages().isEmpty()) {
70  boolean isFinished = true;
71  for(RequiredUsage pu : task.getRequiredUsages()) {
72  if(pu.isHumanResourceType() ||
73  (pu.isProductType() && !pu.getStatus().equals(UsageStatus.USAGE_RECEIVED))) {
74  isFinished = false;
75  break;
76  }
77  }
78  if(isFinished) {
79  status = TaskStatus.TASK_FINISHED;
80  }
81  }
82  task.setWaiting(waiting);
83  return status;
84  }
85 
86  @Override
87  protected TaskStatus doChangeTo(TaskStatus newStatus) {
88  task.setStatus(newStatus);
89  return newStatus;
90  }
91 
92  @Override
93  public boolean canChangeTo(TaskStatus newStatus) {
94  if(current.equals(TaskStatus.TASK_PLANNING)) {
95  return EnumSet.of(
98  TaskStatus.TASK_FINISHED).contains(newStatus) &&
99  task.canStart();
100  } else if(current.equals(TaskStatus.TASK_READY)) {
101  return EnumSet.of(
103  TaskStatus.TASK_FINISHED).contains(newStatus) &&
104  task.canStart();
105  } else if(current.equals(TaskStatus.TASK_ONWORK)) {
106  return EnumSet.of(
107  TaskStatus.TASK_FINISHED).contains(newStatus);
108  }
109  return false;
110  }
111 
112 }
TaskStatus doChangeTo(TaskStatus newStatus)
boolean canChangeTo(TaskStatus newStatus)