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.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"),
65 @SuppressWarnings ("PersistenceUnitPresent")
66 public class BusinessEmployee implements Employable {
72 private static final long serialVersionUID = 48_959_819_859_812_076L;
75 * Branch office (if the employee works there)
77 @JoinColumn (name = "employee_branch_id")
78 @OneToOne (targetEntity = BusinessBranchOffice.class, cascade = CascadeType.REFRESH)
79 private BranchOffice employeeBranchOffice;
82 * Company the employee is working at
84 @JoinColumn (name = "employee_company_id", nullable = false, updatable = false)
85 @OneToOne (targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH, optional = false)
86 private BasicData employeeCompany;
89 * Timestamp when this entry has been created
91 @Basic (optional = false)
92 @Temporal (TemporalType.TIMESTAMP)
93 @Column (name = "employee_entry_created", nullable = false, updatable = false)
94 private Date employeeCreated;
97 * Department the employee works at
99 @JoinColumn (name = "employee_department_id")
100 @OneToOne (targetEntity = BusinessDepartment.class, cascade = CascadeType.REFRESH)
101 private Department employeeDepartment;
104 * Employable's email address
106 @Column (name = "employee_email_address", length = 30)
107 private String employeeEmailAddress;
110 * Head quarters id number (if the employee works there)
112 @JoinColumn (name = "employee_headquarter_id")
113 @OneToOne (targetEntity = BusinessHeadquarter.class, cascade = CascadeType.REFRESH)
114 private Headquarter employeeHeadquarter;
120 @Column (name = "employee_id", nullable = false, updatable = false)
121 @GeneratedValue (strategy = GenerationType.IDENTITY)
122 private Long employeeId;
125 * Employable's business mobile number
127 @JoinColumn (name = "employee_mobile_number_id")
128 @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.REFRESH)
129 private DialableMobileNumber employeeMobileNumber;
132 * Employable's staff number
134 @Column (name = "employee_staff_number", length = 20)
135 private String employeeNumber;
138 * Employable's personal data
140 @JoinColumn (name = "employee_personal_data_id")
141 @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.REFRESH)
142 private Contact employeePersonalData;
145 * Employable's phone extension (or number if different)
147 @Column (name = "employee_phone_extension", length = 10)
148 private Integer employeePhoneExtension;
151 * Employable's position (example: CEO)
153 @JoinColumn (name = "employee_position_id")
154 @OneToOne (targetEntity = EmployeePosition.class, cascade = CascadeType.REFRESH)
155 private JobPosition employeePosition;
158 * User owner instance
160 @JoinColumn (name = "employee_user_id")
161 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
162 private User employeeUserOwner;
165 * Default constructor
167 public BusinessEmployee () {
170 public BusinessEmployee (final BasicData employeeCompany, final String employeeNumber, final Contact employeePersonalData) {
171 // Call other constructor
174 // Validate parameter
175 if (null == employeeCompany) {
177 throw new NullPointerException("employeeCompany is null"); //NOI18N
178 } else if (((null == employeeNumber) || (employeeNumber.isEmpty()) && (null == employeePersonalData))) {
179 // At least one must be given
180 throw new NullPointerException("employeeNumber or employeeContact must be set."); //NOI18N
184 this.employeeCompany = employeeCompany;
185 this.employeeNumber = employeeNumber;
186 this.employeePersonalData = employeePersonalData;
190 public boolean equals (final Object object) {
191 if (null == object) {
193 } else if (this.getClass() != object.getClass()) {
197 final Employable other = (Employable) object;
199 if (!Objects.equals(this.getEmployeeId(), other.getEmployeeId())) {
201 } else if (!Objects.equals(this.getEmployeeCompany(), other.getEmployeeCompany())) {
203 } else if (!Objects.equals(this.getEmployeeNumber(), other.getEmployeeNumber())) {
205 } else if (!Objects.equals(this.getEmployeePersonalData(), other.getEmployeePersonalData())) {
213 public BranchOffice getEmployeeBranchOffice () {
214 return this.employeeBranchOffice;
218 public void setEmployeeBranchOffice (final BranchOffice employeeBranchOffice) {
219 this.employeeBranchOffice = employeeBranchOffice;
223 public BasicData getEmployeeCompany () {
224 return this.employeeCompany;
228 public void setEmployeeCompany (final BasicData employeeCompany) {
229 this.employeeCompany = employeeCompany;
233 @SuppressWarnings ("ReturnOfDateField")
234 public Date getEmployeeCreated () {
235 return this.employeeCreated;
239 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
240 public void setEmployeeCreated (final Date employeeCreated) {
241 this.employeeCreated = employeeCreated;
245 public Department getEmployeeDepartment () {
246 return this.employeeDepartment;
250 public void setEmployeeDepartment (final Department employeeDepartment) {
251 this.employeeDepartment = employeeDepartment;
255 public String getEmployeeEmailAddress () {
256 return this.employeeEmailAddress;
260 public void setEmployeeEmailAddress (final String employeeEmailAddress) {
261 this.employeeEmailAddress = employeeEmailAddress;
265 public Headquarter getEmployeeHeadquarter () {
266 return this.employeeHeadquarter;
270 public void setEmployeeHeadquarter (final Headquarter employeeHeadquarter) {
271 this.employeeHeadquarter = employeeHeadquarter;
275 public Long getEmployeeId () {
276 return this.employeeId;
280 public void setEmployeeId (final Long employeeId) {
281 this.employeeId = employeeId;
285 public DialableMobileNumber getEmployeeMobileNumber () {
286 return this.employeeMobileNumber;
290 public void setEmployeeMobileNumber (final DialableMobileNumber employeeMobileNumber) {
291 this.employeeMobileNumber = employeeMobileNumber;
295 public String getEmployeeNumber () {
296 return this.employeeNumber;
300 public void setEmployeeNumber (final String employeeNumber) {
301 this.employeeNumber = employeeNumber;
305 public Contact getEmployeePersonalData () {
306 return this.employeePersonalData;
310 public void setEmployeePersonalData (final Contact employeePersonalData) {
311 this.employeePersonalData = employeePersonalData;
315 public Integer getEmployeePhoneExtension () {
316 return this.employeePhoneExtension;
320 public void setEmployeePhoneExtension (final Integer employeePhoneExtension) {
321 this.employeePhoneExtension = employeePhoneExtension;
325 public JobPosition getEmployeePosition () {
326 return this.employeePosition;
330 public void setEmployeePosition (final JobPosition employeePosition) {
331 this.employeePosition = employeePosition;
335 public User getEmployeeUserOwner () {
336 return this.employeeUserOwner;
340 public void setEmployeeUserOwner (final User employeeUserOwner) {
341 this.employeeUserOwner = employeeUserOwner;
345 public int hashCode () {
348 hash = 97 * hash + Objects.hashCode(this.getEmployeeId());
349 hash = 97 * hash + Objects.hashCode(this.getEmployeeCompany());
350 hash = 97 * hash + Objects.hashCode(this.getEmployeeNumber());
351 hash = 97 * hash + Objects.hashCode(this.getEmployeePersonalData());