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