]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/model/department/CompanyDepartment.java
Continued:
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / model / department / CompanyDepartment.java
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jcontactsbusiness.model.department;
18
19 import java.util.Date;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.ManyToOne;
30 import javax.persistence.NamedQueries;
31 import javax.persistence.NamedQuery;
32 import javax.persistence.OneToOne;
33 import javax.persistence.Table;
34 import javax.persistence.Temporal;
35 import javax.persistence.TemporalType;
36 import javax.persistence.Transient;
37 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
38 import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData;
39 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
40 import org.mxchange.jcontactsbusiness.model.branchoffice.CompanyBranchOffice;
41 import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployee;
42 import org.mxchange.jcontactsbusiness.model.employee.Employee;
43 import org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersData;
44 import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
45 import org.mxchange.jusercore.model.user.LoginUser;
46 import org.mxchange.jusercore.model.user.User;
47
48 /**
49  * A POJO for company departments
50  * <p>
51  * @author Roland Häder<roland@mxchange.org>
52  */
53 @Entity (name = "company_departments")
54 @Table (name = "company_departments")
55 @NamedQueries (
56                 {
57                         @NamedQuery (name = "AllDepartments", query = "SELECT d FROM company_departments AS d ORDER BY d.departmentId ASC")
58                 }
59 )
60 @SuppressWarnings ("PersistenceUnitPresent")
61 public class CompanyDepartment implements Department {
62
63         /**
64          * Serial number
65          */
66         @Transient
67         private static final long serialVersionUID = 94_835_918_958_717_660L;
68
69         /**
70          * Where this department is located
71          */
72         @JoinColumn (name = "department_branch_id")
73         @ManyToOne (targetEntity = CompanyBranchOffice.class, cascade = CascadeType.ALL)
74         private BranchOffice departmentBranchOffice;
75
76         /**
77          * Connection to company contact
78          */
79         @JoinColumn (name = "department_company_id", nullable = false, updatable = false)
80         @ManyToOne (targetEntity = CompanyBasicData.class, cascade = CascadeType.ALL, optional = false)
81         private BusinessBasicData departmentCompany;
82
83         /**
84          * Timestamp when this entry has been created
85          */
86         @Basic (optional = false)
87         @Temporal (TemporalType.TIMESTAMP)
88         @Column (name = "department_created", nullable = false, updatable = false)
89         private Date departmentCreated;
90
91         /**
92          * Where this department is located
93          */
94         @JoinColumn (name = "department_headquarters_id")
95         @OneToOne (targetEntity = CompanyHeadquartersData.class, cascade = CascadeType.ALL)
96         private HeadquartersData departmentHeadquarters;
97
98         /**
99          * Id number
100          */
101         @Id
102         @GeneratedValue (strategy = GenerationType.IDENTITY)
103         @Column (name = "department_id", nullable = false, updatable = false)
104         private Long departmentId;
105
106         /**
107          * Department lead employee
108          */
109         @JoinColumn (name = "department_lead_id")
110         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
111         private Employee departmentLead;
112
113         /**
114          * Department name
115          */
116         @Basic (optional = false)
117         @Column (name = "department_name", length = 100, nullable = false)
118         private String departmentName;
119
120         /**
121          * User owner instance
122          */
123         @JoinColumn (name = "department_user_id")
124         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
125         private User departmentUserOwner;
126
127         /**
128          * Default constructor
129          */
130         public CompanyDepartment () {
131         }
132
133         /**
134          * Constructor with all required fields
135          * <p>
136          * @param departmentCompany Basic data instance
137          * @param departmentName    Department name
138          */
139         public CompanyDepartment (final BusinessBasicData departmentCompany, final String departmentName) {
140                 // Call other constructor
141                 this();
142
143                 // Validate parameter
144                 if (null == departmentCompany) {
145                         // Throw NPE
146                         throw new NullPointerException("departmentCompany is null"); //NOI18N
147                 } else if (null == departmentName) {
148                         // Throw it again
149                         throw new NullPointerException("departmentName is null"); //NOI18N
150                 } else if (departmentName.isEmpty()) {
151                         // Throw IAE
152                         throw new IllegalArgumentException("departmentName is empty"); //NOI18N
153                 }
154
155                 // Set all fields
156                 this.departmentCompany = departmentCompany;
157                 this.departmentName = departmentName;
158         }
159
160         @Override
161         public boolean equals (final Object object) {
162                 if (null == object) {
163                         return false;
164                 } else if (this.getClass() != object.getClass()) {
165                         return false;
166                 }
167
168                 final Department other = (Department) object;
169
170                 if (!Objects.equals(this.getDepartmentId(), other.getDepartmentId())) {
171                         return false;
172                 } else if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
173                         return false;
174                 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
175                         return false;
176                 }
177
178                 return true;
179         }
180
181         @Override
182         public BranchOffice getDepartmentBranchOffice () {
183                 return this.departmentBranchOffice;
184         }
185
186         @Override
187         public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
188                 this.departmentBranchOffice = departmentBranchOffice;
189         }
190
191         @Override
192         public BusinessBasicData getDepartmentCompany () {
193                 return this.departmentCompany;
194         }
195
196         @Override
197         public void setDepartmentCompany (final BusinessBasicData departmentCompany) {
198                 this.departmentCompany = departmentCompany;
199         }
200
201         @Override
202         @SuppressWarnings ("ReturnOfDateField")
203         public Date getDepartmentCreated () {
204                 return this.departmentCreated;
205         }
206
207         @Override
208         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
209         public void setDepartmentCreated (final Date departmentCreated) {
210                 this.departmentCreated = departmentCreated;
211         }
212
213         @Override
214         public HeadquartersData getDepartmentHeadquarters () {
215                 return this.departmentHeadquarters;
216         }
217
218         @Override
219         public void setDepartmentHeadquarters (final HeadquartersData departmentHeadquarters) {
220                 this.departmentHeadquarters = departmentHeadquarters;
221         }
222
223         @Override
224         public Long getDepartmentId () {
225                 return this.departmentId;
226         }
227
228         @Override
229         public void setDepartmentId (final Long departmentId) {
230                 this.departmentId = departmentId;
231         }
232
233         @Override
234         public Employee getDepartmentLead () {
235                 return this.departmentLead;
236         }
237
238         @Override
239         public void setDepartmentLead (final Employee departmentLead) {
240                 this.departmentLead = departmentLead;
241         }
242
243         @Override
244         public String getDepartmentName () {
245                 return this.departmentName;
246         }
247
248         @Override
249         public void setDepartmentName (final String departmentName) {
250                 this.departmentName = departmentName;
251         }
252
253         @Override
254         public User getDepartmentUserOwner () {
255                 return this.departmentUserOwner;
256         }
257
258         @Override
259         public void setDepartmentUserOwner (final User departmentUserOwner) {
260                 this.departmentUserOwner = departmentUserOwner;
261         }
262
263         @Override
264         public int hashCode () {
265                 int hash = 5;
266
267                 hash = 53 * hash + Objects.hashCode(this.getDepartmentId());
268                 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
269                 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());
270
271                 return hash;
272         }
273
274 }