BrightSide Workbench Full Report + Source Code
ContractFlow.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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.financials.entity;
20 
21 import java.util.HashSet;
22 import java.util.Set;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.FetchType;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.ManyToOne;
31 import javax.persistence.OneToMany;
32 import org.turro.string.Strings;
33 import org.turro.jpa.entity.EntityCollections;
34 import org.turro.jpa.entity.IDaoEntity;
35 
40 @Entity
41 public class ContractFlow implements java.io.Serializable, IDaoEntity {
42 
43  @Id
44  @GeneratedValue(strategy=GenerationType.IDENTITY)
45  @Column(name="IDENTIFIER")
46  private long id;
47 
48  @ManyToOne
49  private Contract contract;
50 
51  private String description;
52 
53  @ManyToOne
54  private DocumentDefinition documentDefinition;
55 
56  @OneToMany(mappedBy = "contractFlow", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=true)
57  private Set<ContractExpiry> contractExpiries = new HashSet<ContractExpiry>();
58 
59  public long getId() {
60  return id;
61  }
62 
63  public void setId(long id) {
64  this.id = id;
65  }
66 
67  public Contract getContract() {
68  return contract;
69  }
70 
71  public void setContract(Contract contract) {
72  this.contract = contract;
73  }
74 
76  return documentDefinition;
77  }
78 
79  public void setDocumentDefinition(DocumentDefinition documentDefinition) {
80  this.documentDefinition = documentDefinition;
81  }
82 
83  public Set<ContractExpiry> getContractExpiries() {
84  return contractExpiries;
85  }
86 
87  public void setContractExpiries(Set<ContractExpiry> contractExpiries) {
88  this.contractExpiries = contractExpiries;
89  }
90 
91  public String getDescription() {
92  return description;
93  }
94 
95  public void setDescription(String description) {
96  this.description = description;
97  }
98 
99  /* IDaoEntity */
100 
101  @Override
102  public Object entityId() {
103  return id;
104  }
105 
106  @Override
107  public boolean isEmpty() {
108  return Strings.isBlank(description) || contractExpiries.isEmpty();
109  }
110 
111  /* Helpers */
112 
113  public void clearEmpties() {
115  }
116 
117  public void generateFlows(Document document) {
118  double amount = document.getTotalAmount();
119  int count = 1;
120  for(ContractExpiry ce : contractExpiries) {
121  amount = ce.generateFlow(document, amount, count++);
122  }
123  }
124 
125 }
Set< ContractExpiry > getContractExpiries()
void setDocumentDefinition(DocumentDefinition documentDefinition)
void setDescription(String description)
void setContractExpiries(Set< ContractExpiry > contractExpiries)
static EntityCollections entities(Collection values)