@Table (name = "company_employees")
@NamedQueries (
{
- @NamedQuery (name = "AllEmployees", query = "SELECT e FROM company_employees AS e ORDER BY e.employeeId ASC"),
- }
+ @NamedQuery (name = "AllEmployees", query = "SELECT e FROM company_employees AS e ORDER BY e.employeeId ASC"),}
)
@SuppressWarnings ("PersistenceUnitPresent")
public class BusinessEmployee implements Employable {
public BusinessEmployee () {
}
+ /**
+ * Constructor with all required data
+ * <p>
+ * @param employeeCompany Basic company data
+ * @param employeeNumber Employee number (alternative or extra to
+ * contact)
+ * @param employeePersonalData Personal data (contact)
+ */
public BusinessEmployee (final BasicData employeeCompany, final String employeeNumber, final Contact employeePersonalData) {
// Call other constructor
this();
throw new NullPointerException("employeeCompany is null"); //NOI18N
} else if (((null == employeeNumber) || (employeeNumber.isEmpty()) && (null == employeePersonalData))) {
// At least one must be given
- throw new NullPointerException("employeeNumber or employeeContact must be set."); //NOI18N
+ throw new NullPointerException("employeeNumber or employeePersonalData must be set."); //NOI18N
}
// Set all fields
return false;
}
- final Employable other = (Employable) object;
+ final Employable employee = (Employable) object;
- if (!Objects.equals(this.getEmployeeId(), other.getEmployeeId())) {
+ if (!Objects.equals(this.getEmployeeId(), employee.getEmployeeId())) {
return false;
- } else if (!Objects.equals(this.getEmployeeCompany(), other.getEmployeeCompany())) {
+ } else if (!Objects.equals(this.getEmployeeCompany(), employee.getEmployeeCompany())) {
return false;
- } else if (!Objects.equals(this.getEmployeeNumber(), other.getEmployeeNumber())) {
+ } else if (!Objects.equals(this.getEmployeeNumber(), employee.getEmployeeNumber())) {
return false;
- } else if (!Objects.equals(this.getEmployeePersonalData(), other.getEmployeePersonalData())) {
+ } else if (!Objects.equals(this.getEmployeePersonalData(), employee.getEmployeePersonalData())) {
return false;
}
--- /dev/null
+/*
+ * Copyright (C) 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.employee;
+
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.Objects;
+
+/**
+ * Utilities class for employees
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class Employees implements Serializable {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 158_376_461_255_901L;
+
+ /**
+ * Checks whether both employees are the same
+ * <p>
+ * @param employee1 Employee 1
+ * @param employee2 Employee 2
+ * <p>
+ * @return Whether both are the same
+ */
+ public static boolean isSameEmployeeFound (final Employable employee1, final Employable employee2) {
+ // Validate parameter
+ if (null == employee1) {
+ // Throw NPE
+ throw new NullPointerException("employee1 is null"); //NOI18N
+ } else if (employee1.getEmployeeCompany() == null) {
+ // Throw it again
+ throw new NullPointerException("employee1.employeeCompany is null"); //NOI18N
+ } else if (employee1.getEmployeeCompany().getBasicDataId() == null) {
+ // Throw it again
+ throw new NullPointerException("employee1.employeeCompany.basicDataId is null"); //NOI18N
+ } else if (employee1.getEmployeeCompany().getBasicDataId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("employee1.employeeCompany.basicDataId={0} is invalid.", employee1.getEmployeeCompany().getBasicDataId())); //NOI18N
+ } else if (employee1.getEmployeeBranchOffice() == null && employee1.getEmployeeDepartment() == null && employee1.getEmployeeHeadquarter() == null) {
+ // At least one must be set
+ throw new NullPointerException("employee1.employeeBranchOffice, employee1.employeeDepartment and employee1.employeeHeadquarter is null"); //NOI18N
+ } else if (employee1.getEmployeeBranchOffice() != null && employee1.getEmployeeBranchOffice().getBranchId() == null) {
+ // Throw NPE
+ throw new NullPointerException("employee1.employeeBranchOffice.branchId is null"); //NOI18N
+ } else if (employee1.getEmployeeBranchOffice() != null && employee1.getEmployeeBranchOffice().getBranchId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("employee1.employeeBranchOffice.branchId={0} is invalid.", employee1.getEmployeeBranchOffice().getBranchId())); //NOI18N
+ } else if (employee1.getEmployeeDepartment() != null && employee1.getEmployeeDepartment().getDepartmentId() == null) {
+ // Throw NPE
+ throw new NullPointerException("employee1.employeeDepartment.departmentId is null"); //NOI18N
+ } else if (employee1.getEmployeeDepartment() != null && employee1.getEmployeeDepartment().getDepartmentId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("employee1.employeeDepartment.departmentId={0} is invalid.", employee1.getEmployeeDepartment().getDepartmentId())); //NOI18N
+ } else if (employee1.getEmployeeHeadquarter() != null && employee1.getEmployeeHeadquarter().getHeadquarterId() == null) {
+ // Throw NPE
+ throw new NullPointerException("employee1.employeeHeadquarter.headquarterId is null"); //NOI18N
+ } else if (employee1.getEmployeeHeadquarter() != null && employee1.getEmployeeHeadquarter().getHeadquarterId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("employee1.employeeHeadquarter.headquarterId={0} is invalid.", employee1.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N
+ } else if ((employee1.getEmployeePersonalData() == null) && (employee1.getEmployeeNumber()== null)) {
+ // Both are null
+ throw new NullPointerException("employee1.employeePersonalData and employee1.employeeNumber are null"); //NOI18N
+ } else if ((employee1.getEmployeePersonalData() != null) && (employee1.getEmployeePersonalData().getContactId() == null)) {
+ // Throw NPE
+ throw new NullPointerException("employee1.employeePersonalData.contactId is null"); //NOI18N
+ } else if ((employee1.getEmployeePersonalData() != null) && (employee1.getEmployeePersonalData().getContactId() < 1)) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("employee1.employeePersonalData.contactId={0} is invalid.", employee1.getEmployeePersonalData().getContactId())); //NOI18N
+ } else if ((employee1.getEmployeeNumber() != null) && (employee1.getEmployeeNumber().isEmpty())) {
+ // Throw it again
+ throw new IllegalArgumentException("employee1.employeeNumber is empty"); //NOI18N
+ } else if (null == employee2) {
+ // Throw NPE
+ throw new NullPointerException("employee2 is null"); //NOI18N
+ } else if (employee2.getEmployeeCompany() == null) {
+ // Throw it again
+ throw new NullPointerException("employee2.employeeCompany is null"); //NOI18N
+ } else if (employee2.getEmployeeCompany().getBasicDataId() == null) {
+ // Throw it again
+ throw new NullPointerException("employee2.employeeCompany.basicDataId is null"); //NOI18N
+ } else if (employee2.getEmployeeCompany().getBasicDataId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("employee2.employeeCompany.basicDataId={0} is invalid.", employee2.getEmployeeCompany().getBasicDataId())); //NOI18N
+ } else if (employee2.getEmployeeBranchOffice() == null && employee2.getEmployeeDepartment() == null && employee2.getEmployeeHeadquarter() == null) {
+ // At least one must be set
+ throw new NullPointerException("employee2.employeeBranchOffice, employee2.employeeDepartment and employee2.employeeHeadquarter is null"); //NOI18N
+ } else if (employee2.getEmployeeBranchOffice() != null && employee2.getEmployeeBranchOffice().getBranchId() == null) {
+ // Throw NPE
+ throw new NullPointerException("employee2.employeeBranchOffice.branchId is null"); //NOI18N
+ } else if (employee2.getEmployeeBranchOffice() != null && employee2.getEmployeeBranchOffice().getBranchId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("employee2.employeeBranchOffice.branchId={0} is invalid.", employee2.getEmployeeBranchOffice().getBranchId())); //NOI18N
+ } else if (employee2.getEmployeeDepartment() != null && employee2.getEmployeeDepartment().getDepartmentId() == null) {
+ // Throw NPE
+ throw new NullPointerException("employee2.employeeDepartment.departmentId is null"); //NOI18N
+ } else if (employee2.getEmployeeDepartment() != null && employee2.getEmployeeDepartment().getDepartmentId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("employee2.employeeDepartment.departmentId={0} is invalid.", employee2.getEmployeeDepartment().getDepartmentId())); //NOI18N
+ } else if (employee2.getEmployeeHeadquarter() != null && employee2.getEmployeeHeadquarter().getHeadquarterId() == null) {
+ // Throw NPE
+ throw new NullPointerException("employee2.employeeHeadquarter.headquarterId is null"); //NOI18N
+ } else if (employee2.getEmployeeHeadquarter() != null && employee2.getEmployeeHeadquarter().getHeadquarterId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("employee2.employeeHeadquarter.headquarterId={0} is invalid.", employee2.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N
+ } else if ((employee2.getEmployeePersonalData() == null) && (employee2.getEmployeeNumber()== null)) {
+ // Both are null
+ throw new NullPointerException("employee2.employeePersonalData and employee2.employeeNumber are null"); //NOI18N
+ } else if ((employee2.getEmployeePersonalData() != null) && (employee2.getEmployeePersonalData().getContactId() == null)) {
+ // Throw NPE
+ throw new NullPointerException("employee2.employeePersonalData.contactId is null"); //NOI18N
+ } else if ((employee2.getEmployeePersonalData() != null) && (employee2.getEmployeePersonalData().getContactId() < 1)) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("employee2.employeePersonalData.contactId={0} is invalid.", employee2.getEmployeePersonalData().getContactId())); //NOI18N
+ } else if ((employee2.getEmployeeNumber() != null) && (employee2.getEmployeeNumber().isEmpty())) {
+ // Throw it again
+ throw new IllegalArgumentException("employee2.employeeNumber is empty"); //NOI18N
+ } else if (Objects.equals(employee1, employee2)) {
+ // Found equal entity
+ return true;
+ }
+
+ // Same data found?
+ if (!Objects.equals(employee1.getEmployeeCompany(), employee2.getEmployeeCompany())) {
+ // Not the same companies
+ return false;
+ } else if (!Objects.equals(employee1.getEmployeeNumber(), employee2.getEmployeeNumber())) {
+ // Not same number
+ return false;
+ } else if (!Objects.equals(employee1.getEmployeePersonalData(), employee2.getEmployeePersonalData())) {
+ // Not same personal data
+ return false;
+ }
+
+ // Is same employee
+ return true;
+ }
+
+ /**
+ * Private constructor
+ */
+ private Employees () {
+ // No instances from utilities
+ }
+
+}