]> git.mxchange.org Git - jcontacts-business-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 7 Oct 2017 19:55:01 +0000 (21:55 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 7 Oct 2017 20:13:51 +0000 (22:13 +0200)
- added event when department has been added
- added exception for not-found opening times
- added utils class for departments
- fixed some tzpos here and there
- used REFRESH instead of ALL as else maybe the other entityos being duplicated
- added first 2 named queries for opening times
- renamed CompanyDepartment -> Department

Signed-off-by: Roland Häder <roland@mxchange.org>
14 files changed:
src/org/mxchange/jcontactsbusiness/events/department/added/DepartmentAddedEvent.java [new file with mode: 0644]
src/org/mxchange/jcontactsbusiness/events/department/added/ObservableDepartmentAddedEvent.java [new file with mode: 0644]
src/org/mxchange/jcontactsbusiness/exceptions/branchoffice/BranchOfficeAlreadyAddedException.java
src/org/mxchange/jcontactsbusiness/exceptions/department/CompanyDepartmentAlreadyAddedException.java [deleted file]
src/org/mxchange/jcontactsbusiness/exceptions/department/CompanyDepartmentNotFoundException.java [deleted file]
src/org/mxchange/jcontactsbusiness/exceptions/department/DepartmentAlreadyAddedException.java [new file with mode: 0644]
src/org/mxchange/jcontactsbusiness/exceptions/department/DepartmentNotFoundException.java [new file with mode: 0644]
src/org/mxchange/jcontactsbusiness/exceptions/opening_times/OpeningTimesNotFoundException.java [new file with mode: 0644]
src/org/mxchange/jcontactsbusiness/model/department/CompanyDepartment.java
src/org/mxchange/jcontactsbusiness/model/department/Department.java
src/org/mxchange/jcontactsbusiness/model/department/Departments.java [new file with mode: 0644]
src/org/mxchange/jcontactsbusiness/model/employee/CompanyEmployee.java
src/org/mxchange/jcontactsbusiness/model/opening_times/BusinessOpeningTimes.java
src/org/mxchange/jcontactsbusiness/model/opening_times/OpeningTimes.java

diff --git a/src/org/mxchange/jcontactsbusiness/events/department/added/DepartmentAddedEvent.java b/src/org/mxchange/jcontactsbusiness/events/department/added/DepartmentAddedEvent.java
new file mode 100644 (file)
index 0000000..7c7cc76
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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.events.department.added;
+
+import java.text.MessageFormat;
+import org.mxchange.jcontactsbusiness.model.department.Department;
+
+/**
+ * An event being fired when a department has been added
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class DepartmentAddedEvent implements ObservableDepartmentAddedEvent {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 572_367_561_659_110L;
+
+       /**
+        * Branch office instance being added
+        */
+       private final Department department;
+
+       /**
+        * Constructor with department instance
+        * <p>
+        * @param department Branch office instance
+        * @throws NullPointerException If the parameter is null
+        */
+       public DepartmentAddedEvent (final Department department) {
+               // Check parameter
+               if (null == department) {
+                       // Throw NPE
+                       throw new NullPointerException("department is null"); //NOI18N
+               } else if (department.getDepartmentId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("department.departmentId is null"); //NOI18N
+               } else if (department.getDepartmentId() < 1) {
+                       // Throw NPE again
+                       throw new NullPointerException(MessageFormat.format("department.departmentId={0} is not valid", department.getDepartmentId())); //NOI18N
+               }
+
+               // Set it
+               this.department = department;
+       }
+
+       @Override
+       public Department getDepartment () {
+               return this.department;
+       }
+
+}
diff --git a/src/org/mxchange/jcontactsbusiness/events/department/added/ObservableDepartmentAddedEvent.java b/src/org/mxchange/jcontactsbusiness/events/department/added/ObservableDepartmentAddedEvent.java
new file mode 100644 (file)
index 0000000..01b2f8c
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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.events.department.added;
+
+import java.io.Serializable;
+import org.mxchange.jcontactsbusiness.model.department.Department;
+
+/**
+ * An interface for events being triggered when a department has been added.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface ObservableDepartmentAddedEvent extends Serializable {
+
+       /**
+        * Getter for department instance
+        * <p>
+        * @return Department instance
+        */
+       Department getDepartment ();
+
+}
index 0ca35e8fccecb383c22d5c915685f9401adaa596..4a49dfeef273f69508ac92d6cd76e92043497292 100644 (file)
@@ -20,7 +20,7 @@ import java.text.MessageFormat;
 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
 
 /**
- * Thrown if the given BusinessBasicData instance is already added
+ * Thrown if the given branch office instance is already added
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
@@ -41,7 +41,7 @@ public class BranchOfficeAlreadyAddedException extends Exception {
        }
 
        /**
-        * Default constructor, may be used if no contact instance is available
+        * Default constructor, may be used if no branch office instance is available
         */
        public BranchOfficeAlreadyAddedException () {
                super("Branch office already added"); //NOI18N
diff --git a/src/org/mxchange/jcontactsbusiness/exceptions/department/CompanyDepartmentAlreadyAddedException.java b/src/org/mxchange/jcontactsbusiness/exceptions/department/CompanyDepartmentAlreadyAddedException.java
deleted file mode 100644 (file)
index 4ac6bd9..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.department;
-
-import java.text.MessageFormat;
-import org.mxchange.jcontactsbusiness.model.department.Department;
-
-/**
- * Thrown if the given BusinessBasicData instance is already added
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class CompanyDepartmentAlreadyAddedException extends Exception {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 129_075_844_851_468L;
-
-       /**
-        * Constructor with a company department instance
-        * <p>
-        * @param department Company department that is already found
-        */
-       public CompanyDepartmentAlreadyAddedException (final Department department) {
-               super(MessageFormat.format("Company department with name {0} already created.", department.getDepartmentName()));
-       }
-
-       /**
-        * Default constructor, may be used if no contact instance is available
-        */
-       public CompanyDepartmentAlreadyAddedException () {
-               super("Company department already added"); //NOI18N
-       }
-
-}
diff --git a/src/org/mxchange/jcontactsbusiness/exceptions/department/CompanyDepartmentNotFoundException.java b/src/org/mxchange/jcontactsbusiness/exceptions/department/CompanyDepartmentNotFoundException.java
deleted file mode 100644 (file)
index 68e568e..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.department;
-
-import java.text.MessageFormat;
-
-/**
- * An exception thrown when a company department (entity) has not found.
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class CompanyDepartmentNotFoundException extends Exception {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 23_759_801_876_416_573L;
-
-       /**
-        * Constructor with company department id
-        * <p>
-        * @param departmentId Company department id
-        */
-       public CompanyDepartmentNotFoundException (final Long departmentId) {
-               // Call super constructor with message and cause
-               super(MessageFormat.format("Company department with id {0} was not found.", departmentId)); //NOI18N
-       }
-
-       /**
-        * Constructor with company department id and causing exception
-        * <p>
-        * @param departmentId Company department id
-        * @param cause          Causing exception
-        */
-       public CompanyDepartmentNotFoundException (final Long departmentId, final Throwable cause) {
-               // Call super constructor with message and cause
-               super(MessageFormat.format("Company department with id {0} was not found.", departmentId), cause); //NOI18N
-       }
-
-}
diff --git a/src/org/mxchange/jcontactsbusiness/exceptions/department/DepartmentAlreadyAddedException.java b/src/org/mxchange/jcontactsbusiness/exceptions/department/DepartmentAlreadyAddedException.java
new file mode 100644 (file)
index 0000000..fcd231b
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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.department;
+
+import java.text.MessageFormat;
+import org.mxchange.jcontactsbusiness.model.department.Department;
+
+/**
+ * Thrown if the given BusinessBasicData instance is already added
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class DepartmentAlreadyAddedException extends Exception {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 129_075_844_851_468L;
+
+       /**
+        * Constructor with a company department instance
+        * <p>
+        * @param department Company department that is already found
+        */
+       public DepartmentAlreadyAddedException (final Department department) {
+               super(MessageFormat.format("Company department with name {0} already created.", department.getDepartmentName()));
+       }
+
+       /**
+        * Default constructor, may be used if no contact instance is available
+        */
+       public DepartmentAlreadyAddedException () {
+               super("Company department already added"); //NOI18N
+       }
+
+}
diff --git a/src/org/mxchange/jcontactsbusiness/exceptions/department/DepartmentNotFoundException.java b/src/org/mxchange/jcontactsbusiness/exceptions/department/DepartmentNotFoundException.java
new file mode 100644 (file)
index 0000000..81e7a97
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.department;
+
+import java.text.MessageFormat;
+
+/**
+ * An exception thrown when a company department (entity) has not found.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class DepartmentNotFoundException extends Exception {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 23_759_801_876_416_573L;
+
+       /**
+        * Constructor with company department id
+        * <p>
+        * @param departmentId Company department id
+        */
+       public DepartmentNotFoundException (final Long departmentId) {
+               // Call super constructor with message and cause
+               super(MessageFormat.format("Company department with id {0} was not found.", departmentId)); //NOI18N
+       }
+
+       /**
+        * Constructor with company department id and causing exception
+        * <p>
+        * @param departmentId Company department id
+        * @param cause          Causing exception
+        */
+       public DepartmentNotFoundException (final Long departmentId, final Throwable cause) {
+               // Call super constructor with message and cause
+               super(MessageFormat.format("Company department with id {0} was not found.", departmentId), cause); //NOI18N
+       }
+
+}
diff --git a/src/org/mxchange/jcontactsbusiness/exceptions/opening_times/OpeningTimesNotFoundException.java b/src/org/mxchange/jcontactsbusiness/exceptions/opening_times/OpeningTimesNotFoundException.java
new file mode 100644 (file)
index 0000000..d232b27
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.opening_times;
+
+import java.text.MessageFormat;
+
+/**
+ * An exception thrown when an opening time (entity) has not found.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class OpeningTimesNotFoundException extends Exception {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 23_759_801_876_416_573L;
+
+       /**
+        * Constructor with opening time id
+        * <p>
+        * @param openingId Opening time id
+        */
+       public OpeningTimesNotFoundException (final Long openingId) {
+               // Call super constructor with message and cause
+               super(MessageFormat.format("Opening time with id {0} was not found.", openingId)); //NOI18N
+       }
+
+       /**
+        * Constructor with opening time id and causing exception
+        * <p>
+        * @param openingId Opening time id
+        * @param cause     Causing exception
+        */
+       public OpeningTimesNotFoundException (final Long openingId, final Throwable cause) {
+               // Call super constructor with message and cause
+               super(MessageFormat.format("Opening time with id {0} was not found.", openingId), cause); //NOI18N
+       }
+
+}
index 25429f49bdc7d78e07f55f692eac20af2e4d2cc3..90a7f85b61917d4ab56ba29878aab95a1ec575a5 100644 (file)
@@ -27,6 +27,8 @@ import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
 import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
 import javax.persistence.Temporal;
