2 * Copyright (C) 2016 Roland Haeder
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 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;
46 * A POJO for company departments
48 * @author Roland Haeder<roland@mxchange.org>
50 @Entity (name = "company_departments")
51 @Table (name = "company_departments")
52 @SuppressWarnings ("PersistenceUnitPresent")
53 public class CompanyDepartment implements Department {
58 private static final long serialVersionUID = 94_835_918_958_717_660L;
61 * Where this department is located
63 @JoinColumn (name = "department_headquarters_id")
64 @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL)
65 private HeadQuartersData departentHeadquarters;
68 * Where this department is located
70 @JoinColumn (name = "department_branch_id")
71 @ManyToOne (targetEntity = CompanyBranchOffice.class, cascade = CascadeType.ALL)
72 private BranchOffice departmentBranchOffice;
75 * Connection to company contact
77 @JoinColumn (name = "department_company_id", nullable = false, updatable = false)
78 @ManyToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL, optional = false)
79 private BusinessContact departmentCompany;
82 * Timestamp when this entry has been created
84 @Basic (optional = false)
85 @Temporal (TemporalType.TIMESTAMP)
86 @Column (name = "department_entry_created", nullable = false, updatable = false)
87 private Calendar departmentCreated;
93 @GeneratedValue (strategy = GenerationType.IDENTITY)
94 @Column (name = "department_id", nullable = false, updatable = false)
95 private Long departmentId;
98 * Department lead employee
100 @JoinColumn (name = "department_lead_id", nullable = false)
101 @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
102 private Employee departmentLead;
107 @Basic (optional = false)
108 @Column (name = "department_name", length = 100, nullable = false)
109 private String departmentName;
112 * User owner instance
114 @JoinColumn (name = "department_user_id", nullable = false, updatable = false)
115 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
116 private User departmentUserOwner;
119 public boolean equals (final Object object) {
120 if (null == object) {
122 } else if (this.getClass() != object.getClass()) {
126 final Department other = (Department) object;
128 if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
130 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
138 public int hashCode () {
140 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
141 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());
146 public HeadQuartersData getDepartentHeadquarters () {
147 return this.departentHeadquarters;
151 public void setDepartentHeadquarters (final HeadQuartersData departentHeadquarters) {
152 this.departentHeadquarters = departentHeadquarters;
156 public BranchOffice getDepartmentBranchOffice () {
157 return this.departmentBranchOffice;
161 public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
162 this.departmentBranchOffice = departmentBranchOffice;
166 public BusinessContact getDepartmentCompany () {
167 return this.departmentCompany;
171 public void setDepartmentCompany (final BusinessContact departmentCompany) {
172 this.departmentCompany = departmentCompany;
176 @SuppressWarnings ("ReturnOfDateField")
177 public Calendar getDepartmentCreated () {
178 return this.departmentCreated;
182 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
183 public void setDepartmentCreated (final Calendar departmentCreated) {
184 this.departmentCreated = departmentCreated;
188 public Long getDepartmentId () {
189 return this.departmentId;
193 public void setDepartmentId (final Long departmentId) {
194 this.departmentId = departmentId;
198 public Employee getDepartmentLead () {
199 return this.departmentLead;
203 public void setDepartmentLead (final Employee departmentLead) {
204 this.departmentLead = departmentLead;
208 public String getDepartmentName () {
209 return this.departmentName;
213 public void setDepartmentName (final String departmentName) {
214 this.departmentName = departmentName;
218 public User getDepartmentUserOwner () {
219 return this.departmentUserOwner;
223 public void setDepartmentUserOwner (final User departmentUserOwner) {
224 this.departmentUserOwner = departmentUserOwner;