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 public class CompanyDepartment implements Department {
57 private static final long serialVersionUID = 94_835_918_958_717_660L;
60 * Where this department is located
62 @JoinColumn (name = "department_headquarters_id")
63 @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL)
64 private HeadQuartersData departentHeadquarters;
67 * Where this department is located
69 @JoinColumn (name = "department_branch_id")
70 @ManyToOne (targetEntity = CompanyBranchOffice.class, cascade = CascadeType.ALL)
71 private BranchOffice departmentBranchOffice;
74 * Connection to company contact
76 @JoinColumn (name = "department_company_id", nullable = false, updatable = false)
77 @ManyToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL, optional = false)
78 private BusinessContact departmentCompany;
81 * Timestamp when this entry has been created
83 @Basic (optional = false)
84 @Temporal (TemporalType.TIMESTAMP)
85 @Column (name = "department_entry_created", nullable = false, updatable = false)
86 private Calendar departmentCreated;
92 @GeneratedValue (strategy = GenerationType.IDENTITY)
93 @Column (name = "department_id", length = 20, nullable = false, updatable = false)
94 private Long departmentId;
97 * Department lead employee
99 @JoinColumn (name = "department_lead_id", nullable = false)
100 @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
101 private Employee departmentLead;
106 @Basic (optional = false)
107 @Column (name = "department_name", length = 100, nullable = false)
108 private String departmentName;
111 * User owner instance
113 @JoinColumn (name = "department_user_id", nullable = false, updatable = false)
114 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
115 private User departmentUserOwner;
118 public boolean equals (final Object object) {
119 if (null == object) {
121 } else if (this.getClass() != object.getClass()) {
125 final Department other = (Department) object;
127 if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
129 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
137 public int hashCode () {
139 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
140 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());
145 public HeadQuartersData getDepartentHeadquarters () {
146 return this.departentHeadquarters;
150 public void setDepartentHeadquarters (final HeadQuartersData departentHeadquarters) {
151 this.departentHeadquarters = departentHeadquarters;
155 public BranchOffice getDepartmentBranchOffice () {
156 return this.departmentBranchOffice;
160 public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
161 this.departmentBranchOffice = departmentBranchOffice;
165 public BusinessContact getDepartmentCompany () {
166 return this.departmentCompany;
170 public void setDepartmentCompany (final BusinessContact departmentCompany) {
171 this.departmentCompany = departmentCompany;
175 public Calendar getDepartmentCreated () {
176 return this.departmentCreated;
180 public void setDepartmentCreated (final Calendar departmentCreated) {
181 this.departmentCreated = departmentCreated;
185 public Long getDepartmentId () {
186 return this.departmentId;
190 public void setDepartmentId (final Long departmentId) {
191 this.departmentId = departmentId;
195 public Employee getDepartmentLead () {
196 return this.departmentLead;
200 public void setDepartmentLead (final Employee departmentLead) {
201 this.departmentLead = departmentLead;
205 public String getDepartmentName () {
206 return this.departmentName;
210 public void setDepartmentName (final String departmentName) {
211 this.departmentName = departmentName;
215 public User getDepartmentUserOwner () {
216 return this.departmentUserOwner;
220 public void setDepartmentUserOwner (final User departmentUserOwner) {
221 this.departmentUserOwner = departmentUserOwner;