BrightSide Workbench Full Report + Source Code
Headquarters.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.action.Contacts;
25 import org.turro.financials.model.business.IValuation;
26 import org.turro.jpa.entity.IDaoEntity;
27 import org.turro.plugin.contacts.IContact;
28 
33 @Entity
34 public class Headquarters implements java.io.Serializable, IDaoEntity, IValuation {
35 
36  @Id
37  @Column(name="IDENTIFIER")
38  @GeneratedValue(strategy=GenerationType.IDENTITY)
39  private long id;
40 
41  @Column(name="HEADQUARTERS_NAME")
42  private String name;
43 
44  private double structureMargin, profitMargin;
45 
46  private boolean alwaysApply;
47 
48  private String idContact;
49 
50  @ManyToOne
51  private Company company;
52 
53  @OneToMany(mappedBy = "headquarters", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=true)
54  @OrderBy(value="name ASC")
55  private Set<Department> departments = new HashSet<Department>();
56 
57  public Company getCompany() {
58  return company;
59  }
60 
61  public void setCompany(Company company) {
62  this.company = company;
63  }
64 
65  public Set<Department> getDepartments() {
66  return departments;
67  }
68 
69  public void setDepartments(Set<Department> departments) {
70  this.departments = departments;
71  }
72 
73  @Override
74  public double getStructureMargin() {
75  return structureMargin;
76  }
77 
78  public void setStructureMargin(double structureMargin) {
79  this.structureMargin = structureMargin;
80  }
81 
82  @Override
83  public long getId() {
84  return id;
85  }
86 
87  public void setId(long id) {
88  this.id = id;
89  }
90 
91  public String getIdContact() {
92  return idContact;
93  }
94 
95  public void setIdContact(String idContact) {
96  this.idContact = idContact;
97  resetIContact();
98  }
99 
100  @Override
101  public String getName() {
102  return name;
103  }
104 
105  public void setName(String name) {
106  this.name = name;
107  }
108 
109  @Override
110  public double getProfitMargin() {
111  return profitMargin;
112  }
113 
114  public void setProfitMargin(double profitMargin) {
115  this.profitMargin = profitMargin;
116  }
117 
118  @Override
119  public boolean isAlwaysApply() {
120  return alwaysApply;
121  }
122 
123  public void setAlwaysApply(boolean alwaysApply) {
124  this.alwaysApply = alwaysApply;
125  }
126 
127  /* IDaoEntity */
128 
129  @Override
130  public Object entityId() {
131  return id;
132  }
133 
134  @Override
135  public boolean isEmpty() {
136  return Strings.isBlank(name) || Strings.isBlank(idContact);
137  }
138 
141  private transient IContact _contact;
142 
144  if(_contact == null) {
145  _contact = Contacts.getContactById(idContact);
146  }
147  return _contact;
148  }
149 
150  public void setIContact(IContact contact) {
151  _contact = contact;
152  idContact = _contact != null ? _contact.getId() : null;
153  name = _contact != null ? _contact.getName() : null;
154  }
155 
156  private void resetIContact() {
157  _contact = null;
158  }
159 
160 }
static IContact getContactById(String id)
Definition: Contacts.java:72
void setStructureMargin(double structureMargin)
void setAlwaysApply(boolean alwaysApply)
void setDepartments(Set< Department > departments)
void setProfitMargin(double profitMargin)