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.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.BusinessBasicData;
39 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
40 import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice;
41 import org.mxchange.jcontactsbusiness.model.department.BusinessDepartment;
42 import org.mxchange.jcontactsbusiness.model.department.Department;
43 import org.mxchange.jcontactsbusiness.model.headquarters.BusinessHeadquarters;
44 import org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition;
45 import org.mxchange.jcontactsbusiness.model.jobposition.JobPosition;
46 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
47 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
48 import org.mxchange.jusercore.model.user.LoginUser;
49 import org.mxchange.jusercore.model.user.User;
50 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
51 import org.mxchange.jcontactsbusiness.model.headquarters.Headquarter;
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"),
63 @NamedQuery (name = "SearchEmployeeById", query = "SELECT e FROM company_employees AS e WHERE e.employeeId = :employeeId")
66 @SuppressWarnings ("PersistenceUnitPresent")
67 public class BusinessEmployee implements Employable {
73 private static final long serialVersionUID = 48_959_819_859_812_076L;
76 * Branch office (if the employee works there)
78 @JoinColumn (name = "employee_branch_id")
79 @OneToOne (targetEntity = BusinessBranchOffice.class, cascade = CascadeType.REFRESH)
80 private BranchOffice employeeBranchOffice;
83 * Company the employee is working at
85 @JoinColumn (name = "employee_company_id", nullable = false, updatable = false)
86 @OneToOne (targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH, optional = false)
87 private BasicData employeeCompany;
90 * Timestamp when this entry has been created
92 @Basic (optional = false)
93 @Temporal (TemporalType.TIMESTAMP)
94 @Column (name = "employee_entry_created", nullable = false, updatable = false)
95 private Date employeeCreated;
98 * Department the employee works at
100 @JoinColumn (name = "employee_department_id")
101 @OneToOne (targetEntity = BusinessDepartment.class, cascade = CascadeType.REFRESH)
102 private Department employeeDepartment;
105 * Employable's email address
107 @Column (name = "employee_email_address", length = 30)
108 private String employeeEmailAddress;
111 * Head quarters id number (if the employee works there)
113 @JoinColumn (name = "employee_headquarters_id")
114 @OneToOne (targetEntity = BusinessHeadquarters.class, cascade = CascadeType.REFRESH)
115 private Headquarter employeeHeadquarter;
121 @Column (name = "employee_id", nullable = false, updatable = false)
122 @GeneratedValue (strategy = GenerationType.IDENTITY)
123 private Long employeeId;
126 * Employable's business mobile number
128 @JoinColumn (name = "employee_mobile_number_id")
129 @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.REFRESH)
130 private DialableMobileNumber employeeMobileNumber;
133 * Employable's staff number
135 @Column (name = "employee_staff_number", length = 20)
136 private String employeeNumber;
139 * Employable's personal data
141 @JoinColumn (name = "employee_personal_data_id")
142 @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.REFRESH)
143 private Contact employeePersonalData;
146 * Employable's phone extension (or number if different)
148 @Column (name = "employee_phone_extension", length = 10)
149 private Integer employeePhoneExtension;
152 * Employable's position (example: CEO)
154 @JoinColumn (name = "employee_position_id")
155 @OneToOne (targetEntity = EmployeePosition.class, cascade = CascadeType.REFRESH)
156 private JobPosition employeePosition;
159 * User owner instance
161 @JoinColumn (name = "employee_user_id")
162 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
163 private User employeeUserOwner;
166 * Default constructor
168 public BusinessEmployee () {
171 public BusinessEmployee (final BasicData employeeCompany, final String employeeNumber, final Contact employeePersonalData) {
172 // Call other constructor
175 // Validate parameter
176 if (null == employeeCompany) {
178 throw new NullPointerException("employeeCompany is null"); //NOI18N
179 } else if (((null == employeeNumber) || (employeeNumber.isEmpty()) && (null == employeePersonalData))) {
180 // At least one must be given
181 throw new NullPointerException("employeeNumber or employeeContact must be set."); //NOI18N
185 this.employeeCompany = employeeCompany;
186 this.employeeNumber = employeeNumber;
187 this.employeePersonalData = employeePersonalData;
191 public boolean equals (final Object object) {
192 if (null == object) {
194 } else if (this.getClass() != object.getClass()) {
198 final Employable other = (Employable) object;
200 if (!Objects.equals(this.getEmployeeId(), other.getEmployeeId())) {
202 } else if (!Objects.equals(this.getEmployeeCompany(), other.getEmployeeCompany())) {
204 } else if (!Objects.equals(this.getEmployeeNumber(), other.getEmployeeNumber())) {
206 } else if (!Objects.equals(this.getEmployeePersonalData(), other.getEmployeePersonalData())) {
214 public BranchOffice getEmployeeBranchOffice () {
215 return this.employeeBranchOffice;
219 public void setEmployeeBranchOffice (final BranchOffice employeeBranchOffice) {
220 this.employeeBranchOffice = employeeBranchOffice;
224 public BasicData getEmployeeCompany () {
225 return this.employeeCompany;
229 public void setEmployeeCompany (final BasicData employeeCompany) {
230 this.employeeCompany = employeeCompany;
234 @SuppressWarnings ("ReturnOfDateField")
235 public Date getEmployeeCreated () {
236 return this.employeeCreated;
240 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
241 public void setEmployeeCreated (final Date employeeCreated) {
242 this.employeeCreated = employeeCreated;
246 public Department getEmployeeDepartment () {
247 return this.employeeDepartment;
251 public void setEmployeeDepartment (final Department employeeDepartment) {
252 this.employeeDepartment = employeeDepartment;
256 public String getEmployeeEmailAddress () {
257 return this.employeeEmailAddress;
261 public void setEmployeeEmailAddress (final String employeeEmailAddress) {
262 this.employeeEmailAddress = employeeEmailAddress;
266 public Headquarter getEmployeeHeadquarter () {
267 return this.employeeHeadquarter;
271 public void setEmployeeHeadquarter (final Headquarter employeeHeadquarter) {
272 this.employeeHeadquarter = employeeHeadquarter;
276 public Long getEmployeeId () {
277 return this.employeeId;
281 public void setEmployeeId (final Long employeeId) {
282 this.employeeId = employeeId;
286 public DialableMobileNumber getEmployeeMobileNumber () {
287 return this.employeeMobileNumber;
291 public void setEmployeeMobileNumber (final DialableMobileNumber employeeMobileNumber) {
292 this.employeeMobileNumber = employeeMobileNumber;
296 public String getEmployeeNumber () {
297 return this.employeeNumber;
301 public void setEmployeeNumber (final String employeeNumber) {
302 this.employeeNumber = employeeNumber;
306 public Contact getEmployeePersonalData () {
307 return this.employeePersonalData;
311 public void setEmployeePersonalData (final Contact employeePersonalData) {
312 this.employeePersonalData = employeePersonalData;
316 public Integer getEmployeePhoneExtension () {
317 return this.employeePhoneExtension;
321 public void setEmployeePhoneExtension (final Integer employeePhoneExtension) {
322 this.employeePhoneExtension = employeePhoneExtension;
326 public JobPosition getEmployeePosition () {
327 return this.employeePosition;
331 public void setEmployeePosition (final JobPosition employeePosition) {
332 this.employeePosition = employeePosition;
336 public User getEmployeeUserOwner () {
337 return this.employeeUserOwner;
341 public void setEmployeeUserOwner (final User employeeUserOwner) {
342 this.employeeUserOwner = employeeUserOwner;
346 public int hashCode () {
349 hash = 97 * hash + Objects.hashCode(this.getEmployeeId());
350 hash = 97 * hash + Objects.hashCode(this.getEmployeeCompany());
351 hash = 97 * hash + Objects.hashCode(this.getEmployeeNumber());
352 hash = 97 * hash + Objects.hashCode(this.getEmployeePersonalData());