2 * Copyright (C) 2016, 2017 Roland Häder
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.
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.
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/>.
17 package org.mxchange.jcontactsbusiness.department;
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.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;
47 * A POJO for company departments
49 * @author Roland Häder<roland@mxchange.org>
51 @Entity (name = "company_departments")
52 @Table (name = "company_departments")
53 @SuppressWarnings ("PersistenceUnitPresent")
54 public class CompanyDepartment implements Department {
60 private static final long serialVersionUID = 94_835_918_958_717_660L;
63 * Where this department is located
65 @JoinColumn (name = "department_headquarters_id")
66 @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL)
67 private HeadQuartersData departentHeadquarters;
70 * Where this department is located
72 @JoinColumn (name = "department_branch_id")
73 @ManyToOne (targetEntity = CompanyBranchOffice.class, cascade = CascadeType.ALL)
74 private BranchOffice departmentBranchOffice;
77 * Connection to company contact
79 @JoinColumn (name = "department_company_id", nullable = false, updatable = false)
80 @ManyToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL, optional = false)
81 private BusinessContact departmentCompany;
84 * Timestamp when this entry has been created
86 @Basic (optional = false)
87 @Temporal (TemporalType.TIMESTAMP)
88 @Column (name = "department_entry_created", nullable = false, updatable = false)
89 private Calendar departmentCreated;
95 @GeneratedValue (strategy = GenerationType.IDENTITY)
96 @Column (name = "department_id", nullable = false, updatable = false)
97 private Long departmentId;
100 * Department lead employee
102 @JoinColumn (name = "department_lead_id", nullable = false)
103 @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
104 private Employee departmentLead;
109 @Basic (optional = false)
110 @Column (name = "department_name", length = 100, nullable = false)
111 private String departmentName;
114 * User owner instance
116 @JoinColumn (name = "department_user_id", nullable = false, updatable = false)
117 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
118 private User departmentUserOwner;
121 public boolean equals (final Object object) {
122 if (null == object) {
124 } else if (this.getClass() != object.getClass()) {
128 final Department other = (Department) object;
130 if (!Objects.equals(this.getDepartmentId(), other.getDepartmentId())) {
132 } else if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
134 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
142 public HeadQuartersData getDepartentHeadquarters () {
143 return this.departentHeadquarters;
147 public void setDepartentHeadquarters (final HeadQuartersData departentHeadquarters) {
148 this.departentHeadquarters = departentHeadquarters;
152 public BranchOffice getDepartmentBranchOffice () {
153 return this.departmentBranchOffice;
157 public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
158 this.departmentBranchOffice = departmentBranchOffice;
162 public BusinessContact getDepartmentCompany () {
163 return this.departmentCompany;
167 public void setDepartmentCompany (final BusinessContact departmentCompany) {
168 this.departmentCompany = departmentCompany;
172 @SuppressWarnings ("ReturnOfDateField")
173 public Calendar getDepartmentCreated () {
174 return this.departmentCreated;
178 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
179 public void setDepartmentCreated (final Calendar departmentCreated) {
180 this.departmentCreated = departmentCreated;
184 public Long getDepartmentId () {
185 return this.departmentId;
189 public void setDepartmentId (final Long departmentId) {
190 this.departmentId = departmentId;
194 public Employee getDepartmentLead () {
195 return this.departmentLead;
199 public void setDepartmentLead (final Employee departmentLead) {
200 this.departmentLead = departmentLead;
204 public String getDepartmentName () {
205 return this.departmentName;
209 public void setDepartmentName (final String departmentName) {
210 this.departmentName = departmentName;
214 public User getDepartmentUserOwner () {
215 return this.departmentUserOwner;
219 public void setDepartmentUserOwner (final User departmentUserOwner) {
220 this.departmentUserOwner = departmentUserOwner;
224 public int hashCode () {
227 hash = 53 * hash + Objects.hashCode(this.getDepartmentId());
228 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
229 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());