]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java
Continued a bit:
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / department / CompanyDepartment.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
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 org.mxchange.jcontactsbusiness.BusinessContact;
35 import org.mxchange.jcontactsbusiness.CompanyContact;
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
45 /**
46  * A POJO for company departments
47  * <p>
48  * @author Roland Haeder<roland@mxchange.org>
49  */
50 @Entity (name = "company_departments")
51 @Table (name = "company_departments")
52 public class CompanyDepartment implements Department {
53
54         /**
55          * Serial number
56          */
57         private static final long serialVersionUID = 94_835_918_958_717_660L;
58
59         /**
60          * Where this department is located
61          */
62         @JoinColumn (name = "department_headquarters_id")
63         @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL)
64         private HeadQuartersData departentHeadquarters;
65
66         /**
67          * Where this department is located
68          */
69         @JoinColumn (name = "department_branch_id")
70         @ManyToOne (targetEntity = CompanyBranchOffice.class, cascade = CascadeType.ALL)
71         private BranchOffice departmentBranchOffice;
72
73         /**
74          * Connection to company contact
75          */
76         @JoinColumn (name = "department_company_id", nullable = false, updatable = false)
77         @ManyToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL, optional = false)
78         private BusinessContact departmentCompany;
79
80         /**
81          * Timestamp when this entry has been created
82          */
83         @Basic (optional = false)
84         @Temporal (TemporalType.TIMESTAMP)
85         @Column (name = "department_entry_created", nullable = false, updatable = false)
86         private Calendar departmentCreated;
87
88         /**
89          * Id number
90          */
91         @Id
92         @GeneratedValue (strategy = GenerationType.IDENTITY)
93         @Column (name = "department_id", nullable = false, updatable = false)
94         private Long departmentId;
95
96         /**
97          * Department lead employee
98          */
99         @JoinColumn (name = "department_lead_id", nullable = false)
100         @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
101         private Employee departmentLead;
102
103         /**
104          * Department name
105          */
106         @Basic (optional = false)
107         @Column (name = "department_name", length = 100, nullable = false)
108         private String departmentName;
109
110         /**
111          * User owner instance
112          */
113         @JoinColumn (name = "department_user_id", nullable = false, updatable = false)
114         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
115         private User departmentUserOwner;
116
117         @Override
118         public boolean equals (final Object object) {
119                 if (null == object) {
120                         return false;
121                 } else if (this.getClass() != object.getClass()) {
122                         return false;
123                 }
124
125                 final Department other = (Department) object;
126
127                 if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
128                         return false;
129                 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
130                         return false;
131                 }
132
133                 return true;
134         }
135
136         @Override
137         public int hashCode () {
138                 int hash = 5;
139                 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
140                 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());
141                 return hash;
142         }
143
144         @Override
145         public HeadQuartersData getDepartentHeadquarters () {
146                 return this.departentHeadquarters;
147         }
148
149         @Override
150         public void setDepartentHeadquarters (final HeadQuartersData departentHeadquarters) {
151                 this.departentHeadquarters = departentHeadquarters;
152         }
153
154         @Override
155         public BranchOffice getDepartmentBranchOffice () {
156                 return this.departmentBranchOffice;
157         }
158
159         @Override
160         public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
161                 this.departmentBranchOffice = departmentBranchOffice;
162         }
163
164         @Override
165         public BusinessContact getDepartmentCompany () {
166                 return this.departmentCompany;
167         }
168
169         @Override
170         public void setDepartmentCompany (final BusinessContact departmentCompany) {
171                 this.departmentCompany = departmentCompany;
172         }
173
174         @Override
175         public Calendar getDepartmentCreated () {
176                 return this.departmentCreated;
177         }
178
179         @Override
180         public void setDepartmentCreated (final Calendar departmentCreated) {
181                 this.departmentCreated = departmentCreated;
182         }
183
184         @Override
185         public Long getDepartmentId () {
186                 return this.departmentId;
187         }
188
189         @Override
190         public void setDepartmentId (final Long departmentId) {
191                 this.departmentId = departmentId;
192         }
193
194         @Override
195         public Employee getDepartmentLead () {
196                 return this.departmentLead;
197         }
198
199         @Override
200         public void setDepartmentLead (final Employee departmentLead) {
201                 this.departmentLead = departmentLead;
202         }
203
204         @Override
205         public String getDepartmentName () {
206                 return this.departmentName;
207         }
208
209         @Override
210         public void setDepartmentName (final String departmentName) {
211                 this.departmentName = departmentName;
212         }
213
214         @Override
215         public User getDepartmentUserOwner () {
216                 return this.departmentUserOwner;
217         }
218
219         @Override
220         public void setDepartmentUserOwner (final User departmentUserOwner) {
221                 this.departmentUserOwner = departmentUserOwner;
222         }
223
224 }