2 * Copyright (C) 2016, 2017 Roland Häder
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.model.department;
19 import java.util.Date;
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.NamedQueries;
31 import javax.persistence.NamedQuery;
32 import javax.persistence.OneToOne;
33 import javax.persistence.Table;
34 import javax.persistence.Temporal;
35 import javax.persistence.TemporalType;
36 import javax.persistence.Transient;
37 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
38 import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData;
39 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
40 import org.mxchange.jcontactsbusiness.model.branchoffice.CompanyBranchOffice;
41 import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployee;
42 import org.mxchange.jcontactsbusiness.model.employee.Employee;
43 import org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersData;
44 import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
45 import org.mxchange.jusercore.model.user.LoginUser;
46 import org.mxchange.jusercore.model.user.User;
49 * A POJO for company departments
51 * @author Roland Häder<roland@mxchange.org>
53 @Entity (name = "company_departments")
54 @Table (name = "company_departments")
57 @NamedQuery (name = "AllDepartments", query = "SELECT d FROM company_departments AS d ORDER BY d.departmentId ASC")
60 @SuppressWarnings ("PersistenceUnitPresent")
61 public class CompanyDepartment implements Department {
67 private static final long serialVersionUID = 94_835_918_958_717_660L;
70 * Where this department is located
72 @JoinColumn (name = "department_branch_id")
73 @ManyToOne (targetEntity = CompanyBranchOffice.class, cascade = CascadeType.ALL)
74 private BranchOffice departmentBranchOffice;
77 * Connection to company contact
79 @JoinColumn (name = "department_company_id", nullable = false, updatable = false)
80 @ManyToOne (targetEntity = CompanyBasicData.class, cascade = CascadeType.ALL, optional = false)
81 private BusinessBasicData departmentCompany;
84 * Timestamp when this entry has been created
86 @Basic (optional = false)
87 @Temporal (TemporalType.TIMESTAMP)
88 @Column (name = "department_created", nullable = false, updatable = false)
89 private Date departmentCreated;
92 * Where this department is located
94 @JoinColumn (name = "department_headquarters_id")
95 @OneToOne (targetEntity = CompanyHeadquartersData.class, cascade = CascadeType.ALL)
96 private HeadquartersData departmentHeadquarters;
102 @GeneratedValue (strategy = GenerationType.IDENTITY)
103 @Column (name = "department_id", nullable = false, updatable = false)
104 private Long departmentId;
107 * Department lead employee
109 @JoinColumn (name = "department_lead_id")
110 @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
111 private Employee departmentLead;
116 @Basic (optional = false)
117 @Column (name = "department_name", length = 100, nullable = false)
118 private String departmentName;
121 * User owner instance
123 @JoinColumn (name = "department_user_id")
124 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
125 private User departmentUserOwner;
128 * Default constructor
130 public CompanyDepartment () {
134 * Constructor with all required fields
136 * @param departmentCompany Basic data instance
137 * @param departmentName Department name
139 public CompanyDepartment (final BusinessBasicData departmentCompany, final String departmentName) {
140 // Call other constructor
143 // Validate parameter
144 if (null == departmentCompany) {
146 throw new NullPointerException("departmentCompany is null"); //NOI18N
147 } else if (null == departmentName) {
149 throw new NullPointerException("departmentName is null"); //NOI18N
150 } else if (departmentName.isEmpty()) {
152 throw new IllegalArgumentException("departmentName is empty"); //NOI18N
156 this.departmentCompany = departmentCompany;
157 this.departmentName = departmentName;
161 public boolean equals (final Object object) {
162 if (null == object) {
164 } else if (this.getClass() != object.getClass()) {
168 final Department other = (Department) object;
170 if (!Objects.equals(this.getDepartmentId(), other.getDepartmentId())) {
172 } else if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) {
174 } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) {
182 public BranchOffice getDepartmentBranchOffice () {
183 return this.departmentBranchOffice;
187 public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
188 this.departmentBranchOffice = departmentBranchOffice;
192 public BusinessBasicData getDepartmentCompany () {
193 return this.departmentCompany;
197 public void setDepartmentCompany (final BusinessBasicData departmentCompany) {
198 this.departmentCompany = departmentCompany;
202 @SuppressWarnings ("ReturnOfDateField")
203 public Date getDepartmentCreated () {
204 return this.departmentCreated;
208 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
209 public void setDepartmentCreated (final Date departmentCreated) {
210 this.departmentCreated = departmentCreated;
214 public HeadquartersData getDepartmentHeadquarters () {
215 return this.departmentHeadquarters;
219 public void setDepartmentHeadquarters (final HeadquartersData departmentHeadquarters) {
220 this.departmentHeadquarters = departmentHeadquarters;
224 public Long getDepartmentId () {
225 return this.departmentId;
229 public void setDepartmentId (final Long departmentId) {
230 this.departmentId = departmentId;
234 public Employee getDepartmentLead () {
235 return this.departmentLead;
239 public void setDepartmentLead (final Employee departmentLead) {
240 this.departmentLead = departmentLead;
244 public String getDepartmentName () {
245 return this.departmentName;
249 public void setDepartmentName (final String departmentName) {
250 this.departmentName = departmentName;
254 public User getDepartmentUserOwner () {
255 return this.departmentUserOwner;
259 public void setDepartmentUserOwner (final User departmentUserOwner) {
260 this.departmentUserOwner = departmentUserOwner;
264 public int hashCode () {
267 hash = 53 * hash + Objects.hashCode(this.getDepartmentId());
268 hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany());
269 hash = 53 * hash + Objects.hashCode(this.getDepartmentName());