@@ -50,6 +52,11 @@ import org.mxchange.jusercore.model.user.User;
  */
 @Entity (name = "company_departments")
 @Table (name = "company_departments")
+@NamedQueries (
+               {
+                       @NamedQuery (name = "AllDepartments", query = "SELECT d FROM company_departments AS d ORDER BY d.departmentId ASC")
+               }
+)
 @SuppressWarnings ("PersistenceUnitPresent")
 public class CompanyDepartment implements Department {
 
@@ -59,13 +66,6 @@ public class CompanyDepartment implements Department {
        @Transient
        private static final long serialVersionUID = 94_835_918_958_717_660L;
 
-       /**
-        * Where this department is located
-        */
-       @JoinColumn (name = "department_headquarters_id")
-       @OneToOne (targetEntity = CompanyHeadquartersData.class, cascade = CascadeType.ALL)
-       private HeadquartersData departentHeadquarters;
-
        /**
         * Where this department is located
         */
@@ -85,9 +85,16 @@ public class CompanyDepartment implements Department {
         */
        @Basic (optional = false)
        @Temporal (TemporalType.TIMESTAMP)
-       @Column (name = "department_entry_created", nullable = false, updatable = false)
+       @Column (name = "department_created", nullable = false, updatable = false)
        private Date departmentCreated;
 
+       /**
+        * Where this department is located
+        */
+       @JoinColumn (name = "department_headquarters_id")
+       @OneToOne (targetEntity = CompanyHeadquartersData.class, cascade = CascadeType.ALL)
+       private HeadquartersData departmentHeadquarters;
+
        /**
         * Id number
         */
@@ -99,7 +106,7 @@ public class CompanyDepartment implements Department {
        /**
         * Department lead employee
         */
-       @JoinColumn (name = "department_lead_id", nullable = false)
+       @JoinColumn (name = "department_lead_id")
        @OneToOne (targetEntity = CompanyEmployee.class, cascade = CascadeType.ALL)
        private Employee departmentLead;
 
@@ -113,10 +120,43 @@ public class CompanyDepartment implements Department {
        /**
         * User owner instance
         */
-       @JoinColumn (name = "department_user_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
+       @JoinColumn (name = "department_user_id")
+       @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
        private User departmentUserOwner;
 
+       /**
+        * Default constructor
+        */
+       public CompanyDepartment () {
+       }
+
+       /**
+        * Constructor with all required fields
+        * <p>
+        * @param departmentCompany Basic data instance
+        * @param departmentName    Department name
+        */
+       public CompanyDepartment (final BusinessBasicData departmentCompany, final String departmentName) {
+               // Call other constructor
+               this();
+
+               // Validate parameter
+               if (null == departmentCompany) {
+                       // Throw NPE
+                       throw new NullPointerException("departmentCompany is null"); //NOI18N
+               } else if (null == departmentName) {
+                       // Throw it again
+                       throw new NullPointerException("departmentName is null"); //NOI18N
+               } else if (departmentName.isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("departmentName is empty"); //NOI18N
+               }
+
+               // Set all fields
+               this.departmentCompany = departmentCompany;
+               this.departmentName = departmentName;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (null == object) {
@@ -138,16 +178,6 @@ public class CompanyDepartment implements Department {
                return true;
        }
 
-       @Override
-       public HeadquartersData getDepartentHeadquarters () {
-               return this.departentHeadquarters;
-       }
-
-       @Override
-       public void setDepartentHeadquarters (final HeadquartersData departentHeadquarters) {
-               this.departentHeadquarters = departentHeadquarters;
-       }
-
        @Override
        public BranchOffice getDepartmentBranchOffice () {
                return this.departmentBranchOffice;
@@ -180,6 +210,16 @@ public class CompanyDepartment implements Department {
                this.departmentCreated = departmentCreated;
        }
 
+       @Override
+       public HeadquartersData getDepartmentHeadquarters () {
+               return this.departmentHeadquarters;
+       }
+
+       @Override
+       public void setDepartmentHeadquarters (final HeadquartersData departmentHeadquarters) {
+               this.departmentHeadquarters = departmentHeadquarters;
+       }
+
        @Override
        public Long getDepartmentId () {
                return this.departmentId;
index f0550fb83934017eabf0fbfe91374cd00e2ee6d4..860d2e2ea6d02dd5f4262cdd2687fc266035bff5 100644 (file)
@@ -50,14 +50,14 @@ public interface Department extends Serializable {
         * <p>
         * @return Connection to company headquarters
         */
-       HeadquartersData getDepartentHeadquarters ();
+       HeadquartersData getDepartmentHeadquarters ();
 
        /**
         * Setter for connection to company headquarters
         * <p>
-        * @param departentHeadquarters Connection to company headquarters
+        * @param departmentHeadquarters Connection to company headquarters
         */
-       void setDepartentHeadquarters (final HeadquartersData departentHeadquarters);
+       void setDepartmentHeadquarters (final HeadquartersData departmentHeadquarters);
 
        /**
         * Getter for connection to company branch office
diff --git a/src/org/mxchange/jcontactsbusiness/model/department/Departments.java b/src/org/mxchange/jcontactsbusiness/model/department/Departments.java
new file mode 100644 (file)
index 0000000..033c736
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * 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.department;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * Utilities class for departments
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class Departments implements Serializable {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 20_154_686_786_561L;
+
+       /**
+        * Checks if both departments are the same (entity) or if at least basic
+        * company data and department name are matching.
+        * <p>
+        * @param department1 Department 1
+        * @param department2 Department 2
+        * <p>
+        * @return Whether both are the same
+        */
+       public static boolean isSameDepartment (final Department department1, final Department department2) {
+               // Now check it
+               if (null == department1) {
+                       // Throw NPE
+                       throw new NullPointerException("department1 is null"); //NOI18N
+               } else if (null == department2) {
+                       // Throw it again
+                       throw new NullPointerException("department2 is null"); //NOI18N
+               } else if (Objects.equals(department1, department2)) {
+                       // Same department
+                       return true;
+               } else if (department1.getDepartmentCompany() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("department1.departmentCompany is null"); //NOI18N
+               } else if (department1.getDepartmentName() == null) {
+                       // Throw it again
+                       throw new NullPointerException("department1.departmentName is null"); //NOI18N
+               } else if (department1.getDepartmentName().isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("department1.departmentName is empty"); //NOI18N
+               } else if (department2.getDepartmentCompany() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("department2.departmentCompany is null"); //NOI18N
+               } else if (department2.getDepartmentName() == null) {
+                       // Throw it again
+                       throw new NullPointerException("department2.departmentName is null"); //NOI18N
+               } else if (department2.getDepartmentName().isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("department2.departmentName is empty"); //NOI18N
+               }
+
+               // Same company and same name?
+               boolean isSame = ((Objects.equals(department1.getDepartmentCompany(), department2.getDepartmentCompany())) &&
+                                                 (Objects.equals(department1.getDepartmentName(), department2.getDepartmentName())));
+
+               // Return it
+               return isSame;
+       }
+
+       /**
+        * Private default constructor
+        */
+       private Departments () {
+               // Prevent instances from utilities classes
+       }
+
+}
index ad54a5c2cd85de116da6a21c25766dfc60e59224..327144b9d64be9b0123102021fd5c71cdb26019c 100644 (file)
@@ -76,14 +76,14 @@ public class CompanyEmployee implements Employee {
         * Branch office (if the employee works there)
         */
        @JoinColumn (name = "employee_branch_id")
-       @OneToOne (targetEntity = CompanyBranchOffice.class, cascade = CascadeType.ALL)
+       @OneToOne (targetEntity = CompanyBranchOffice.class, cascade = CascadeType.REFRESH)
        private BranchOffice employeeBranchOffice;
 
        /**
         * Company the employee is working at
         */
        @JoinColumn (name = "employee_company_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = CompanyBasicData.class, cascade = CascadeType.ALL, optional = false)
+       @OneToOne (targetEntity = CompanyBasicData.class, cascade = CascadeType.REFRESH, optional = false)
        private BusinessBasicData employeeCompany;
 
        /**
@@ -98,7 +98,7 @@ public class CompanyEmployee implements Employee {
         * Department the employee works at
         */
        @JoinColumn (name = "employee_department_id")
-       @OneToOne (targetEntity = CompanyDepartment.class, cascade = CascadeType.ALL)
+       @OneToOne (targetEntity = CompanyDepartment.class, cascade = CascadeType.REFRESH)
        private Department employeeDepartment;
 
        /**
@@ -111,7 +111,7 @@ public class CompanyEmployee implements Employee {
         * Head quarters id number (if the employee works there)
         */
        @JoinColumn (name = "employee_headquarters_id")
-       @OneToOne (targetEntity = CompanyHeadquartersData.class, cascade = CascadeType.ALL)
+       @OneToOne (targetEntity = CompanyHeadquartersData.class, cascade = CascadeType.REFRESH)
        private HeadquartersData employeeHeadquarter;
 
        /**
@@ -126,7 +126,7 @@ public class CompanyEmployee implements Employee {
         * Employee's business mobile number
         */
        @JoinColumn (name = "employee_mobile_number_id")
-       @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.ALL)
+       @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.REFRESH)
        private DialableMobileNumber employeeMobileNumber;
 
        /**
@@ -138,8 +138,8 @@ public class CompanyEmployee implements Employee {
        /**
         * Employee's personal data
         */
-       @JoinColumn (name = "employee_personal_data_id", nullable = false, updatable = false)
-       @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false)
+       @JoinColumn (name = "employee_personal_data_id")
+       @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.REFRESH)
        private Contact employeePersonalData;
 
        /**
@@ -162,6 +162,31 @@ public class CompanyEmployee implements Employee {
        @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
        private User employeeUserOwner;
 
+       /**
+        * Default constructor
+        */
+       public CompanyEmployee () {
+       }
+
+       public CompanyEmployee (final BusinessBasicData employeeCompany, final String employeeNumber, final Contact employeePersonalData) {
+               // Call other constructor
+               this();
+
+               // Validate parameter
+               if (null == employeeCompany) {
+                       // Throw NPE
+                       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
+               }
+
+               // Set all fields
+               this.employeeCompany = employeeCompany;
+               this.employeeNumber = employeeNumber;
+               this.employeePersonalData = employeePersonalData;
+       }
+
        @Override
        public boolean equals (final Object object) {
                if (null == object) {
index 09eba678efcc5b396c026a43d8bcaa8a5e8e1068..81af03c06b2cc37ee8c01d0f52811e86a2520428 100644 (file)
@@ -26,6 +26,8 @@ import javax.persistence.Enumerated;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
 import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
@@ -39,6 +41,12 @@ import org.mxchange.jcontactsbusiness.model.opening_times.dayofweek.DayOfTheWeek
  */
 @Entity (name = "company_opening_times")
 @Table (name = "company_opening_times")
+@NamedQueries (
+               {
+                       @NamedQuery (name = "AllOpeningTimes", query = "SELECT ot FROM company_opening_times AS ot ORDER BY ot.openingId ASC"),
+                       @NamedQuery (name = "SearchOpeningTimesById", query = "SELECT ot FROM company_opening_times AS ot WHERE ot.openingId = :openingId")
+               }
+)
 @SuppressWarnings ("PersistenceUnitPresent")
 public class BusinessOpeningTimes implements OpeningTimes {
 
@@ -53,7 +61,7 @@ public class BusinessOpeningTimes implements OpeningTimes {
         */
        @Column (name = "opening_times_end_day")
        @Enumerated (EnumType.STRING)
-       private DayOfTheWeek endDay;
+       private DayOfTheWeek openingEndDay;
 
        /**
         * Ending time (hh:mm)
@@ -61,7 +69,7 @@ public class BusinessOpeningTimes implements OpeningTimes {
        @Basic (optional = false)
        @Column (name = "opening_times_end_time", nullable = false)
        @Temporal (TemporalType.TIME)
-       private Date endTime;
+       private Date openingEndTime;
 
        /**
         * Id number
@@ -69,7 +77,7 @@ public class BusinessOpeningTimes implements OpeningTimes {
        @Id
        @Column (name = "opening_times_id", nullable = false, updatable = false)
        @GeneratedValue (strategy = GenerationType.IDENTITY)
-       private Long id;
+       private Long openingId;
 
        /**
         * Starting day of opening times
@@ -77,7 +85,7 @@ public class BusinessOpeningTimes implements OpeningTimes {
        @Basic (optional = false)
        @Column (name = "opening_times_start_day", nullable = false)
        @Enumerated (EnumType.STRING)
-       private DayOfTheWeek startDay;
+       private DayOfTheWeek openingStartDay;
 
        /**
         * Starting time (hh:mm)
@@ -85,7 +93,7 @@ public class BusinessOpeningTimes implements OpeningTimes {
        @Basic (optional = false)
        @Column (name = "opening_times_start_time", nullable = false)
        @Temporal (TemporalType.TIME)
-       private Date startTime;
+       private Date openingStartTime;
 
        /**
         * Default constructor
@@ -94,36 +102,36 @@ public class BusinessOpeningTimes implements OpeningTimes {
        }
 
        /**
-        * Constructor with all field
+        * Constructor with all required field
         * <p>
-        * @param endDay    End day
-        * @param endTime   End time
-        * @param id        Id number
-        * @param startDay  Start day
-        * @param startTime Start time
+        * @param openingEndDay    End day
+        * @param openingEndTime   End time
+        * @param openingId        Id number
+        * @param openingStartDay  Start day
+        * @param openingStartTime Start time
         */
-       public BusinessOpeningTimes (final DayOfTheWeek endDay, final Date endTime, final Long id, final DayOfTheWeek startDay, final Date startTime) {
+       public BusinessOpeningTimes (final DayOfTheWeek openingEndDay, final Date openingEndTime, final Long openingId, final DayOfTheWeek openingStartDay, final Date openingStartTime) {
                // Call other constructor
-               this(endDay, endTime, startDay, startTime);
+               this(openingEndDay, openingEndTime, openingStartDay, openingStartTime);
 
-               // Set id number
-               this.id = id;
+               // Set openingTimeId number
+               this.openingId = openingId;
        }
 
        /**
-        * Constructor with all fields except id number
+        * Constructor with all fields except openingTimeId number
         * <p>
-        * @param endDay    End day
-        * @param endTime   End time
-        * @param startDay  Start day
-        * @param startTime Start time
+        * @param openingEndDay    End day
+        * @param openingEndTime   End time
+        * @param openingStartDay  Start day
+        * @param openingStartTime Start time
         */
-       public BusinessOpeningTimes (final DayOfTheWeek endDay, final Date endTime, final DayOfTheWeek startDay, final Date startTime) {
+       public BusinessOpeningTimes (final DayOfTheWeek openingEndDay, final Date openingEndTime, final DayOfTheWeek openingStartDay, final Date openingStartTime) {
                // Set all fields
-               this.endDay = endDay;
-               this.endTime = endTime;
-               this.startDay = startDay;
-               this.startTime = startTime;
+               this.openingEndDay = openingEndDay;
+               this.openingEndTime = openingEndTime;
+               this.openingStartDay = openingStartDay;
+               this.openingStartTime = openingStartTime;
        }
 
        @Override
@@ -138,15 +146,15 @@ public class BusinessOpeningTimes implements OpeningTimes {
 
                final OpeningTimes openingTimes = (OpeningTimes) obj;
 
-               if (!Objects.equals(this.getId(), openingTimes.getId())) {
+               if (!Objects.equals(this.getOpeningId(), openingTimes.getOpeningId())) {
                        return false;
-               } else if (this.getStartDay() != openingTimes.getStartDay()) {
+               } else if (this.getOpeningStartDay() != openingTimes.getOpeningStartDay()) {
                        return false;
-               } else if (this.getEndDay() != openingTimes.getEndDay()) {
+               } else if (this.getOpeningEndDay() != openingTimes.getOpeningEndDay()) {
                        return false;
-               } else if (!Objects.equals(this.getStartTime(), openingTimes.getStartTime())) {
+               } else if (!Objects.equals(this.getOpeningStartTime(), openingTimes.getOpeningStartTime())) {
                        return false;
-               } else if (!Objects.equals(this.getEndTime(), openingTimes.getEndTime())) {
+               } else if (!Objects.equals(this.getOpeningEndTime(), openingTimes.getOpeningEndTime())) {
                        return false;
                }
 
@@ -154,68 +162,68 @@ public class BusinessOpeningTimes implements OpeningTimes {
        }
 
        @Override
-       public DayOfTheWeek getEndDay () {
-               return this.endDay;
+       public DayOfTheWeek getOpeningEndDay () {
+               return this.openingEndDay;
        }
 
        @Override
-       public void setEndDay (final DayOfTheWeek endDay) {
-               this.endDay = endDay;
+       public void setOpeningEndDay (final DayOfTheWeek openingEndDay) {
+               this.openingEndDay = openingEndDay;
        }
 
        @Override
        @SuppressWarnings ("ReturnOfDateField")
-       public Date getEndTime () {
-               return this.endTime;
+       public Date getOpeningEndTime () {
+               return this.openingEndTime;
        }
 
        @Override
        @SuppressWarnings ("AssignmentToDateFieldFromParameter")
-       public void setEndTime (final Date endTime) {
-               this.endTime = endTime;
+       public void setOpeningEndTime (final Date openingEndTime) {
+               this.openingEndTime = openingEndTime;
        }
 
        @Override
-       public Long getId () {
-               return this.id;
+       public Long getOpeningId () {
+               return this.openingId;
        }
 
        @Override
-       public void setId (Long id) {
-               this.id = id;
+       public void setOpeningId (final Long openingId) {
+               this.openingId = openingId;
        }
 
        @Override
-       public DayOfTheWeek getStartDay () {
-               return this.startDay;
+       public DayOfTheWeek getOpeningStartDay () {
+               return this.openingStartDay;
        }
 
        @Override
-       public void setStartDay (final DayOfTheWeek startDay) {
-               this.startDay = startDay;
+       public void setOpeningStartDay (final DayOfTheWeek openingStartDay) {
+               this.openingStartDay = openingStartDay;
        }
 
        @Override
        @SuppressWarnings ("ReturnOfDateField")
-       public Date getStartTime () {
-               return this.startTime;
+       public Date getOpeningStartTime () {
+               return this.openingStartTime;
        }
 
        @Override
        @SuppressWarnings ("AssignmentToDateFieldFromParameter")
-       public void setStartTime (final Date startTime) {
-               this.startTime = startTime;
+       public void setOpeningStartTime (final Date openingStartTime) {
+               this.openingStartTime = openingStartTime;
        }
 
        @Override
        public int hashCode () {
                int hash = 7;
 
-               hash = 97 * hash + Objects.hashCode(this.getId());
-               hash = 97 * hash + Objects.hashCode(this.getStartDay());
-               hash = 97 * hash + Objects.hashCode(this.getEndDay());
-               hash = 97 * hash + Objects.hashCode(this.getStartTime());
-               hash = 97 * hash + Objects.hashCode(this.getEndTime());
+               hash = 97 * hash + Objects.hashCode(this.getOpeningId());
+               hash = 97 * hash + Objects.hashCode(this.getOpeningStartDay());
+               hash = 97 * hash + Objects.hashCode(this.getOpeningEndDay());
+               hash = 97 * hash + Objects.hashCode(this.getOpeningStartTime());
+               hash = 97 * hash + Objects.hashCode(this.getOpeningEndTime());
 
                return hash;
        }
index f62b63bce11ec58437d9a0a891b13c07ef9b6ffd..3278c9e7bb6be825e3d7fb588f59253b4daecf25 100644 (file)
@@ -32,70 +32,70 @@ public interface OpeningTimes extends Serializable {
         * <p>
         * @return Id number
         */
-       Long getId ();
+       Long getOpeningId ();
 
        /**
         * Setter for id number
         * <p>
-        * @param id Id number
+        * @param openingId Id number
         */
-       void setId (final Long id);
+       void setOpeningId (final Long openingId);
 
        /**
         * Getter for starting day
         * <p>
         * @return Starting day
         */
-       DayOfTheWeek getStartDay ();
+       DayOfTheWeek getOpeningStartDay ();
 
        /**
         * Setter for starting day
         * <p>
-        * @param startDay Starting day
+        * @param openingStartDay Starting day
         */
-       void setStartDay (final DayOfTheWeek startDay);
+       void setOpeningStartDay (final DayOfTheWeek openingStartDay);
 
        /**
         * Getter for ending day
         * <p>
         * @return Ending day
         */
-       DayOfTheWeek getEndDay ();
+       DayOfTheWeek getOpeningEndDay ();
 
        /**
         * Setter for ending day
         * <p>
-        * @param endDay Ending day
+        * @param openinhEndDay Ending day
         */
-       void setEndDay (final DayOfTheWeek endDay);
+       void setOpeningEndDay (final DayOfTheWeek openinhEndDay);
 
        /**
         * Getter for starting time
         * <p>
         * @return Starting time
         */
-       Date getStartTime ();
+       Date getOpeningStartTime ();
 
        /**
         * Setter for starting time
         * <p>
-        * @param startTime Starting time
+        * @param openingStartTime Starting time
         */
-       void setStartTime (final Date startTime);
+       void setOpeningStartTime (final Date openingStartTime);
 
        /**
         * Getter for ending time
         * <p>
         * @return Ending time
         */
-       Date getEndTime ();
+       Date getOpeningEndTime ();
 
        /**
         * Setter for ending time
         * <p>
-        * @param endTime Ending time
+        * @param openingEndTime Ending time
         */
-       void setEndTime (final Date endTime);
+       void setOpeningEndTime (final Date openingEndTime);
 
        @Override
        boolean equals (final Object obj);