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.mxchange.jcontacts.model.contact.Contact;
37 import org.mxchange.jcontacts.model.contact.UserContact;
38 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
39 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
40 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
41 import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice;
42 import org.mxchange.jcontactsbusiness.model.department.BusinessDepartment;
43 import org.mxchange.jcontactsbusiness.model.department.Department;
44 import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter;
45 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
46 import org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition;
47 import org.mxchange.jcontactsbusiness.model.jobposition.JobPosition;
48 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
49 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
50 import org.mxchange.jusercore.model.user.LoginUser;
51 import org.mxchange.jusercore.model.user.User;
54 * A POJO for company employees (including CEO)
56 * @author Roland Häder<roland@mxchange.org>
58 @Entity (name = "company_employees")
59 @Table (name = "company_employees")
62 @NamedQuery (name = "AllEmployees", query = "SELECT e FROM company_employees AS e ORDER BY e.employeeId ASC"),}
64 @SuppressWarnings ("PersistenceUnitPresent")
65 public class BusinessEmployee implements Employable {
71 private static final long serialVersionUID = 48_959_819_859_812_076L;
74 * Branch office (if the employee works there)
76 @JoinColumn (name = "employee_branch_id")
77 @OneToOne (targetEntity = BusinessBranchOffice.class, cascade = CascadeType.REFRESH)
78 private BranchOffice employeeBranchOffice;
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 employeeCompany;
88 * Timestamp when this entry has been created
90 @Basic (optional = false)
91 @Temporal (TemporalType.TIMESTAMP)
92 @Column (name = "employee_entry_created", nullable = false, updatable = false)
93 private Date employeeCreated;
96 * Department the employee works at
98 @JoinColumn (name = "employee_department_id")
99 @OneToOne (targetEntity = BusinessDepartment.class, cascade = CascadeType.REFRESH)
100 private Department employeeDepartment;
103 * Employable's email address
105 @Column (name = "employee_email_address", length = 30)
106 private String employeeEmailAddress;
109 * Head quarters id number (if the employee works there)
111 @JoinColumn (name = "employee_headquarter_id")
112 @OneToOne (targetEntity = BusinessHeadquarter.class, cascade = CascadeType.REFRESH)
113 private Headquarter employeeHeadquarter;
119 @Column (name = "employee_id", nullable = false, updatable = false)
120 @GeneratedValue (strategy = GenerationType.IDENTITY)
121 private Long employeeId;
124 * Employable's business mobile number
126 @JoinColumn (name = "employee_mobile_number_id")
127 @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.REFRESH)
128 private DialableMobileNumber employeeMobileNumber;
131 * Employable's staff number
133 @Column (name = "employee_staff_number", length = 20)
134 private String employeeNumber;
137 * Employable's personal data
139 @JoinColumn (name = "employee_personal_data_id")
140 @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.REFRESH)
141 private Contact employeePersonalData;
144 * Employable's phone extension (or number if different)
146 @Column (name = "employee_phone_extension", length = 10)
147 private Integer employeePhoneExtension;
150 * Employable's position (example: CEO)
152 @JoinColumn (name = "employee_position_id")
153 @OneToOne (targetEntity = EmployeePosition.class, cascade = CascadeType.REFRESH)
154 private JobPosition employeePosition;
157 * User owner instance
159 @JoinColumn (name = "employee_user_id")
160 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
161 private User employeeUserOwner;
164 * Default constructor
166 public BusinessEmployee () {
170 * Constructor with all required data
172 * @param employeeCompany Basic company data
173 * @param employeeNumber Employee number (alternative or extra to
175 * @param employeePersonalData Personal data (contact)
177 public BusinessEmployee (final BasicData employeeCompany, final String employeeNumber, final Contact employeePersonalData) {
178 // Call other constructor
181 // Validate parameter
182 if (null == employeeCompany) {
184 throw new NullPointerException("employeeCompany is null"); //NOI18N
185 } else if (((null == employeeNumber) || (employeeNumber.isEmpty())) && (null == employeePersonalData)) {
186 // At least one must be given
187 throw new NullPointerException("employeeNumber or employeePersonalData must be set."); //NOI18N
191 this.employeeCompany = employeeCompany;
192 this.employeeNumber = employeeNumber;
193 this.employeePersonalData = employeePersonalData;
197 public boolean equals (final Object object) {
198 if (null == object) {
200 } else if (this.getClass() != object.getClass()) {
204 final Employable employee = (Employable) object;
206 if (!Objects.equals(this.getEmployeeId(), employee.getEmployeeId())) {
208 } else if (!Objects.equals(this.getEmployeeCompany(), employee.getEmployeeCompany())) {
210 } else if (!Objects.equals(this.getEmployeeNumber(), employee.getEmployeeNumber())) {
212 } else if (!Objects.equals(this.getEmployeePersonalData(), employee.getEmployeePersonalData())) {
220 public BranchOffice getEmployeeBranchOffice () {
221 return this.employeeBranchOffice;
225 public void setEmployeeBranchOffice (final BranchOffice employeeBranchOffice) {
226 this.employeeBranchOffice = employeeBranchOffice;
230 public BasicData getEmployeeCompany () {
231 return this.employeeCompany;
235 public void setEmployeeCompany (final BasicData employeeCompany) {
236 this.employeeCompany = employeeCompany;
240 @SuppressWarnings ("ReturnOfDateField")
241 public Date getEmployeeCreated () {
242 return this.employeeCreated;
246 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
247 public void setEmployeeCreated (final Date employeeCreated) {
248 this.employeeCreated = employeeCreated;
252 public Department getEmployeeDepartment () {
253 return this.employeeDepartment;
257 public void setEmployeeDepartment (final Department employeeDepartment) {
258 this.employeeDepartment = employeeDepartment;
262 public String getEmployeeEmailAddress () {
263 return this.employeeEmailAddress;
267 public void setEmployeeEmailAddress (final String employeeEmailAddress) {
268 this.employeeEmailAddress = employeeEmailAddress;
272 public Headquarter getEmployeeHeadquarter () {
273 return this.employeeHeadquarter;
277 public void setEmployeeHeadquarter (final Headquarter employeeHeadquarter) {
278 this.employeeHeadquarter = employeeHeadquarter;
282 public Long getEmployeeId () {
283 return this.employeeId;
287 public void setEmployeeId (final Long employeeId) {
288 this.employeeId = employeeId;
292 public DialableMobileNumber getEmployeeMobileNumber () {
293 return this.employeeMobileNumber;
297 public void setEmployeeMobileNumber (final DialableMobileNumber employeeMobileNumber) {
298 this.employeeMobileNumber = employeeMobileNumber;
302 public String getEmployeeNumber () {
303 return this.employeeNumber;
307 public void setEmployeeNumber (final String employeeNumber) {
308 this.employeeNumber = employeeNumber;
312 public Contact getEmployeePersonalData () {
313 return this.employeePersonalData;
317 public void setEmployeePersonalData (final Contact employeePersonalData) {
318 this.employeePersonalData = employeePersonalData;
322 public Integer getEmployeePhoneExtension () {
323 return this.employeePhoneExtension;
327 public void setEmployeePhoneExtension (final Integer employeePhoneExtension) {
328 this.employeePhoneExtension = employeePhoneExtension;
332 public JobPosition getEmployeePosition () {
333 return this.employeePosition;
337 public void setEmployeePosition (final JobPosition employeePosition) {
338 this.employeePosition = employeePosition;
342 public User getEmployeeUserOwner () {
343 return this.employeeUserOwner;
347 public void setEmployeeUserOwner (final User employeeUserOwner) {
348 this.employeeUserOwner = employeeUserOwner;
352 public int hashCode () {
355 hash = 97 * hash + Objects.hashCode(this.getEmployeeId());
356 hash = 97 * hash + Objects.hashCode(this.getEmployeeCompany());
357 hash = 97 * hash + Objects.hashCode(this.getEmployeeNumber());
358 hash = 97 * hash + Objects.hashCode(this.getEmployeePersonalData());