BrightSide Workbench Full Report + Source Code
WorkOrderClone.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.Collection;
22 import java.util.HashSet;
23 import java.util.Set;
24 import org.turro.clone.ClonedEntity;
25 import org.turro.clone.ClonedEntitySet;
26 import org.turro.erp.entity.OrderReference;
27 import org.turro.erp.entity.OwnedAptitude;
28 import org.turro.erp.entity.WorkOrder;
29 import org.turro.hierarchy.Hierarchical;
30 
35 public class WorkOrderClone extends ClonedEntity<WorkOrder, Long> implements Hierarchical {
36 
37  private String description;
38  private OwnedAptitude supervised;
39  private Set<OrderReferenceClone> orderReferences = new HashSet<OrderReferenceClone>();
40 
41  public WorkOrderClone(WorkOrder workOrder, ClonedEntitySet entities) {
42  super(workOrder.getId(), workOrder, entities);
43  description = workOrder.getDescription();
44  supervised = workOrder.getSupervised();
45  for(OrderReference orderReference : workOrder.getOrderReferences()) {
46  if(orderReference.getId() > 0) {
47  OrderReferenceClone or = new OrderReferenceClone(orderReference, entities);
48  or.setWorkOrder(this);
49  orderReferences.add((OrderReferenceClone) entities.addClonedEntity(or));
50  }
51  }
52  }
53 
54  @Override
55  protected WorkOrder createClone() {
56  WorkOrder workOrder = new WorkOrder();
57  applyData(workOrder);
58  for(OrderReferenceClone orderReferenceClone : orderReferences) {
59  orderReferenceClone.generateClone();
60  OrderReference orderReference = orderReferenceClone.getClone();
61  orderReference.setWorkOrder(workOrder);
62  workOrder.getOrderReferences().add(orderReference);
63  }
64  return workOrder;
65  }
66 
67  @Override
68  protected void applyData(WorkOrder entity) {
69  entity.setDescription(description);
70  entity.setSupervised(supervised);
71  }
72 
73  @Override
74  protected void applyChildren(WorkOrder entity) {
75  for(OrderReferenceClone orderReferenceClone : orderReferences) {
76  orderReferenceClone.applyChanges();
77  }
78  }
79 
80  @Override
81  protected void assignEntities() {
82  for(OrderReferenceClone orderReferenceClone : orderReferences) {
83  orderReferenceClone.assignEntities();
84  }
85  }
86 
87  /* Hierarchical */
88 
89  @Override
90  public Collection children() {
91  return orderReferences;
92  }
93 
94  @Override
95  public Object parent() {
96  return null;
97  }
98 
99 }
void setWorkOrder(WorkOrderClone workOrder)
WorkOrderClone(WorkOrder workOrder, ClonedEntitySet entities)
void applyChildren(WorkOrder entity)
void applyData(WorkOrder entity)
void setWorkOrder(WorkOrder workOrder)
void setSupervised(OwnedAptitude supervised)
Definition: WorkOrder.java:160
void setDescription(String description)
Definition: WorkOrder.java:96
Set< OrderReference > getOrderReferences()
Definition: WorkOrder.java:124