]> git.mxchange.org Git - addressbook-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sat, 14 Oct 2017 13:32:51 +0000 (15:32 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 1 Feb 2020 03:09:00 +0000 (04:09 +0100)
- added createManaged() methods for BranchOffice and HeadquartersData entities
- added helper method setAllOpeningTimesCreated() which sets "created" entity
  property of all opening times
- renamed EJB [admin]companyEmployee to only plain [admin]employee (enough),
  remember to write the "e" upper-case in adminEmployee
- added EJB for opening times
- added EJB for departments
- updated persistence unit with new entity class' name

Signed-off-by: Roland Häder <roland@mxchange.org>
12 files changed:
src/conf/persistence.xml
src/java/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java
src/java/org/mxchange/addressbook/model/receipt/FinancialAdminReceiptSessionBean.java [deleted file]
src/java/org/mxchange/jcontactsbusiness/model/basicdata/AddressbookBusinessDataSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookAdminBranchOfficeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/branchoffice/AddressbookBranchOfficeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookDepartmentSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookAdminCompanyEmployeeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/employee/AddressbookCompanyEmployeeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookAdminOpeningTimesSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookOpeningTimesSessionBean.java [new file with mode: 0644]

index ee278be3885c2ecac73ca59a0129f87fb6a68f86..274981feaace376a2ee4ba250a0992e537051ae0 100644 (file)
@@ -13,7 +13,7 @@
     <class>org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersData</class>
     <class>org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition</class>
     <class>org.mxchange.jcontactsbusiness.model.logo.CompanyLogo</class>
-    <class>org.mxchange.jcontactsbusiness.model.opening_times.BusinessOpeningTimes</class>
+    <class>org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime</class>
     <class>org.mxchange.jcountry.model.data.CountryData</class>
     <class>org.mxchange.jphone.model.phonenumbers.fax.FaxNumber</class>
     <class>org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber</class>
index 3748fcd2c574f727a5f6532fad0c7ed24fde23df..678220cc96290c7bc8945ff19fa66ecd9222f808 100644 (file)
@@ -18,6 +18,7 @@ package org.mxchange.addressbook.database;
 
 import java.text.MessageFormat;
 import java.util.Date;
+import java.util.List;
 import java.util.Objects;
 import java.util.Properties;
 import javax.ejb.EJBException;
@@ -32,8 +33,12 @@ import org.mxchange.jcontacts.model.contact.UserContact;
 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
 import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData;
 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.branchoffice.CompanyBranchOffice;
 import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployee;
 import org.mxchange.jcontactsbusiness.model.employee.Employee;
+import org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersData;
+import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
+import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
 import org.mxchange.jcoreee.database.BaseDatabaseBean;
 import org.mxchange.jcountry.model.data.Country;
 import org.mxchange.jcountry.model.data.CountryData;
@@ -308,7 +313,7 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                        throw new NullPointerException("contact.contactId is null"); //NOI18N
                } else if (contact.getContactId() < 1) {
                        // Id is set
-                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is null", contact.getContactId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
                }
 
                // Try to find it (should be there)
@@ -344,7 +349,7 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                        throw new NullPointerException("country.countryId is null"); //NOI18N
                } else if (country.getCountryId() < 1) {
                        // Id is set
-                       throw new IllegalArgumentException(MessageFormat.format("country.countryId={0} is null", country.getCountryId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("country.countryId={0} is invalid", country.getCountryId())); //NOI18N
                }
 
                // Try to find it (should be there)
@@ -380,7 +385,7 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                        throw new NullPointerException("basicData.basicDataId is null"); //NOI18N
                } else if (basicData.getBasicDataId() < 1) {
                        // Id is set
-                       throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is null", basicData.getBasicDataId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} is invalid", basicData.getBasicDataId())); //NOI18N
                }
 
                // Try to find it (should be there)
@@ -396,6 +401,42 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                return managedBasicData;
        }
 
