]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java
Having basic data and "business contact" which is really no contact in general
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / 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.department;
18
19 import java.util.Calendar;
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.OneToOne;
31 import javax.persistence.Table;
32 import javax.persistence.Temporal;
33 import javax.persistence.TemporalType;
34 import javax.persistence.Transient;
35 import org.mxchange.jcontactsbusiness.CompanyBasicData;
36 import org.mxchange.jcontactsbusiness.branch.BranchOffice;
37 import org.mxchange.jcontactsbusiness.branch.CompanyBranchOffice;
38 import org.mxchange.jcontactsbusiness.employee.CompanyEmployee;
39 import org.mxchange.jcontactsbusiness.employee.Employee;
40 import org.mxchange.jcontactsbusiness.headquarters.CompanyHeadQuartersData;
41 import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData;
42 import org.mxchange.jusercore.model.user.LoginUser;
43 import org.mxchange.jusercore.model.user.User;
44 import org.mxchange.jcontactsbusiness.BusinessBasicData;
45
46 /**
47  * A POJO for company departments
48  * <p>
49  * @author Roland Häder<roland@mxchange.org>
50  */
51 @Entity (name = "company_departments")
52 @Table (name = "company_departments")
53 @SuppressWarnings ("PersistenceUnitPresent")
54 public class CompanyDepartment implements Department {
55
56         /**
57          * Serial number
58          */
59         @Transient
60         private static final long serialVersionUID = 94_835_918_958_717_660L;
61
62         /**
63          * Where this department is located
64          */
65         @JoinColumn (name = "department_headquarters_id")
66         @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL)
67         private HeadQuartersData departentHeadquarters;
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_entry_created", nullable = false, updatable = false)
89         private Calendar departmentCreated;
90
91         /**
92          * Id number
93          */
94         @Id
95         @GeneratedValue (strategy = GenerationType.IDENTITY)
96         @Column (name = "department_id", nullable = false, updatable = false)
97         private Long departmentId;
98
99         /**
100          * Department lead employee
101          */
102         @JoinColumn (name = "department_lead_id", nullable = false)
103         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
104         private Employee departmentLead;
105
106         /**
107          * Department name
108          */
109         @Basic (optional = false)
110         @Column (name = "department_name", length = 100, nullable = false)
111         private String departmentName;
112
113         /**
114          * User owner instance
115          */
116         @JoinColumn (name = "department_user_id", nullable = false, updatable = false)
117         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
118         private User departmentUserOwner;
119
120         @Override
121         public boolean equals (final Object object) {
122                 if (null == object) {
123                         return false;
124                 } else if (this.getClass() != object.getClass()) {
125                         return false;
126                 }
127
128                 final Department other = (Department) object;
129
130                 if (!Objects.equals(this.getDepartmentId(), other.getDepartmentId())) {
131                         return false;
132                 } else if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
133                         return false;
134                 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
135                         return false;
136                 }
137
138                 return true;
139         }
140
141         @Override
142         public HeadQuartersData getDepartentHeadquarters () {
143                 return this.departentHeadquarters;
144         }
145
146         @Override
147         public void setDepartentHeadquarters (final HeadQuartersData departentHeadquarters) {
148                 this.departentHeadquarters = departentHeadquarters;
149         }
150
151         @Override
152         public BranchOffice getDepartmentBranchOffice () {
153                 return this.departmentBranchOffice;
154         }
155
156         @Override
157         public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
158                 this.departmentBranchOffice = departmentBranchOffice;
159         }
160
161         @Override
162         public BusinessBasicData getDepartmentCompany () {
163                 return this.departmentCompany;
164         }
165
166         @Override
167         public void setDepartmentCompany (final BusinessBasicData departmentCompany) {
168                 this.departmentCompany = departmentCompany;
169         }
170
171         @Override
172         @SuppressWarnings ("ReturnOfDateField")
173         public Calendar getDepartmentCreated () {
174                 return this.departmentCreated;
175         }
176
177         @Override
178         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
179         public void setDepartmentCreated (final Calendar departmentCreated) {
180                 this.departmentCreated = departmentCreated;
181         }
182
183         @Override
184         public Long getDepartmentId () {
185                 return this.departmentId;
186         }
187
188         @Override
189         public void setDepartmentId (final Long departmentId) {
190                 this.departmentId = departmentId;
191         }
192
193         @Override
194         public Employee getDepartmentLead () {
195                 return this.departmentLead;
196         }
197
198         @Override
199         public void setDepartmentLead (final Employee departmentLead) {
200                 this.departmentLead = departmentLead;
201         }
202
203         @Override
204         public String getDepartmentName () {
205                 return this.departmentName;
206         }
207
208         @Override
209         public void setDepartmentName (final String departmentName) {
210                 this.departmentName = departmentName;
211         }
212
213         @Override
214         public User getDepartmentUserOwner () {
215                 return this.departmentUserOwner;
216         }
217
218         @Override
219         public void setDepartmentUserOwner (final User departmentUserOwner) {
220                 this.departmentUserOwner = departmentUserOwner;
221         }
222
223         @Override
224         public int hashCode () {
225                 int hash = 5;
226
227                 hash = 53 * hash + Objects.hashCode(this.getDepartmentId());
228                 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
229                 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());
230
231                 return hash;
232         }
233
234 }