2 * Copyright (C) 2016 - 2018 Free Software Foundation
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.employee;
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.NamedQueries;
30 import javax.persistence.NamedQuery;
31 import javax.persistence.OneToOne;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import javax.persistence.Transient;
36 import org.apache.commons.lang3.StringUtils;
37 import org.mxchange.jcontacts.model.contact.Contact;
38 import org.mxchange.jcontacts.model.contact.Contacts;
39 import org.mxchange.jcontacts.model.contact.UserContact;
40 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
41 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
42 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
43 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices;
44 import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice;
45 import org.mxchange.jcontactsbusiness.model.department.BusinessDepartment;
46 import org.mxchange.jcontactsbusiness.model.department.Department;
47 import org.mxchange.jcontactsbusiness.model.department.Departments;
48 import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter;
49 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
50 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarters;
51 import org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition;
52 import org.mxchange.jcontactsbusiness.model.jobposition.JobPosition;
53 import org.mxchange.jcontactsbusiness.model.jobposition.JobPositions;
54 import org.mxchange.jcoreutils.Comparables;
55 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
56 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
57 import org.mxchange.jusercore.model.user.LoginUser;
58 import org.mxchange.jusercore.model.user.User;
61 * A POJO for company employees (including CEO)
63 * @author Roland Häder<roland@mxchange.org>
65 @Entity (name = "company_employees")
66 @Table (name = "company_employees")
69 @NamedQuery (name = "AllEmployees", query = "SELECT e FROM company_employees AS e ORDER BY e.employeeId ASC"),}
71 @SuppressWarnings ("PersistenceUnitPresent")
72 public class BusinessEmployee implements Employable {
78 private static final long serialVersionUID = 48_959_819_859_812_076L;
81 * Company the employee is working at
83 @JoinColumn (name = "employee_company_id", nullable = false, updatable = false)
84 @OneToOne (targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH, optional = false)
85 private BasicData employeeBasicData;
88 * Branch office (if the employee works there)
90 @JoinColumn (name = "employee_branch_id")
91 @OneToOne (targetEntity = BusinessBranchOffice.class, cascade = CascadeType.REFRESH)
92 private BranchOffice employeeBranchOffice;
95 * Timestamp when this entry has been created
97 @Basic (optional = false)
98 @Temporal (TemporalType.TIMESTAMP)
99 @Column (name = "employee_entry_created", nullable = false, updatable = false)
100 private Date employeeCreated;
103 * Department the employee works at
105 @JoinColumn (name = "employee_department_id")
106 @OneToOne (targetEntity = BusinessDepartment.class, cascade = CascadeType.REFRESH)
107 private Department employeeDepartment;
110 * Employee's email address
112 @Column (name = "employee_email_address", length = 30)
113 private String employeeEmailAddress;
116 * Head quarters id number (if the employee works there)
118 @JoinColumn (name = "employee_headquarter_id")
119 @OneToOne (targetEntity = BusinessHeadquarter.class, cascade = CascadeType.REFRESH)
120 private Headquarter employeeHeadquarter;
126 @Column (name = "employee_id", nullable = false, updatable = false)
127 @GeneratedValue (strategy = GenerationType.IDENTITY)
128 private Long employeeId;
131 * Employee's position (example: CEO)
133 @JoinColumn (name = "employee_position_id")
134 @OneToOne (targetEntity = EmployeePosition.class, cascade = CascadeType.REFRESH)
135 private JobPosition employeeJobPosition;
138 * Employee's business mobile number
140 @JoinColumn (name = "employee_mobile_number_id")
141 @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.REFRESH)
142 private DialableMobileNumber employeeMobileNumber;
145 * Employee's staff number
147 @Column (name = "employee_staff_number", length = 20)
148 private String employeeNumber;
151 * Employee's personal data
153 @JoinColumn (name = "employee_personal_data_id")
154 @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.REFRESH)
155 private Contact employeePersonalData;
158 * Employee's phone extension (or number if different)
160 @Column (name = "employee_phone_extension", length = 10)
161 private Integer employeePhoneExtension;
164 * User owner instance
166 @JoinColumn (name = "employee_user_id")
167 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
168 private User employeeUserOwner;
171 * Default constructor
173 public BusinessEmployee () {
177 * Constructor with all required data
179 * @param employeeCompany Basic company data
180 * @param employeeNumber Employee number (alternative or extra to
182 * @param employeePersonalData Personal data (contact)
184 public BusinessEmployee (final BasicData employeeCompany, final String employeeNumber, final Contact employeePersonalData) {
185 // Call other constructor
188 // Validate parameter
189 if (null == employeeCompany) {
191 throw new NullPointerException("employeeCompany is null"); //NOI18N
192 } else if (((null == employeeNumber) || (employeeNumber.isEmpty())) && (null == employeePersonalData)) {
193 // At least one must be given
194 throw new NullPointerException("employeeNumber or employeePersonalData must be set."); //NOI18N
198 this.employeeBasicData = employeeCompany;
199 this.employeeNumber = employeeNumber;
200 this.employeePersonalData = employeePersonalData;
204 public int compareTo (final Employable employable) {
205 // Check parameter on null-reference and equality to this
206 if (null == employable) {
208 throw new NullPointerException("employable is null"); //NOI18N
209 } else if (employable.equals(this)) {
215 final int[] comparators = {
216 // First employee's number
217 StringUtils.compareIgnoreCase(this.getEmployeeNumber(), employable.getEmployeeNumber()),
218 // ... finally contact data
219 Contacts.compare(this.getEmployeePersonalData(), employable.getEmployeePersonalData()),
220 // ... employee's email address
221 StringUtils.compareIgnoreCase(this.getEmployeeEmailAddress(), employable.getEmployeeEmailAddress()),
222 // ... company data (BasicData)
223 this.getEmployeeBasicData().compareTo(employable.getEmployeeBasicData()),
225 JobPositions.compare(this.getEmployeeJobPosition(), employable.getEmployeeJobPosition()),
227 Departments.compare(this.getEmployeeDepartment(), employable.getEmployeeDepartment()),
229 BranchOffices.compare(this.getEmployeeBranchOffice(), employable.getEmployeeBranchOffice()),
230 // ... next headquarters
231 Headquarters.compare(this.getEmployeeHeadquarter(), employable.getEmployeeHeadquarter()),
235 final int comparison = Comparables.checkAll(comparators);
242 public boolean equals (final Object object) {
243 if (null == object) {
245 } else if (this.getClass() != object.getClass()) {
249 final Employable employee = (Employable) object;
251 if (!Objects.equals(this.getEmployeeId(), employee.getEmployeeId())) {
253 } else if (!Objects.equals(this.getEmployeeBasicData(), employee.getEmployeeBasicData())) {
255 } else if (!Objects.equals(this.getEmployeeNumber(), employee.getEmployeeNumber())) {
257 } else if (!Objects.equals(this.getEmployeePersonalData(), employee.getEmployeePersonalData())) {
265 public BasicData getEmployeeBasicData () {
266 return this.employeeBasicData;
270 public void setEmployeeBasicData (final BasicData employeeBasicData) {
271 this.employeeBasicData = employeeBasicData;
275 public BranchOffice getEmployeeBranchOffice () {
276 return this.employeeBranchOffice;
280 public void setEmployeeBranchOffice (final BranchOffice employeeBranchOffice) {
281 this.employeeBranchOffice = employeeBranchOffice;
285 @SuppressWarnings ("ReturnOfDateField")
286 public Date getEmployeeCreated () {
287 return this.employeeCreated;
291 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
292 public void setEmployeeCreated (final Date employeeCreated) {
293 this.employeeCreated = employeeCreated;
297 public Department getEmployeeDepartment () {
298 return this.employeeDepartment;
302 public void setEmployeeDepartment (final Department employeeDepartment) {
303 this.employeeDepartment = employeeDepartment;
307 public String getEmployeeEmailAddress () {
308 return this.employeeEmailAddress;
312 public void setEmployeeEmailAddress (final String employeeEmailAddress) {
313 this.employeeEmailAddress = employeeEmailAddress;
317 public Headquarter getEmployeeHeadquarter () {
318 return this.employeeHeadquarter;
322 public void setEmployeeHeadquarter (final Headquarter employeeHeadquarter) {
323 this.employeeHeadquarter = employeeHeadquarter;
327 public Long getEmployeeId () {
328 return this.employeeId;
332 public void setEmployeeId (final Long employeeId) {
333 this.employeeId = employeeId;
337 public JobPosition getEmployeeJobPosition () {
338 return this.employeeJobPosition;
342 public void setEmployeeJobPosition (final JobPosition employeeJobPosition) {
343 this.employeeJobPosition = employeeJobPosition;
347 public DialableMobileNumber getEmployeeMobileNumber () {
348 return this.employeeMobileNumber;
352 public void setEmployeeMobileNumber (final DialableMobileNumber employeeMobileNumber) {
353 this.employeeMobileNumber = employeeMobileNumber;
357 public String getEmployeeNumber () {
358 return this.employeeNumber;
362 public void setEmployeeNumber (final String employeeNumber) {
363 this.employeeNumber = employeeNumber;
367 public Contact getEmployeePersonalData () {
368 return this.employeePersonalData;
372 public void setEmployeePersonalData (final Contact employeePersonalData) {
373 this.employeePersonalData = employeePersonalData;
377 public Integer getEmployeePhoneExtension () {
378 return this.employeePhoneExtension;
382 public void setEmployeePhoneExtension (final Integer employeePhoneExtension) {
383 this.employeePhoneExtension = employeePhoneExtension;
387 public User getEmployeeUserOwner () {
388 return this.employeeUserOwner;
392 public void setEmployeeUserOwner (final User employeeUserOwner) {
393 this.employeeUserOwner = employeeUserOwner;
397 public int hashCode () {
400 hash = 97 * hash + Objects.hashCode(this.getEmployeeId());
401 hash = 97 * hash + Objects.hashCode(this.getEmployeeBasicData());
402 hash = 97 * hash + Objects.hashCode(this.getEmployeeNumber());
403 hash = 97 * hash + Objects.hashCode(this.getEmployeePersonalData());