+       /**
+        * Get back a managed instance from given branch office
+        * <p>
+        * @param branchOffice Unmanaged/detached branch office instance
+        * <p>
+        * @return Managed basic data instance
+        */
+       protected BranchOffice createManaged (final BranchOffice branchOffice) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N
+
+               // user should not be null
+               if (null == branchOffice) {
+                       // Abort here
+                       throw new NullPointerException("branchOffice is null"); //NOI18N
+               } else if (branchOffice.getBranchId() == null) {
+                       // Id is set
+                       throw new NullPointerException("branchOffice.branchOfficeId is null"); //NOI18N
+               } else if (branchOffice.getBranchId() < 1) {
+                       // Id is set
+                       throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchOfficeId={0} is invalid", branchOffice.getBranchId())); //NOI18N
+               }
+
+               // Try to find it (should be there)
+               final BranchOffice managedBranchOffice = this.getEntityManager().find(CompanyBranchOffice.class, branchOffice.getBranchId());
+
+               // Should be there
+               assert (managedBranchOffice instanceof BusinessBasicData) : "managedBranchOffice is null"; //NOI18N
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBranchOffice={1} - EXIT!", this.getClass().getSimpleName(), managedBranchOffice)); //NOI18N
+
+               // Return it
+               return managedBranchOffice;
+       }
+
        /**
         * Get back a managed instance from given employee
         * <p>
@@ -416,7 +457,7 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                        throw new NullPointerException("employee.employeeId is null"); //NOI18N
                } else if (employee.getEmployeeId() < 1) {
                        // Id is set
-                       throw new IllegalArgumentException(MessageFormat.format("employee.employeeId={0} is null", employee.getEmployeeId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("employee.employeeId={0} is invalid", employee.getEmployeeId())); //NOI18N
                }
 
                // Try to find it (should be there)
@@ -432,6 +473,42 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                return managedEmployee;
        }
 
+       /**
+        * Get back a managed instance from given headquarters
+        * <p>
+        * @param headquarters Unmanaged/detached headquarters instance
+        * <p>
+        * @return Managed basic data instance
+        */
+       protected HeadquartersData createManaged (final HeadquartersData headquarters) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: branchOffice={1} - CALLED!", this.getClass().getSimpleName(), headquarters)); //NOI18N
+
+               // user should not be null
+               if (null == headquarters) {
+                       // Abort here
+                       throw new NullPointerException("branchOffice is null"); //NOI18N
+               } else if (headquarters.getHeadquartersId() == null) {
+                       // Id is set
+                       throw new NullPointerException("branchOffice.headquartersId is null"); //NOI18N
+               } else if (headquarters.getHeadquartersId() < 1) {
+                       // Id is set
+                       throw new IllegalArgumentException(MessageFormat.format("branchOffice.headquartersId={0} is invalid", headquarters.getHeadquartersId())); //NOI18N
+               }
+
+               // Try to find it (should be there)
+               final HeadquartersData managedHeadquarters = this.getEntityManager().find(CompanyHeadquartersData.class, headquarters.getHeadquartersId());
+
+               // Should be there
+               assert (managedHeadquarters instanceof BusinessBasicData) : "managedHeadquarters is null"; //NOI18N
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedHeadquarters={1} - EXIT!", this.getClass().getSimpleName(), managedHeadquarters)); //NOI18N
+
+               // Return it
+               return managedHeadquarters;
+       }
+
        /**
         * Get back a managed instance from given user
         * <p>
@@ -452,7 +529,7 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                        throw new NullPointerException("user.userId is null"); //NOI18N
                } else if (user.getUserId() < 1) {
                        // Id is set
-                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is null", user.getUserId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
                } else if (user.getUserContact() == null) {
                        // Throw NPE again
                        throw new NullPointerException("user.userContact is null"); //NOI18N
@@ -477,6 +554,38 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                return managedUser;
        }
 
+       /**
+        * Sets created timestamp on all opening times.
+        * <p>
+        * @param openingTimes Opening times list
+        * <p>
+        * @throws NullPointerException If given list is null
+        * @throws IllegalArgumentException If given list is empty
+        * @throws IllegalStateException If openingId is not null
+        */
+       protected void setAllOpeningTimesCreated (final List<OpeningTime> openingTimes) {
+               // Validate parameter
+               if (null == openingTimes) {
+                       // Throw NPE
+                       throw new NullPointerException("openingTimes is null");
+               } else if (openingTimes.isEmpty()) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("openingTimes is empty");
+               }
+
+               // Walk through whole list
+               for (final OpeningTime openingTime : openingTimes) {
+                       // Id should not be set
+                       if (openingTime.getOpeningId() != null) {
+                               // Abort here
+                               throw new IllegalStateException("openingTime.openingId is not null");
+                       }
+
+                       // Set created timestamp
+                       openingTime.setOpeningCreated(new Date());
+               }
+       }
+
        /**
         * Updates all contact's phone entry's created timestamps
         * <p>
diff --git a/src/java/org/mxchange/addressbook/model/receipt/FinancialAdminReceiptSessionBean.java b/src/java/org/mxchange/addressbook/model/receipt/FinancialAdminReceiptSessionBean.java
deleted file mode 100644 (file)
index 8b4b615..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * 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 Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jfinancials.model.receipt;
-
-import java.text.MessageFormat;
-import java.util.GregorianCalendar;
-import java.util.List;
-import java.util.Objects;
-import javax.ejb.Stateless;
-import javax.persistence.Query;
-import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean;
-import org.mxchange.jfinancials.exceptions.ReceiptAlreadyAddedException;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * A stateless bean for general purposes for receipts
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "financialReceipt", description = "A stateless session bean for handling receipts.")
-public class FinancialReceiptSessionBean extends BaseFinancialsDatabaseBean implements FinancialReceiptSessionBeanRemote {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 659_868_076_723_741L;
-
-       @Override
-       public BillableReceipt addReceipt (final BillableReceipt receipt) throws ReceiptAlreadyAddedException {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addReceipt(): receipt={1} - CALLED!", this.getClass().getSimpleName(), receipt));
-
-               // Validate parameter
-               if (null == receipt) {
-                       // Throw NPE
-                       throw new NullPointerException("receipt is null");
-               } else if (receipt.getReceiptId() != null) {
-                       // Throw IAE
-                       throw new IllegalArgumentException(MessageFormat.format("receipt.receiptId={0} is not expected.", receipt.getReceiptId()));
-               } else if (receipt.getReceiptIssued() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("receipt.receiptIssued is null");
-               } else if (receipt.getReceiptBranchOffice() == null) {
-                       // Throw it again
-                       throw new NullPointerException("receipt.receiptBranchOffice is null");
-               } else if (receipt.getReceiptBranchOffice().getBranchId() == null) {
-                       // Throw it again
-                       throw new NullPointerException("receipt.receiptBranchOffice.branchId is null");
-               } else if (receipt.getReceiptBranchOffice().getBranchId() < 1) {
-                       // Throw IAE
-                       throw new IllegalArgumentException(MessageFormat.format("receipt.receiptBranchOffice.branchId={0} is not valid.", receipt.getReceiptBranchOffice().getBranchId()));
-               } else if (receipt.getReceiptPaymentType() == null) {
-                       // Throw NPE
-                       throw new NullPointerException("receipt.receiptPaymentType is null");
-               } else if ((receipt.getReceiptUser() instanceof User) && receipt.getReceiptUser().getUserId() == null) {
-                       // Throw NPE again
-                       throw new NullPointerException("receipt.receiptUser.userId is null");
-               } else if ((receipt.getReceiptUser() instanceof User) && receipt.getReceiptUser().getUserId() < 1) {
-                       // Throw NPE again
-                       throw new NullPointerException(MessageFormat.format("receipt.receiptUser.userId={0} is not valid", receipt.getReceiptUser().getUserId()));
-               } else if (this.isReceiptRegistered(receipt)) {
-                       // Has already been registered
-                       throw new ReceiptAlreadyAddedException(receipt);
-               }
-
-               // Add created instance
-               receipt.setReceiptCreated(new GregorianCalendar());
-
-               // Persist it
-               this.getEntityManager().persist(receipt);
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addReceipt(): receipt.receiptId={1} - EXIT!", this.getClass().getSimpleName(), receipt.getReceiptId()));
-
-               // Return it
-               return receipt;
-       }
-
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<BillableReceipt> allReceipts () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allReceipts(): CALLED!", this.getClass().getSimpleName()));
-
-               // Query all
-               final Query query = this.getEntityManager().createNamedQuery("AllReceipts");
-
-               // Get all
-               final List<BillableReceipt> receipts = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allReceipts(): receipts.size()={1} EXIT!", this.getClass().getSimpleName(), receipts.size()));
-
-               // Return it
-               return receipts;
-       }
-
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<BillableReceipt> allUsersReceipts (final User user) {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsersReceipts(): user={1} - CALLED!", this.getClass().getSimpleName(), user));
-
-               // Validate parameter
-               if (null == user) {
-                       // Throw NPE
-                       throw new NullPointerException("user is null");
-               } else if (user.getUserId() == null) {
-                       // Throw it again
-                       throw new NullPointerException("user.userId is null");
-               } else if (user.getUserId() < 1) {
-                       // Throw IAE
-                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId()));
-               }
-
-               // Query all
-               final Query query = this.getEntityManager().createNamedQuery("SearchAllUserReceipts");
-
-               // Add parameter
-               query.setParameter("receiptUser", user);
-
-               // Get all
-               final List<BillableReceipt> receipts = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allUsersReceipts(): receipts.size()={1} EXIT!", this.getClass().getSimpleName(), receipts.size()));
-
-               // Return it
-               return receipts;
-       }
-
-       /**
-        * Checks if given receipt is already persisted by checking receipt number
-        * and branch office combination.
-        * <p>
-        * @param receipt Receipt instance
-        * <p>
-        * @return Whether the receipt has already been registered
-        */
-       private boolean isReceiptRegistered (final BillableReceipt receipt) {
-               // Get all receipts
-               final List<BillableReceipt> receipts = this.allReceipts();
-
-               // Is the list empty?
-               if (receipts.isEmpty()) {
-                       // Abort here
-                       return false;
-               }
-
-               // Default is not found
-               boolean isFound = false;
-
-               // Now, check each entry
-               for (final BillableReceipt foundReceipt : receipts) {
-                       // Is same entity or same receipt number and branch office found?
-                       if (Objects.equals(foundReceipt, receipt)) {
-                               // Yes, then stop searching
-                               isFound = true;
-                               break;
-                       } else if (Receipts.isSameReceipt(foundReceipt, receipt)){
-                               // Yes, then stop searching
-                               isFound = true;
-                               break;
-                       }
-               }
-
-               // Return flag
-               return isFound;
-       }
-
-}
index 7ed0a6e2d706ffdaf485506594b54736579a1052..5f29a8551da14f1c7a8a07f7b3418f63f08b038f 100644 (file)
@@ -70,6 +70,15 @@ public class AddressbookBusinessDataSessionBean extends BaseAddressbookDatabaseB
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBasicDataById: CALLED!", this.getClass().getSimpleName())); //NOI18N
 
