]> git.mxchange.org Git - jcontacts-business-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Fri, 3 Nov 2017 21:41:05 +0000 (22:41 +0100)
committerRoland Häder <roland@mxchange.org>
Fri, 3 Nov 2017 23:19:14 +0000 (00:19 +0100)
- added exception for already added employees
- fixed serial numbers, must be globally unique
- sorted imports
- added utilities class for employees

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jcontactsbusiness/exceptions/department/DepartmentNotFoundException.java
src/org/mxchange/jcontactsbusiness/exceptions/employee/EmployeeAlreadyAddedException.java [new file with mode: 0644]
src/org/mxchange/jcontactsbusiness/exceptions/headquarter/HeadquarterAlreadyAddedException.java
src/org/mxchange/jcontactsbusiness/exceptions/opening_time/OpeningTimeNotFoundException.java
src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java
src/org/mxchange/jcontactsbusiness/model/employee/Employable.java
src/org/mxchange/jcontactsbusiness/model/employee/Employees.java [new file with mode: 0644]

index 81e7a970cf80a3ecc9ccdcd2fc1269e962bbd663..91b1ad8c073568c5c976c5cd8257a420828e0838 100644 (file)
@@ -28,7 +28,7 @@ public class DepartmentNotFoundException extends Exception {
        /**
         * Serial number
         */
-       private static final long serialVersionUID = 23_759_801_876_416_573L;
+       private static final long serialVersionUID = 23_759_801_876_416_574L;
 
        /**
         * Constructor with company department id
diff --git a/src/org/mxchange/jcontactsbusiness/exceptions/employee/EmployeeAlreadyAddedException.java b/src/org/mxchange/jcontactsbusiness/exceptions/employee/EmployeeAlreadyAddedException.java
new file mode 100644 (file)
index 0000000..441a9e8
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2016, 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.exceptions.employee;
+
+/**
+ * An exception thrown when a employee (entity) has not found.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class EmployeeAlreadyAddedException extends Exception {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 23_759_801_876_416_573L;
+
+       /**
+        * Default constructor
+        */
+       public EmployeeAlreadyAddedException () {
+               super();
+       }
+
+}
index 41629c1b04fb29f5ff9b889ea2bad80ec60a3b05..78c90b0361e12ddc29475c0db2260cdb3756d5e1 100644 (file)
@@ -29,7 +29,7 @@ public class HeadquarterAlreadyAddedException extends Exception {
        /**
         * Serial number
         */
-       private static final long serialVersionUID = 23_759_801_876_416_573L;
+       private static final long serialVersionUID = 23_759_801_876_416_575L;
 
        /**
         * Constructor with a headquarter instance
index 7fc610b8d101dfb4f37130c27fe776c2543f4edc..4471aec13f59f54fe7fc157fcffea218b260580f 100644 (file)
@@ -28,7 +28,7 @@ public class OpeningTimeNotFoundException extends Exception {
        /**
         * Serial number
         */
-       private static final long serialVersionUID = 23_759_801_876_416_573L;
+       private static final long serialVersionUID = 23_759_801_876_416_576L;
 
        /**
         * Constructor with opening time id
index fb9c820215aa7b9a71f62d261d0d7c86496bf447..e3e1e48168d17d90ff98c665dfcba74ab5127004 100644 (file)
@@ -59,8 +59,7 @@ import org.mxchange.jusercore.model.user.User;
 @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 {
@@ -167,6 +166,14 @@ 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();
@@ -177,7 +184,7 @@ public class BusinessEmployee implements Employable {
                        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
@@ -194,15 +201,15 @@ public class BusinessEmployee implements Employable {
                        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;
                }
 
index 532f1da53e82fa4940173eb97bbcc7038128b6c3..a62a6fc6327b1a90e145fa6706ac31c8ee91b395 100644 (file)
@@ -19,13 +19,13 @@ package org.mxchange.jcontactsbusiness.model.employee;
 import java.io.Serializable;
 import java.util.Date;
 import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
 import org.mxchange.jcontactsbusiness.model.department.Department;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
 import org.mxchange.jcontactsbusiness.model.jobposition.JobPosition;
 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
 import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
-import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
 
 /**
  * A POJI for employees
diff --git a/src/org/mxchange/jcontactsbusiness/model/employee/Employees.java b/src/org/mxchange/jcontactsbusiness/model/employee/Employees.java
new file mode 100644 (file)
index 0000000..2d675f1
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * 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
+       }
+
+}