BrightSide Workbench Full Report + Source Code
TaskClone.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.clone;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Date;
24 import java.util.HashSet;
25 import java.util.Set;
26 import org.turro.clone.ClonedEntity;
27 import org.turro.clone.ClonedEntitySet;
28 import org.turro.erp.entity.AptitudeDegree;
29 import org.turro.erp.entity.OwnedAptitude;
30 import org.turro.erp.entity.Predecessor;
31 import org.turro.erp.entity.RequiredUsage;
32 import org.turro.erp.entity.Task;
33 import org.turro.hierarchy.Hierarchical;
34 
39 public class TaskClone extends ClonedEntity<Task, Long> implements Hierarchical {
40 
41  private String name;
42  private String description;
43  private OwnedAptitude supervised;
44  private AptitudeDegree aptitudeDegree;
45  private Date startDate;
46  private Date endDate;
47  private Date delivery;
48  private boolean milestone;
49  private OrderReferenceClone orderReference;
50  private long departmentId;
51  private Set<PredecessorClone> predecessors = new HashSet<PredecessorClone>();
52  private Set<RequiredUsageClone> requiredUsages = new HashSet<RequiredUsageClone>();
53 
54  public TaskClone(Task task, ClonedEntitySet entities) {
55  super(task.getId(), task, entities);
56  name = task.getName();
57  description = task.getDescription();
58  supervised = task.getSupervised();
59  aptitudeDegree = task.getAptitudeDegree();
60  startDate = task.getStartDate();
61  endDate = task.getEndDate();
62  delivery = task.getDelivery();
63  milestone = task.isMilestone();
64  departmentId = task.getDepartmentId();
65  for(RequiredUsage requiredUsage : task.getRequiredUsages()) {
66  if(requiredUsage.getId() > 0) {
67  RequiredUsageClone ru = new RequiredUsageClone(requiredUsage, entities);
68  ru.setTask(this);
69  requiredUsages.add((RequiredUsageClone) entities.addClonedEntity(ru));
70  }
71  }
72  for(Predecessor predecessor : task.getPredecessors()) {
73  if(predecessor.getId() > 0) {
74  PredecessorClone pre = new PredecessorClone(predecessor, entities);
75  pre.setTask(this);
76  predecessors.add((PredecessorClone) entities.addClonedEntity(pre));
77  }
78  }
79  }
80 
81  public void setOrderReference(OrderReferenceClone orderReference) {
82  this.orderReference = orderReference;
83  }
84 
85  public Set<RequiredUsageClone> getRequiredUsages() {
86  return requiredUsages;
87  }
88 
89  @Override
90  protected Task createClone() {
91  Task task = new Task();
92  applyData(task);
93  for(RequiredUsageClone requiredUsageClone : requiredUsages) {
94  requiredUsageClone.generateClone();
95  RequiredUsage requiredUsage = requiredUsageClone.getClone();
96  requiredUsage.setTask(task);
97  task.getRequiredUsages().add(requiredUsage);
98  }
99  for(PredecessorClone predecessorClone : predecessors) {
100  predecessorClone.generateClone();
101  Predecessor predecessor = predecessorClone.getClone();
102  predecessor.setTask(task);
103  task.getPredecessors().add(predecessor);
104  }
105  return task;
106  }
107 
108  @Override
109  protected void applyData(Task entity) {
110  entity.setName(name);
111  entity.setDescription(description);
112  entity.setSupervised(supervised);
113  entity.setAptitudeDegree(aptitudeDegree);
114  entity.setStartDate(startDate);
115  entity.setEndDate(endDate);
116  entity.setDelivery(delivery);
117  entity.setMilestone(milestone);
118  entity.setDepartmentId(departmentId);
119  }
120 
121  @Override
122  protected void applyChildren(Task entity) {
123  for(RequiredUsageClone requiredUsageClone : requiredUsages) {
124  requiredUsageClone.applyChanges();
125  }
126  for(PredecessorClone predecessorClone : predecessors) {
127  predecessorClone.applyChanges();
128  }
129  }
130 
131  @Override
132  protected void assignEntities() {
133  for(RequiredUsageClone requiredUsageClone : requiredUsages) {
134  requiredUsageClone.assignEntities();
135  }
136  for(PredecessorClone predecessorClone : predecessors) {
137  predecessorClone.assignEntities();
138  }
139  }
140 
141  /* Hierarchical */
142 
143  @Override
144  public Collection children() {
145  ArrayList list = new ArrayList();
146  list.add(requiredUsages);
147  list.add(predecessors);
148  return list;
149  }
150 
151  @Override
152  public Object parent() {
153  return orderReference;
154  }
155 
156 }
void applyData(Task entity)
Definition: TaskClone.java:109
Set< RequiredUsageClone > getRequiredUsages()
Definition: TaskClone.java:85
void applyChildren(Task entity)
Definition: TaskClone.java:122
TaskClone(Task task, ClonedEntitySet entities)
Definition: TaskClone.java:54
void setOrderReference(OrderReferenceClone orderReference)
Definition: TaskClone.java:81