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.branch.BranchOffice;
36 import org.mxchange.jcontactsbusiness.employee.Employee;
37 import org.mxchange.jcontactsbusiness.headquarters.HeadQuartersData;
38 import org.mxchange.jusercore.model.user.User;
41 * A POJO for company departments
43 * @author Roland Haeder<roland@mxchange.org>
45 @Entity (name = "company_departments")
46 @Table (name = "company_departments")
47 @SuppressWarnings ("PersistenceUnitPresent")
48 public class CompanyDepartment implements Department {
53 private static final long serialVersionUID = 94_835_918_958_717_660L;
56 * Where this department is located
58 @JoinColumn (name = "department_headquarters_id")
59 @OneToOne (targetEntity = HeadQuartersData.class, cascade = CascadeType.ALL)
60 private HeadQuartersData departentHeadquarters;
63 * Where this department is located
65 @JoinColumn (name = "department_branch_id")
66 @ManyToOne (targetEntity = BranchOffice.class, cascade = CascadeType.ALL)
67 private BranchOffice departmentBranchOffice;
70 * Connection to company contact
72 @JoinColumn (name = "department_company_id", nullable = false, updatable = false)
73 @ManyToOne (targetEntity = BusinessContact.class, cascade = CascadeType.ALL, optional = false)
74 private BusinessContact departmentCompany;
77 * Timestamp when this entry has been created
79 @Basic (optional = false)
80 @Temporal (TemporalType.TIMESTAMP)
81 @Column (name = "department_entry_created", nullable = false, updatable = false)
82 private Calendar departmentCreated;
88 @GeneratedValue (strategy = GenerationType.IDENTITY)
89 @Column (name = "department_id", nullable = false, updatable = false)
90 private Long departmentId;
93 * Department lead employee
95 @JoinColumn (name = "department_lead_id", nullable = false)
96 @OneToOne (targetEntity = Employee.class, cascade = CascadeType.ALL)
97 private Employee departmentLead;
102 @Basic (optional = false)
103 @Column (name = "department_name", length = 100, nullable = false)
104 private String departmentName;
107 * User owner instance
109 @JoinColumn (name = "department_user_id", nullable = false, updatable = false)
110 @OneToOne (targetEntity = User.class, cascade = CascadeType.REFRESH, optional = false)
111 private User departmentUserOwner;
114 public boolean equals (final Object object) {
115 if (null == object) {
117 } else if (this.getClass() != object.getClass()) {
121 final Department other = (Department) object;
123 if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
125 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
133 public int hashCode () {
135 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
136 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());
141 public HeadQuartersData getDepartentHeadquarters () {
142 return this.departentHeadquarters;
146 public void setDepartentHeadquarters (final HeadQuartersData departentHeadquarters) {
147 this.departentHeadquarters = departentHeadquarters;
151 public BranchOffice getDepartmentBranchOffice () {
152 return this.departmentBranchOffice;
156 public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
157 this.departmentBranchOffice = departmentBranchOffice;
161 public BusinessContact getDepartmentCompany () {
162 return this.departmentCompany;
166 public void setDepartmentCompany (final BusinessContact departmentCompany) {
167 this.departmentCompany = departmentCompany;
171 @SuppressWarnings ("ReturnOfDateField")
172 public Calendar getDepartmentCreated () {
173 return this.departmentCreated;
177 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
178 public void setDepartmentCreated (final Calendar departmentCreated) {
179 this.departmentCreated = departmentCreated;
183 public Long getDepartmentId () {
184 return this.departmentId;
188 public void setDepartmentId (final Long departmentId) {
189 this.departmentId = departmentId;
193 public Employee getDepartmentLead () {
194 return this.departmentLead;
198 public void setDepartmentLead (final Employee departmentLead) {
199 this.departmentLead = departmentLead;
203 public String getDepartmentName () {
204 return this.departmentName;
208 public void setDepartmentName (final String departmentName) {
209 this.departmentName = departmentName;
213 public User getDepartmentUserOwner () {
214 return this.departmentUserOwner;
218 public void setDepartmentUserOwner (final User departmentUserOwner) {
219 this.departmentUserOwner = departmentUserOwner;