BrightSide Workbench Full Report + Source Code
FixedAsset.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.financials.entity;
19 
20 import java.util.HashSet;
21 import java.util.Set;
22 import javax.persistence.*;
23 import org.turro.string.Strings;
24 import org.turro.elephant.db.IdUtils;
25 import org.turro.financials.db.FinancialsPU;
26 import org.turro.jpa.entity.IDaoEntity;
27 import org.turro.reflection.MappingSet;
28 
33 @Entity
34 public class FixedAsset implements java.io.Serializable, IDaoEntity {
35 
36  @Id
37  @GeneratedValue(strategy=GenerationType.IDENTITY)
38  @Column(name="IDENTIFIER")
39  private long id;
40 
41  @Column(name="ASSET_NAME")
42  private String name;
43 
44  private double depreciated;
45  private double investment;
46 
47  private boolean unsubscribed;
48 
49  @OneToMany(mappedBy="fixedAsset",fetch=FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=true)
50  @OrderBy("depreciationDate")
51  private Set<FixedAssetDepreciation> depreciations = new HashSet<FixedAssetDepreciation>();
52 
53  @OneToMany(fetch=FetchType.EAGER)
54  private Set<DocumentLine> documentLines = new HashSet<DocumentLine>();
55 
56  @OneToOne
57  private ContractPreference investmentPreference;
58 
59  @OneToOne
60  private LineType depreciationLineType;
61 
62  @OneToOne
63  private RegisterView view;
64 
65  @OneToOne
66  private Contract store;
67 
68  @Lob
69  @Column(length=4096)
70  private String notes;
71 
72  public double getDepreciated() {
73  return depreciated;
74  }
75 
76  public void setDepreciated(double depreciated) {
77  this.depreciated = depreciated;
78  }
79 
81  return depreciationLineType;
82  }
83 
84  public void setDepreciationLineType(LineType depreciationLineType) {
85  this.depreciationLineType = depreciationLineType;
86  }
87 
88  public Set<FixedAssetDepreciation> getDepreciations() {
89  return depreciations;
90  }
91 
92  public void setDepreciations(Set<FixedAssetDepreciation> depreciations) {
93  this.depreciations = depreciations;
94  }
95 
96  public Set<DocumentLine> getDocumentLines() {
97  return documentLines;
98  }
99 
100  public void setDocumentLines(Set<DocumentLine> documentLines) {
101  this.documentLines = documentLines;
102  }
103 
104  public long getId() {
105  return id;
106  }
107 
108  public void setId(long id) {
109  this.id = id;
110  }
111 
112  public double getInvestment() {
113  return investment;
114  }
115 
116  public void setInvestment(double investment) {
117  this.investment = investment;
118  }
119 
121  return investmentPreference;
122  }
123 
124  public void setInvestmentPreference(ContractPreference investmentPreference) {
125  this.investmentPreference = investmentPreference;
126  }
127 
128  public String getName() {
129  return name;
130  }
131 
132  public void setName(String name) {
133  this.name = name;
134  }
135 
136  public String getNotes() {
137  return notes;
138  }
139 
140  public void setNotes(String notes) {
141  this.notes = notes;
142  }
143 
144  public Contract getStore() {
145  return store;
146  }
147 
148  public void setStore(Contract store) {
149  this.store = store;
150  }
151 
152  public boolean isUnsubscribed() {
153  return unsubscribed;
154  }
155 
156  public void setUnsubscribed(boolean unsubscribed) {
157  this.unsubscribed = unsubscribed;
158  }
159 
161  return view;
162  }
163 
164  public void setView(RegisterView view) {
165  this.view = view;
166  }
167 
168  /* IDaoEntity */
169 
170  @Override
171  public Object entityId() {
172  return id;
173  }
174 
175  @Override
176  public boolean isEmpty() {
177  return Strings.isBlank(name) || view == null || store == null ||
178  investmentPreference == null || depreciationLineType == null;
179  }
180 
183  public void prepareForSaving() {
184  if(id == 0) {
185  id = IdUtils.getNewLongIdFromLong(new FinancialsPU(), "FixedAsset", "id");
186  }
187  }
188 
189  /* XML Serializer */
190 
191  public MappingSet getSerializerMappings() {
192  MappingSet set = new MappingSet();
193  set.addMapping(FixedAsset.class, 1,
194  new String[] { "name", "depreciated", "investment" },
195  new String[] { "depreciations", "investmentPreference",
196  "depreciationLineType", "view", "store", "notes" });
197  set.addMapping(RegisterView.class, 2,
198  new String[] { "id", "name" },
199  null);
200  set.addMapping(ContractPreference.class, 2,
201  new String[] { "id", "name" },
202  null);
203  set.addMapping(Contract.class, 2,
204  new String[] { "id", "name" },
205  null);
206  set.addMapping(FixedAssetDepreciation.class, 2,
207  new String[] { "depreciationDate", "percent", "comment" },
208  new String[] {});
209  set.addMapping(LineType.class, 2,
210  new String[] { "name" },
211  null);
212  return set;
213  }
214 
215 }
static long getNewLongIdFromLong(Dao dao, String table, String field)
Definition: IdUtils.java:33
void setInvestmentPreference(ContractPreference investmentPreference)
void setDepreciated(double depreciated)
Definition: FixedAsset.java:76
void setDocumentLines(Set< DocumentLine > documentLines)
void setDepreciations(Set< FixedAssetDepreciation > depreciations)
Definition: FixedAsset.java:92
Set< FixedAssetDepreciation > getDepreciations()
Definition: FixedAsset.java:88
Set< DocumentLine > getDocumentLines()
Definition: FixedAsset.java:96
ContractPreference getInvestmentPreference()
void setDepreciationLineType(LineType depreciationLineType)
Definition: FixedAsset.java:84
void setInvestment(double investment)
void setUnsubscribed(boolean unsubscribed)