+               // Validate parameter
+               if (null == basicDataId) {
+                       // Throw NPE
+                       throw new NullPointerException("basicDataId is null"); //NOI18N
+               } else if (basicDataId < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("basicDataId={0}is invalid", basicDataId)); //NOI18N
+               }
+
                // Get query
                final Query query = this.getEntityManager().createNamedQuery("SearchBusinessDataById", CompanyBasicData.class); //NOI18N
 
index 6456896b85e1558c9d78ad8aafcb05fb240cf131..95d5961e22285240393f703e247f04f20a585e23 100644 (file)
@@ -24,6 +24,7 @@ import javax.ejb.Stateless;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
 import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeAlreadyAddedException;
 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
+import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
 import org.mxchange.jcountry.model.data.Country;
 import org.mxchange.jusercore.model.user.User;
 
@@ -104,6 +105,21 @@ public class AddressbookAdminBranchOfficeSessionBean extends BaseAddressbookData
                // Set "created" timestamp on any number assigned
                this.setAllPhoneEntriesCreated(branchOffice);
 
+               // Get opening times
+               final List<OpeningTime> openingTimes = branchOffice.getBranchOpeningTimes();
+
+               // Debugging:
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.addBranchOffice(): branchOffice.branchOfficeOpeningTimes={1}", this.getClass().getSimpleName(), openingTimes));
+
+               // Is opening times set and not empty?
+               if ((openingTimes instanceof List) && (!openingTimes.isEmpty())) {
+                       // Add created timestamp for all times
+                       this.setAllOpeningTimesCreated(openingTimes);
+               } else {
+                       // Set all to null
+                       branchOffice.setBranchOpeningTimes(null);
+               }
+
                // Persist it
                this.getEntityManager().persist(branchOffice);
 
