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, Comparable<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 int compareTo (final Department department) {
119 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
123 public boolean equals (final Object object) {
124 if (object == null) {
126 } else if (this.getClass() != object.getClass()) {
130 final Department other = (Department) object;
132 if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
134 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
142 public int hashCode () {
144 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
145 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());
150 public HeadQuartersData getDepartentHeadquarters () {
151 return this.departentHeadquarters;
155 public void setDepartentHeadquarters (final HeadQuartersData departentHeadquarters) {
156 this.departentHeadquarters = departentHeadquarters;
160 public BranchOffice getDepartmentBranchOffice () {
161 return this.departmentBranchOffice;
165 public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
166 this.departmentBranchOffice = departmentBranchOffice;
170 public BusinessContact getDepartmentCompany () {
171 return this.departmentCompany;
175 public void setDepartmentCompany (final BusinessContact departmentCompany) {
176 this.departmentCompany = departmentCompany;
180 public Calendar getDepartmentCreated () {
181 return this.departmentCreated;
185 public void setDepartmentCreated (final Calendar departmentCreated) {
186 this.departmentCreated = departmentCreated;
190 public Long getDepartmentId () {
191 return this.departmentId;
195 public void setDepartmentId (final Long departmentId) {
196 this.departmentId = departmentId;
200 public Employee getDepartmentLead () {
201 return this.departmentLead;
205 public void setDepartmentLead (final Employee departmentLead) {
206 this.departmentLead = departmentLead;
210 public String getDepartmentName () {
211 return this.departmentName;
215 public void setDepartmentName (final String departmentName) {
216 this.departmentName = departmentName;
220 public User getDepartmentUserOwner () {
221 return this.departmentUserOwner;
225 public void setDepartmentUserOwner (final User departmentUserOwner) {
226 this.departmentUserOwner = departmentUserOwner;