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.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;
47 * A POJO for company departments
49 * @author Roland Haeder
51 @Entity (name = "company_departments")
52 @Table (name = "company_departments")
53 public class CompanyDepartment implements Department, Comparable<Department> {
58 private static final long serialVersionUID = 94_835_918_958_717_660L;
61 * Connection to company contact
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;
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 * Where this department is located
77 @JoinColumn (name = "department_headquarters_id")
78 @OneToOne (targetEntity = CompanyHeadQuartersData.class, cascade = CascadeType.ALL)
79 private HeadQuartersData departentHeadquarters;
85 @GeneratedValue (strategy = GenerationType.IDENTITY)
86 @Column (name = "department_id", length = 20, nullable = false, updatable = false)
87 private Long departmentId;
90 * Department lead employee
92 @JoinColumn (name = "department_lead_id", nullable = false)
93 @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
94 private Employee departmentLead;
99 @Basic (optional = false)
100 @Column (name = "department_name", length = 100, nullable = false)
101 private String departmentName;
104 * User owner instance
106 @JoinColumn (name = "department_user_id", nullable = false, updatable = false)
107 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.MERGE, optional = false)
108 private User departmentUserOwner;
111 * Timestamp when this entry has been created
113 @Basic (optional = false)
114 @Temporal (TemporalType.TIMESTAMP)
115 @Column (name = "department_entry_created", nullable = false, updatable = false)
116 private Calendar departmentCreated;
119 public HeadQuartersData getDepartentHeadquarters () {
120 return this.departentHeadquarters;
124 public void setDepartentHeadquarters (final HeadQuartersData departentHeadquarters) {
125 this.departentHeadquarters = departentHeadquarters;
129 public BranchOffice getDepartmentBranchOffice () {
130 return this.departmentBranchOffice;
134 public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
135 this.departmentBranchOffice = departmentBranchOffice;
139 public BusinessContact getDepartmentCompany () {
140 return this.departmentCompany;
144 public void setDepartmentCompany (final BusinessContact departmentCompany) {
145 this.departmentCompany = departmentCompany;
149 public Long getDepartmentId () {
150 return this.departmentId;
154 public void setDepartmentId (final Long departmentId) {
155 this.departmentId = departmentId;
159 public Employee getDepartmentLead () {
160 return this.departmentLead;
164 public void setDepartmentLead (final Employee departmentLead) {
165 this.departmentLead = departmentLead;
169 public String getDepartmentName () {
170 return this.departmentName;
174 public void setDepartmentName (final String departmentName) {
175 this.departmentName = departmentName;
179 public Calendar getDepartmentCreated () {
180 return this.departmentCreated;
184 public void setDepartmentCreated (final Calendar departmentCreated) {
185 this.departmentCreated = departmentCreated;
189 public User getDepartmentUserOwner () {
190 return this.departmentUserOwner;
194 public void setDepartmentUserOwner (final User departmentUserOwner) {
195 this.departmentUserOwner = departmentUserOwner;
199 public int compareTo (final Department department) {
200 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
204 public boolean equals (final Object object) {
205 if (object == null) {
207 } else if (getClass() != object.getClass()) {
211 final Department other = (Department) object;
213 if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
215 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
223 public int hashCode () {
225 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
226 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());