index 3683fd4063d44311c32a17e4cf225857e0ae97ce..4f4621c2da7d0a74952e2aa5f029a719804376ff 100644 (file)
@@ -61,6 +61,15 @@ public class AddressbookBranchOfficeSessionBean extends BaseAddressbookDatabaseB
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findBranchOfficeById: CALLED!", this.getClass().getSimpleName())); //NOI18N
 
+               // Validate parameter
+               if (null == branchOfficeId) {
+                       // Throw NPE
+                       throw new NullPointerException("branchOfficeId is null"); //NOI18N
+               } else if (branchOfficeId < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("branchOfficeId={0}is invalid", branchOfficeId)); //NOI18N
+               }
+
                // Get query
                final Query query = this.getEntityManager().createNamedQuery("SearchBranchOfficeById", CompanyBranchOffice.class); //NOI18N
 
diff --git a/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookAdminDepartmentSessionBean.java
new file mode 100644 (file)
index 0000000..03b74b7
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * 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 Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.department;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.List;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.employee.Employee;
+import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A stateless session bean for administrative department purposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "adminDepartment", description = "An administrative statless bean for handling department data (all)")
+public class AddressbookAdminDepartmentSessionBean extends BaseAddressbookDatabaseBean implements AdminDepartmentSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 58_467_386_571_701L;
+
+       /**
+        * General department bean
+        */
+       @EJB (lookup = "java:global/addressbook-ejb/department!org.mxchange.jcontactsbusiness.model.department.DepartmentSessionBeanRemote")
+       private DepartmentSessionBeanRemote departmentBean;
+
+       /**
+        * Default constructor
+        */
+       public AddressbookAdminDepartmentSessionBean () {
+               // Call super constructor
+               super();
+       }
+
+       @Override
+       public Department addDepartment (final Department department) throws DepartmentAlreadyAddedException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addDepartment(): department={1} - CALLED!", this.getClass().getSimpleName(), department)); //NOI18N
+
+               // Validate parameter
+               if (null == department) {
+                       // Throw NPE
+                       throw new NullPointerException("department is null"); //NOI18N
+               } else if (department.getDepartmentId() instanceof Long) {
+                       // Should not happen
+                       throw new IllegalArgumentException("department.departmentId should not be set."); //NOI18N
+               } else if (department.getDepartmentCompany() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("department.departmentCompany is null"); //NOI18N
+               } else if (department.getDepartmentCompany().getBasicDataId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("department.departmentCompany.basicDataId is null"); //NOI18N
+               } else if (department.getDepartmentCompany().getBasicDataId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("department.departmentCompany.basicDataId={0} is invalid", department.getDepartmentCompany().getBasicDataId())); //NOI18N
+               } else if (department.getDepartmentI18nKey() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("department.departmentName is null"); //NOI18N
+               } else if (department.getDepartmentI18nKey().isEmpty()) {
+                       // Throw IAE
+                       throw new NullPointerException("department.departmentName is empty"); //NOI18N
+               } else if (this.isDepartmentFound(department)) {
+                       // Already added, abort here
+                       throw new DepartmentAlreadyAddedException(department);
+               }
+
+               // Set created timestamp
+               department.setDepartmentCreated(new Date());
+
+               // Get managed basic data instance
+               final BusinessBasicData managedBasicData = this.createManaged(department.getDepartmentCompany());
+
+               // Set it back
+               department.setDepartmentCompany(managedBasicData);
+
+               // Is branch office set?
+               if (department.getDepartmentBranchOffice() instanceof BranchOffice) {
+                       // Get managed branch office
+                       final BranchOffice managedBranchOffice = this.createManaged(department.getDepartmentBranchOffice());
+
+                       // Set it back
+                       department.setDepartmentBranchOffice(managedBranchOffice);
+               }
+
+               // Is headquarters set?
+               if (department.getDepartmentHeadquarters() instanceof HeadquartersData) {
+                       // Get managed headquarters
+                       final HeadquartersData managedHeadquarters = this.createManaged(department.getDepartmentHeadquarters());
+
+                       // Set it back
+                       department.setDepartmentHeadquarters(managedHeadquarters);
+               }
+
+               // Is lead employee set?
+               if (department.getDepartmentLead()instanceof Employee) {
+                       // Get managed lead employee
+                       final Employee managedEmployee = this.createManaged(department.getDepartmentLead());
+
+                       // Set it back
+                       department.setDepartmentLead(managedEmployee);
+               }
+
+               // Is "owning" user set?
+               if (department.getDepartmentUserOwner()instanceof User) {
+                       // Get managed user
+                       final User managedUser = this.createManaged(department.getDepartmentUserOwner());
+
+                       // Set it back
+                       department.setDepartmentUserOwner(managedUser);
+               }
+
+               // Persist it
+               this.getEntityManager().persist(department);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addDepartment(): department.departmentId={1} - EXIT!", this.getClass().getSimpleName(), department.getDepartmentId())); //NOI18N
+
+               // Return updated instance
+               return department;
+       }
+
+       /**
+        * Checks if given department's address is already persisted. The whole
+        * (persisted) list is being loaded and each address is being matched
+        * against the given department's address.
+        * <p>
+        * @param department Branch office being checked
+        * <p>
+        * @return Whether it has been found
+        */
+       private boolean isDepartmentFound (final Department department) {
+               // Get whole list
+               final List<Department> departments = this.departmentBean.allDepartments();
+
+               // Default is not found
+               boolean isFound = false;
+
+               // Check all single addresses
+               for (final Department dep : departments) {
+                       // Is the same address found?
+                       if (Departments.isSameDepartment(dep, department)) {
+                               // Found one
+                               isFound = true;
+                               break;
+                       }
+               }
+
+               // Return flag
+               return isFound;
+       }
+
+}
diff --git a/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookDepartmentSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/department/AddressbookDepartmentSessionBean.java
new file mode 100644 (file)
index 0000000..452aeec
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * 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 Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.department;
+
+import java.text.MessageFormat;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentNotFoundException;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+
+/**
+ * A stateless session bean for general department purposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "department", description = "A general statless bean for handling branch office data (all)")
+public class AddressbookDepartmentSessionBean extends BaseAddressbookDatabaseBean implements DepartmentSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 58_467_386_571_701L;
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<Department> allDepartments () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allDepartments: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
+               // Get query
+               final Query query = this.getEntityManager().createNamedQuery("AllDepartments"); //NOI18N
+
+               // Get list from it
+               final List<Department> list = query.getResultList();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allDepartments: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
+
+               // Return it
+               return list;
+       }
+
+       @Override
+       public Department findDepartmentById (final Long departmentId) throws DepartmentNotFoundException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findDepartmentById: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
+               // Validate parameter
+               if (null == departmentId) {
+                       // Throw NPE
+                       throw new NullPointerException("departmentId is null"); //NOI18N
+               } else if (departmentId < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("departmentId={0}is invalid", departmentId)); //NOI18N
+               }
+
+               // Get query
+               final Query query = this.getEntityManager().createNamedQuery("SearchDepartmentById", CompanyDepartment.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("departmentId", departmentId); //NOI18N
+
+               // Get single instance
+               final Department department;
+
+               // Try to find a result
+               try {
+                       // Find a single result
+                       department = (Department) query.getSingleResult();
+
+                       // Log trace message
+                       this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findDepartmentById: Found department={1}", this.getClass().getSimpleName(), department)); //NOI18N
+               } catch (final NoResultException ex) {
+                       // No result found
+                       throw new DepartmentNotFoundException(departmentId, ex);
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findDepartmentById: department={1} - EXIT!", this.getClass().getSimpleName(), department)); //NOI18N
+
+               // Return it
+               return department;
+       }
+
+}
index 00155670dc8acf26eda138098dcf2c05ad0773cf..11cb56ff39cc3c0c0717cf333ffff3a0a1163b84 100644 (file)
@@ -24,7 +24,7 @@ import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-@Stateless (name = "adminCompanyEmployee", description = "An administrative statless bean for handling company employees")
+@Stateless (name = "adminEmployee", description = "An administrative statless bean for handling company employees")
 public class AddressbookAdminCompanyEmployeeSessionBean extends BaseAddressbookDatabaseBean implements AdminCompanyEmployeeSessionBeanRemote {
 
        /**
index 8d8673a51f3533a7d23759034d1462c621e5790b..f6dbe38433d33e3f9d79cfcc1ea680198da9b8e8 100644 (file)
@@ -29,7 +29,7 @@ import org.mxchange.jcontactsbusiness.exceptions.employee.CompanyEmployeeNotFoun
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-@Stateless (name = "companyEmployee", description = "A general statless bean for handling company employees")
+@Stateless (name = "employee", description = "A general statless bean for handling company employees")
 public class AddressbookCompanyEmployeeSessionBean extends BaseAddressbookDatabaseBean implements CompanyEmployeeSessionBeanRemote {
 
        /**
diff --git a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookAdminOpeningTimesSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookAdminOpeningTimesSessionBean.java
new file mode 100644 (file)
index 0000000..70b22f0
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * 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 Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.opening_time;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import javax.ejb.Stateless;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+
+/**
+ * A stateless session bean for administrative opening times purposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "adminOpeningTimes", description = "An administrative statless bean for handling opening times")
+public class AddressbookAdminOpeningTimesSessionBean extends BaseAddressbookDatabaseBean implements AdminOpeningTimeSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 58_467_386_571_701L;
+
+       /**
+        * Default constructor
+        */
+       public AddressbookAdminOpeningTimesSessionBean () {
+               // Call super constructor
+               super();
+       }
+
+       @Override
+       public OpeningTime addOpeningTime (final OpeningTime openingTime) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addOpeningTimes(): openingTime={1} - CALLED!", this.getClass().getSimpleName(), openingTime)); //NOI18N
+
+               // Validate parameter
+               if (null == openingTime) {
+                       // Throw NPE
+                       throw new NullPointerException("openingTime is null"); //NOI18N
+               } else if (openingTime.getOpeningId() instanceof Long) {
+                       // Should not happen
+                       throw new IllegalArgumentException("openingTime.openingId should not be set."); //NOI18N
+               } else if (openingTime.getOpeningStartDay()== null) {
+                       // Throw NPE
+                       throw new NullPointerException("openingTime.openingStartDay is null"); //NOI18N
+               } else if (openingTime.getOpeningStartTime()== null) {
+                       // Throw NPE
+                       throw new NullPointerException("openingTime.openingStartTime is null"); //NOI18N
+               } else if (openingTime.getOpeningEndDay()== null) {
+                       // Throw NPE
+                       throw new NullPointerException("openingTime.openingEndDay is null"); //NOI18N
+               } else if (openingTime.getOpeningEndTime()== null) {
+                       // Throw NPE
+                       throw new NullPointerException("openingTime.openingEndTime is null"); //NOI18N
+               }
+
+               // Set created timestamp
+               openingTime.setOpeningCreated(new Date());
+
+               // Persist it
+               this.getEntityManager().persist(openingTime);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addOpeningTimes(): openingTime.openingId={1} - EXIT!", this.getClass().getSimpleName(), openingTime.getOpeningId())); //NOI18N
+
+               // Return updated instance
+               return openingTime;
+       }
+
+}
diff --git a/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookOpeningTimesSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/opening_time/AddressbookOpeningTimesSessionBean.java
new file mode 100644 (file)
index 0000000..b7d041f
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * 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 Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.opening_time;
+
+import java.text.MessageFormat;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+import org.mxchange.jcontactsbusiness.exceptions.opening_time.OpeningTimeNotFoundException;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+
+/**
+ * A stateless session bean for general opening times purposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "openingTimes", description = "A general statless bean for handling branch office data (all)")
+public class AddressbookOpeningTimesSessionBean extends BaseAddressbookDatabaseBean implements OpeningTimeSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 58_467_386_571_701L;
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<OpeningTime> allOpeningTimes () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allOpeningTimes: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
+               // Get query
+               final Query query = this.getEntityManager().createNamedQuery("AllOpeningTimes"); //NOI18N
+
+               // Get list from it
+               final List<OpeningTime> list = query.getResultList();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allOpeningTimes: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
+
+               // Return it
+               return list;
+       }
+
+       @Override
+       public OpeningTime findOpeningTimesById (final Long departmentId) throws OpeningTimeNotFoundException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findOpeningTimesById: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
+               // Validate parameter
+               if (null == departmentId) {
+                       // Throw NPE
+                       throw new NullPointerException("departmentId is null"); //NOI18N
+               } else if (departmentId < 1) {
+                       // Throw NPE
+                       throw new NullPointerException(MessageFormat.format("departmentId={0}is invalid", departmentId)); //NOI18N
+               }
+
+               // Get query
+               final Query query = this.getEntityManager().createNamedQuery("SearchOpeningTimesById", BusinessOpeningTime.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("departmentId", departmentId); //NOI18N
+
+               // Get single instance
+               final OpeningTime department;
+
+               // Try to find a result
+               try {
+                       // Find a single result
+                       department = (OpeningTime) query.getSingleResult();
+
+                       // Log trace message
+                       this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findOpeningTimesById: Found department={1}", this.getClass().getSimpleName(), department)); //NOI18N
+               } catch (final NoResultException ex) {
+                       // No result found
+                       throw new OpeningTimeNotFoundException(departmentId, ex);
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findOpeningTimesById: department={1} - EXIT!", this.getClass().getSimpleName(), department)); //NOI18N
+
+               // Return it
+               return department;
+       }
+
+}