BrightSide Workbench Full Report + Source Code
Company.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.Date;
21 import java.util.HashSet;
22 import java.util.Set;
23 import javax.persistence.*;
24 import org.turro.string.Strings;
25 import org.turro.action.Contacts;
26 import org.turro.financials.model.business.IValuation;
27 import org.turro.jpa.entity.IDaoEntity;
28 import org.turro.plugin.contacts.IContact;
29 import org.turro.reflection.MappingSet;
30 
35 @Entity
36 public class Company implements java.io.Serializable, IDaoEntity, IValuation {
37 
38  @Id
39  @GeneratedValue(strategy=GenerationType.IDENTITY)
40  @Column(name="IDENTIFIER")
41  private long id;
42 
43  @Column(name="COMPANY_NAME")
44  private String name;
45 
46  private double structureMargin, profitMargin;
47 
48  private boolean alwaysApply;
49 
50  private String idContact;
51 
52  @Temporal(value = TemporalType.DATE)
53  private Date closingDate;
54 
55  @OneToMany(mappedBy = "company", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=true)
56  @OrderBy(value="name ASC")
57  private Set<Service> services = new HashSet<Service>();
58 
59  @OneToMany(mappedBy = "company", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=true)
60  @OrderBy(value="name ASC")
61  private Set<Headquarters> headquarters = new HashSet<Headquarters>();
62 
63  public Date getClosingDate() {
64  return closingDate;
65  }
66 
67  public void setClosingDate(Date closingDate) {
68  this.closingDate = closingDate;
69  }
70 
71  @Override
72  public double getStructureMargin() {
73  return structureMargin;
74  }
75 
76  public void setStructureMargin(double structureMargin) {
77  this.structureMargin = structureMargin;
78  }
79 
80  public Set<Headquarters> getHeadquarters() {
81  return headquarters;
82  }
83 
84  public void setHeadquarters(Set<Headquarters> headquarters) {
85  this.headquarters = headquarters;
86  }
87 
88  @Override
89  public long getId() {
90  return id;
91  }
92 
93  public void setId(long id) {
94  this.id = id;
95  }
96 
97  public String getIdContact() {
98  return idContact;
99  }
100 
101  public void setIdContact(String idContact) {
102  this.idContact = idContact;
103  resetIContact();
104  }
105 
106  @Override
107  public String getName() {
108  return name;
109  }
110 
111  public void setName(String name) {
112  this.name = name;
113  }
114 
115  @Override
116  public double getProfitMargin() {
117  return profitMargin;
118  }
119 
120  public void setProfitMargin(double profitMargin) {
121  this.profitMargin = profitMargin;
122  }
123 
124  public Set<Service> getServices() {
125  return services;
126  }
127 
128  public void setServices(Set<Service> services) {
129  this.services = services;
130  }
131 
132  @Override
133  public boolean isAlwaysApply() {
134  return alwaysApply;
135  }
136 
137  public void setAlwaysApply(boolean alwaysApply) {
138  this.alwaysApply = alwaysApply;
139  }
140 
143  @Override
144  public Object entityId() {
145  return id;
146  }
147 
148  @Override
149  public boolean isEmpty() {
150  return Strings.isBlank(name);
151  }
152 
155  private transient IContact _contact;
156 
158  if(_contact == null) {
159  _contact = Contacts.getContactById(idContact);
160  }
161  return _contact;
162  }
163 
164  public void setIContact(IContact contact) {
165  _contact = contact;
166  idContact = _contact != null ? _contact.getId() : null;
167  name = _contact != null ? _contact.getName() : null;
168  }
169 
170  private void resetIContact() {
171  _contact = null;
172  }
173 
174  /* XML Serializer */
175 
176  public MappingSet getSerializerMappings() {
177  MappingSet set = new MappingSet();
178  set.addMapping(Contract.class, 1,
179  new String[] { "id", "name" },
180  null);
181  return set;
182  }
183 
184 }
static IContact getContactById(String id)
Definition: Contacts.java:72
void setStructureMargin(double structureMargin)
Definition: Company.java:76
void setProfitMargin(double profitMargin)
Definition: Company.java:120
void setServices(Set< Service > services)
Definition: Company.java:128
void setAlwaysApply(boolean alwaysApply)
Definition: Company.java:137
void setIdContact(String idContact)
Definition: Company.java:101
Set< Headquarters > getHeadquarters()
Definition: Company.java:80
void setIContact(IContact contact)
Definition: Company.java:164
void setHeadquarters(Set< Headquarters > headquarters)
Definition: Company.java:84
void setClosingDate(Date closingDate)
Definition: Company.java:67