]> git.mxchange.org Git - addressbook-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sat, 9 Sep 2017 12:18:10 +0000 (14:18 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 9 Sep 2017 19:04:32 +0000 (21:04 +0200)
- introduced isSameCompanyNameAdded() which encapsulates checking for if a
  company name has already been used. This is, together with the thrown checked
  exception a last effort to prevent bad bad SqlException or any other
  "low-level" exception as they are more severage than this.
- thumb of a rule: always pre-validate if all conditions are met (return "okay")
  prior doing risky things where uncontrolled exceptions may be thrown.
- make company-owner (User), founder (Employee) and contact person (dito)
  managed before persisting the whole BasicData instance as this makes sure that
  no duplicates will end up in database

Signed-off-by: Roland Häder <roland@mxchange.org>
16 files changed:
src/java/org/mxchange/addressbook/database/BaseAddressbookDatabaseBean.java
src/java/org/mxchange/jcontactsbusiness/basicdata/AddressbookAdminBusinessDataSessionBean.java
src/java/org/mxchange/jcontactsbusiness/basicdata/AddressbookBusinessDataSessionBean.java
src/java/org/mxchange/jcontactsbusiness/branchoffice/AddressbookAdminBranchOfficeSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jcontactsbusiness/branchoffice/AddressbookBranchOfficeSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jcontactsbusiness/branchoffice/FinancialsAdminBranchOfficeSessionBean.java [deleted file]
src/java/org/mxchange/jcontactsbusiness/branchoffice/FinancialsBranchOfficeSessionBean.java [deleted file]
src/java/org/mxchange/jcontactsbusiness/employee/AddressbookAdminCompanyEmployeeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/employee/AddressbookCompanyEmployeeSessionBean.java
src/java/org/mxchange/jcountry/data/AddressbookCountrySingletonBean.java
src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookAdminMobileProviderSessionBean.java
src/java/org/mxchange/jphone/phonenumbers/mobileprovider/AddressbookMobileProviderSingletonBean.java
src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookAdminPhoneSessionBean.java
src/java/org/mxchange/jphone/phonenumbers/phone/AddressbookPhoneSessionBean.java
src/java/org/mxchange/jusercore/model/user/AddressbookAdminUserSessionBean.java
src/java/org/mxchange/jusercore/model/user/activity/AddressbookUserActivityLogMessageBean.java

index cce383eda55871ac729f72926e1ac8d3d787d153..e19d63d9cff7458c5fdd735b95ccb0e39b3a3926 100644 (file)
@@ -31,6 +31,8 @@ import org.mxchange.jcontacts.model.contact.ContactUtils;
 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.employee.CompanyEmployee;
+import org.mxchange.jcontactsbusiness.model.employee.Employee;
 import org.mxchange.jcoreee.database.BaseDatabaseBean;
 import org.mxchange.jcountry.model.data.Country;
 import org.mxchange.jcountry.model.data.CountryData;
@@ -292,9 +294,9 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
         * <p>
         * @return Managed contact instance
         */
-       protected Contact getManaged (final Contact contact) {
+       protected Contact createManaged (final Contact contact) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: contact={1} - CALLED!", this.getClass().getSimpleName(), contact)); //NOI18N
 
                // user should not be null
                if (null == contact) {
@@ -315,7 +317,7 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                assert (managedContact instanceof Contact) : "managedContact is null"; //NOI18N
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedContact={1} - EXIT!", this.getClass().getSimpleName(), managedContact)); //NOI18N
 
                // Return it
                return managedContact;
@@ -328,9 +330,9 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
         * <p>
         * @return Managed country instance
         */
-       protected Country getManaged (final Country country) {
+       protected Country createManaged (final Country country) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: country={1} - CALLED!", this.getClass().getSimpleName(), country)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: country={1} - CALLED!", this.getClass().getSimpleName(), country)); //NOI18N
 
                // user should not be null
                if (null == country) {
@@ -351,22 +353,22 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                assert (managedCountry instanceof Country) : "managedCountry is null"; //NOI18N
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: managedCountry={1} - EXIT!", this.getClass().getSimpleName(), managedCountry)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedCountry={1} - EXIT!", this.getClass().getSimpleName(), managedCountry)); //NOI18N
 
                // Return it
                return managedCountry;
        }
 
        /**
-        * Get back a managed instance from given contact
+        * Get back a managed instance from given basic data
         * <p>
-        * @param basicData Unmanaged/detached contact instance
+        * @param basicData Unmanaged/detached basic data instance
         * <p>
-        * @return Managed contact instance
+        * @return Managed basic data instance
         */
-       protected BusinessBasicData getManaged (final BusinessBasicData basicData) {
+       protected BusinessBasicData createManaged (final BusinessBasicData basicData) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: basicData={1} - CALLED!", this.getClass().getSimpleName(), basicData)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: basicData={1} - CALLED!", this.getClass().getSimpleName(), basicData)); //NOI18N
 
                // user should not be null
                if (null == basicData) {
@@ -387,12 +389,48 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                assert (managedBasicData instanceof BusinessBasicData) : "managedBasicData is null"; //NOI18N
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: managedBasicData={1} - EXIT!", this.getClass().getSimpleName(), managedBasicData)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedBasicData={1} - EXIT!", this.getClass().getSimpleName(), managedBasicData)); //NOI18N
 
                // Return it
                return managedBasicData;
        }
 
+       /**
+        * Get back a managed instance from given employee
+        * <p>
+        * @param employee Unmanaged/detached employee instance
+        * <p>
+        * @return Managed employee instance
+        */
+       protected Employee createManaged (final Employee employee) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: employee={1} - CALLED!", this.getClass().getSimpleName(), employee)); //NOI18N
+
+               // user should not be null
+               if (null == employee) {
+                       // Abort here
+                       throw new NullPointerException("employee is null"); //NOI18N
+               } else if (employee.getEmployeeId() == null) {
+                       // Id is set
+                       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
+               }
+
+               // Try to find it (should be there)
+               final Employee managedEmployee = this.getEntityManager().find(CompanyEmployee.class, employee.getEmployeeId());
+
+               // Should be there
+               assert (managedEmployee instanceof Employee) : "managedEmployee is null"; //NOI18N
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedEmployee={1} - EXIT!", this.getClass().getSimpleName(), managedEmployee)); //NOI18N
+
+               // Return it
+               return managedEmployee;
+       }
+
        /**
         * Get back a managed instance from given user
         * <p>
@@ -400,9 +438,9 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
         * <p>
         * @return Managed user instance
         */
-       protected User getManaged (final User user) {
+       protected User createManaged (final User user) {
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
 
                // user should not be null
                if (null == user) {
@@ -432,7 +470,7 @@ public abstract class BaseAddressbookDatabaseBean extends BaseDatabaseBean {
                assert (managedUser instanceof User) : "managedUser is null"; //NOI18N
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.createManaged: managedUser={1} - EXIT!", this.getClass().getSimpleName(), managedUser)); //NOI18N
 
                // Return it
                return managedUser;
index 592003baea9fa40c8dd31314f8852d7af182f712..cf8d545cd15cab8a3b39875b2533280d5780fc66 100644 (file)
@@ -24,8 +24,11 @@ import javax.ejb.EJB;
 import javax.ejb.Stateless;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
 import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.model.basicdata.AdminBusinessDataSessionBeanRemote;
 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessDataSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.employee.Employee;
+import org.mxchange.jusercore.model.user.User;
 
 /**
  * An administrative stateless session bean for business data
@@ -66,25 +69,40 @@ public class AddressbookAdminBusinessDataSessionBean extends BaseAddressbookData
                } else if (basicData.getBasicDataId() != null) {
                        // Should be null
                        throw new IllegalArgumentException(MessageFormat.format("basicData.basicDataId={0} - is not null", basicData.getBasicDataId())); //NOI18N
+               } else if (this.isSameCompanyNameAdded(basicData)) {
+                       // Throw exception
+                       throw new BusinessDataAlreadyAddedException(basicData);
                }
 
-               // Get all available entries
-               final List<BusinessBasicData> list = this.businessDataBean.allCompanyBasicData();
+               // Now add current date
+               basicData.setCompanyCreated(new GregorianCalendar());
 
-               // Is the list filled?
-               if (!list.isEmpty()) {
-                       // Then check each entry
-                       for (final BusinessBasicData entry : list) {
-                               // Is the company name matching?
-                               if (Objects.equals(entry.getCompanyName(), basicData.getCompanyName())) {
-                                       // Found match
-                                       throw new BusinessDataAlreadyAddedException(basicData);
-                               }
-                       }
+               // Is there a owner set?
+               if (basicData.getCompanyUserOwner() instanceof User) {
+                       // Get managed instance
+                       final User managedUser = this.createManaged(basicData.getCompanyUserOwner());
+
+                       // Set it back
+                       basicData.setCompanyUserOwner(managedUser);
                }
 
-               // Now add current date
-               basicData.setCompanyCreated(new GregorianCalendar());
+               // Is a founder set?
+               if (basicData.getCompanyFounder() instanceof Employee) {
+                       // Get managed instance
+                       final Employee managedEmployee = this.createManaged(basicData.getCompanyFounder());
+
+                       // Set it back
+                       basicData.setCompanyFounder(managedEmployee);
+               }
+
+               // Is a contact person set?
+               if (basicData.getCompanyContactEmployee() instanceof Employee) {
+                       // Get managed instance
+                       final Employee managedEmployee = this.createManaged(basicData.getCompanyContactEmployee());
+
+                       // Set it back
+                       basicData.setCompanyContactEmployee(managedEmployee);
+               }
 
                // Persist it
                this.getEntityManager().persist(basicData);
@@ -96,4 +114,31 @@ public class AddressbookAdminBusinessDataSessionBean extends BaseAddressbookData
                return basicData;
        }
 
+       /**
+        * Checks if given basic data is already added by it's company name
+        * <p>
+        * @param basicData Basic data to be checked
+        *
+        * @return Whether same company name has been used
+        */
+       private boolean isSameCompanyNameAdded (final BusinessBasicData basicData) {
+               // Get all available entries
+               final List<BusinessBasicData> list = this.businessDataBean.allCompanyBasicData();
+
+               // Default is not found
+               boolean isFound = false;
+
+               // Then check each entry
+               for (final BusinessBasicData entry : list) {
+                       // Is the company name matching?
+                       if (Objects.equals(entry.getCompanyName(), basicData.getCompanyName())) {
+                               // Found match
+                               isFound = true;
+                       }
+               }
+
+               // Return flag
+               return isFound;
+       }
+
 }
index fcd2af925a01037d20b6f327cf959caecc20157e..33d84f6a1382042cd06e94eec48e373996163c31 100644 (file)
@@ -25,6 +25,8 @@ import javax.persistence.Query;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
 import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataNotFoundException;
 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
+import org.mxchange.jcontactsbusiness.model.basicdata.BusinessDataSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData;
 
 /**
  * A stateless session bean for business data
diff --git a/src/java/org/mxchange/jcontactsbusiness/branchoffice/AddressbookAdminBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/branchoffice/AddressbookAdminBranchOfficeSessionBean.java
new file mode 100644 (file)
index 0000000..020d0ba
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * 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.branchoffice;
+
+import java.text.MessageFormat;
+import java.util.GregorianCalendar;
+import java.util.List;
+import javax.ejb.EJB;
+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.branchoffice.AdminBranchOfficeSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A stateless session bean for administrative branch office purposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "adminBranchOffice", description = "An administrative statless bean for handling branch office data (all)")
+public class AddressbookAdminBranchOfficeSessionBean extends BaseAddressbookDatabaseBean implements AdminBranchOfficeSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 58_467_386_571_701L;
+
+       /**
+        * General branch office bean
+        */
+       @EJB
+       private BranchOfficeSessionBeanRemote branchOfficeBean;
+
+       /**
+        * Default constructor
+        */
+       public AddressbookAdminBranchOfficeSessionBean () {
+               // Call super constructor
+               super();
+       }
+
+       @Override
+       public BranchOffice addBranchOffice (final BranchOffice branchOffice) throws BranchOfficeAlreadyAddedException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBranchOffice(): branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N
+
+               // Validate parameter
+               if (null == branchOffice) {
+                       // Throw NPE
+                       throw new NullPointerException("branchOffice is null"); //NOI18N
+               } else if (branchOffice.getBranchId() instanceof Long) {
+                       // Should not happen
+                       throw new IllegalArgumentException("branchOffice.branchId should not be set."); //NOI18N
+               } else if (this.isBranchOfficeFound(branchOffice)) {
+                       // Already added, abort here
+                       throw new BranchOfficeAlreadyAddedException(branchOffice);
+               }
+
+               // Add created timestamp
+               branchOffice.setBranchCreated(new GregorianCalendar());
+
+               // Is user instance set?
+               if (branchOffice.getBranchCompany() instanceof BusinessBasicData) {
+                       // Get managed instance back
+                       final BusinessBasicData managedBasicData = this.createManaged(branchOffice.getBranchCompany());
+
+                       // Set it back in branch office
+                       branchOffice.setBranchCompany(managedBasicData);
+               }
+
+               // Is user instance set?
+               if (branchOffice.getBranchUserOwner() instanceof User) {
+                       // Get managed instance back
+                       final User managedUser = this.createManaged(branchOffice.getBranchUserOwner());
+
+                       // Set it back in branch office
+                       branchOffice.setBranchUserOwner(managedUser);
+               }
+
+               // Is user instance set?
+               if (branchOffice.getBranchCountry() instanceof Country) {
+                       // Get managed instance back
+                       final Country managedCountry = this.createManaged(branchOffice.getBranchCountry());
+
+                       // Set it back in branch office
+                       branchOffice.setBranchCountry(managedCountry);
+               }
+
+               // Persist it
+               this.getEntityManager().persist(branchOffice);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBranchOffice(): branchOffice.branchId={1} - EXIT!", this.getClass().getSimpleName(), branchOffice.getBranchId())); //NOI18N
+
+               // Return updated instance
+               return branchOffice;
+       }
+
+       /**
+        * Checks if given branch office's address is already persisted. The whole
+        * (persisted) list is being loaded and each address is being matched
+        * against the given branch office's address.
+        * <p>
+        * @param branchOffice Branch office being checked
+        * <p>
+        * @return Whether it has been found
+        */
+       private boolean isBranchOfficeFound (final BranchOffice branchOffice) {
+               // Get whole list
+               final List<BranchOffice> branchOffices = this.branchOfficeBean.allBranchOffices();
+
+               // Default is not found
+               boolean isFound = false;
+
+               // Check all single addresses
+               for (final BranchOffice bo : branchOffices) {
+                       // Is the same address found?
+                       if (BranchOffices.isSameAddress(bo, branchOffice)) {
+                               // Found one
+                               isFound = true;
+                               break;
+                       }
+               }
+
+               // Return flag
+               return isFound;
+       }
+
+}
diff --git a/src/java/org/mxchange/jcontactsbusiness/branchoffice/AddressbookBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/branchoffice/AddressbookBranchOfficeSessionBean.java
new file mode 100644 (file)
index 0000000..3fe167a
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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.branchoffice;
+
+import java.text.MessageFormat;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.Query;
+import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote;
+
+/**
+ * A stateless session bean for general branch office purposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "branchOffice", description = "A general statless bean for handling branch office data (all)")
+public class AddressbookBranchOfficeSessionBean extends BaseAddressbookDatabaseBean implements BranchOfficeSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 58_467_386_571_701L;
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<BranchOffice> allBranchOffices () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBranchOffices: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
+               // Get query
+               final Query query = this.getEntityManager().createNamedQuery("AllBranchOffices"); //NOI18N
+
+               // Get list from it
+               final List<BranchOffice> list = query.getResultList();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBranchOffices: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
+
+               // Return it
+               return list;
+       }
+
+}
diff --git a/src/java/org/mxchange/jcontactsbusiness/branchoffice/FinancialsAdminBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/branchoffice/FinancialsAdminBranchOfficeSessionBean.java
deleted file mode 100644 (file)
index c15a831..0000000
+++ /dev/null
@@ -1,144 +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.jcontactsbusiness.branchoffice;
-
-import java.text.MessageFormat;
-import java.util.GregorianCalendar;
-import java.util.List;
-import javax.ejb.EJB;
-import javax.ejb.Stateless;
-import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData;
-import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeAlreadyAddedException;
-import org.mxchange.jcountry.data.Country;
-import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * A stateless session bean for administrative branch office purposes
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "adminBranchOffice", description = "An administrative statless bean for handling branch office data (all)")
-public class FinancialsAdminBranchOfficeSessionBean extends BaseFinancialsDatabaseBean implements AdminBranchOfficeSessionBeanRemote {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 58_467_386_571_701L;
-
-       /**
-        * General branch office bean
-        */
-       @EJB
-       private BranchOfficeSessionBeanRemote branchOfficeBean;
-
-       /**
-        * Default constructor
-        */
-       public FinancialsAdminBranchOfficeSessionBean () {
-               // Call super constructor
-               super();
-       }
-
-       @Override
-       public BranchOffice addBranchOffice (final BranchOffice branchOffice) throws BranchOfficeAlreadyAddedException {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBranchOffice(): branchOffice={1} - CALLED!", this.getClass().getSimpleName(), branchOffice)); //NOI18N
-
-               // Validate parameter
-               if (null == branchOffice) {
-                       // Throw NPE
-                       throw new NullPointerException("branchOffice is null"); //NOI18N
-               } else if (branchOffice.getBranchId() instanceof Long) {
-                       // Should not happen
-                       throw new IllegalArgumentException("branchOffice.branchId should not be set."); //NOI18N
-               } else if (this.isBranchOfficeFound(branchOffice)) {
-                       // Already added, abort here
-                       throw new BranchOfficeAlreadyAddedException(branchOffice);
-               }
-
-               // Add created timestamp
-               branchOffice.setBranchCreated(new GregorianCalendar());
-
-               // Is user instance set?
-               if (branchOffice.getBranchCompany() instanceof BusinessBasicData) {
-                       // Get managed instance back
-                       final BusinessBasicData managedBasicData = this.getManaged(branchOffice.getBranchCompany());
-
-                       // Set it back in branch office
-                       branchOffice.setBranchCompany(managedBasicData);
-               }
-
-               // Is user instance set?
-               if (branchOffice.getBranchUserOwner() instanceof User) {
-                       // Get managed instance back
-                       final User managedUser = this.getManaged(branchOffice.getBranchUserOwner());
-
-                       // Set it back in branch office
-                       branchOffice.setBranchUserOwner(managedUser);
-               }
-
-               // Is user instance set?
-               if (branchOffice.getBranchCountry() instanceof Country) {
-                       // Get managed instance back
-                       final Country managedCountry = this.getManaged(branchOffice.getBranchCountry());
-
-                       // Set it back in branch office
-                       branchOffice.setBranchCountry(managedCountry);
-               }
-
-               // Persist it
-               this.getEntityManager().persist(branchOffice);
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addBranchOffice(): branchOffice.branchId={1} - EXIT!", this.getClass().getSimpleName(), branchOffice.getBranchId())); //NOI18N
-
-               // Return updated instance
-               return branchOffice;
-       }
-
-       /**
-        * Checks if given branch office's address is already persisted. The whole
-        * (persisted) list is being loaded and each address is being matched
-        * against the given branch office's address.
-        * <p>
-        * @param branchOffice Branch office being checked
-        * <p>
-        * @return Whether it has been found
-        */
-       private boolean isBranchOfficeFound (final BranchOffice branchOffice) {
-               // Get whole list
-               final List<BranchOffice> branchOffices = this.branchOfficeBean.allBranchOffices();
-
-               // Default is not found
-               boolean isFound = false;
-
-               // Check all single addresses
-               for (final BranchOffice bo : branchOffices) {
-                       // Is the same address found?
-                       if (BranchOfficeUtils.isSameAddress(bo, branchOffice)) {
-                               // Found one
-                               isFound = true;
-                               break;
-                       }
-               }
-
-               // Return flag
-               return isFound;
-       }
-
-}
diff --git a/src/java/org/mxchange/jcontactsbusiness/branchoffice/FinancialsBranchOfficeSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/branchoffice/FinancialsBranchOfficeSessionBean.java
deleted file mode 100644 (file)
index 0d720c7..0000000
+++ /dev/null
@@ -1,57 +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.jcontactsbusiness.branchoffice;
-
-import java.text.MessageFormat;
-import java.util.List;
-import javax.ejb.Stateless;
-import javax.persistence.Query;
-import org.mxchange.jfinancials.database.BaseFinancialsDatabaseBean;
-
-/**
- * A stateless session bean for general branch office purposes
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "branchOffice", description = "A general statless bean for handling branch office data (all)")
-public class FinancialsBranchOfficeSessionBean extends BaseFinancialsDatabaseBean implements BranchOfficeSessionBeanRemote {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 58_467_386_571_701L;
-
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<BranchOffice> allBranchOffices () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBranchOffices: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
-               // Get query
-               final Query query = this.getEntityManager().createNamedQuery("AllBranchOffices"); //NOI18N
-
-               // Get list from it
-               final List<BranchOffice> list = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allBranchOffices: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
-
-               // Return it
-               return list;
-       }
-
-}
index 391fa3327c060f2bac9f7eb330d8d221755ab4db..27bd3640388e9f6da56722585e153d6601ebc1fa 100644 (file)
@@ -18,6 +18,7 @@ package org.mxchange.jcontactsbusiness.employee;
 
 import javax.ejb.Stateless;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+import org.mxchange.jcontactsbusiness.model.employee.AdminCompanyEmployeeSessionBeanRemote;
 
 /**
  * A stateless bean for administrative purposes for company employees.
index 18aa92973c2856e4d894601ea9253fb60cdc3b77..5c191710b8f254546215db02b1f7ca3a493cf815 100644 (file)
@@ -23,6 +23,8 @@ import javax.persistence.NoResultException;
 import javax.persistence.Query;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
 import org.mxchange.jcontactsbusiness.exceptions.employee.CompanyEmployeeNotFoundException;
+import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.employee.Employee;
 
 /**
  * A stateless bean for general purposes for company employees.
index 08dc8386f2d04dc1ae94ac0c42df686d50b6518d..0aad3fdf3e11272b29e6749665938b33b602875d 100644 (file)
@@ -25,6 +25,9 @@ import javax.persistence.NoResultException;
 import javax.persistence.Query;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
 import org.mxchange.jcountry.exceptions.CountryAlreadyAddedException;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jcountry.model.data.CountryData;
+import org.mxchange.jcountry.model.data.CountrySingletonBeanRemote;
 
 /**
  * A singleton EJB for country informations
index 4f04b1e85a2ba880853f1f54787ddb5c35413329..e36dc5dd9337216cc964e863be65172ad4aade7d 100644 (file)
@@ -21,6 +21,8 @@ import java.util.GregorianCalendar;
 import javax.ejb.Stateless;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
 import org.mxchange.jphone.exceptions.MobileProviderAlreadyAddedException;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.AdminMobileProviderSessionBeanRemote;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
 
 /**
  * An administrative singleton EJB for mobile provider informations
index 1877f08f014de0fe32612eaf6d7720161a625065..58777217202a28411d927ab89ebd3006b4aa9655 100644 (file)
@@ -22,6 +22,9 @@ import javax.ejb.Singleton;
 import javax.ejb.Startup;
 import javax.persistence.Query;
 import org.mxchange.addressbook.database.BaseAddressbookDatabaseBean;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.CellphoneProvider;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote;
 
 /**
  * A singleton EJB for mobile provider informations
index 3b5a5d4955b30a180e3c7c595b33f73c534494c3..bee9e5b65994d4399d7b0828cd188100369e3f6b 100644 (file)
@@ -26,6 +26,7 @@ import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers;
 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumbers;
+import org.mxchange.jphone.model.phonenumbers.phone.AdminPhoneSessionBeanRemote;
 
 /**
  * An EJB for administrative phone purposes
index 4bae357a7383912cdedb5965fa4f48b9575109e4..54259d70a96de869fc345453aea2efe44675c9c6 100644 (file)
@@ -29,6 +29,7 @@ import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
+import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote;
 
 /**
  * A general phone EJB
index 8c1b38691801788e0af8d436a3457c3253c669ba..f8969af1446be768aea8956ffb01312b18fc2197 100644 (file)
@@ -137,7 +137,7 @@ public class AddressbookAdminUserSessionBean extends BaseAddressbookDatabaseBean
                }
 
                // Get a managed instance
-               final User managedUser = this.getManaged(user);
+               final User managedUser = this.createManaged(user);
 
                // Should be found!
                assert (managedUser instanceof User) : MessageFormat.format("User with id {0} not found, but should be.", user.getUserId()); //NOI18N
index 31a9eca7d5ec1e6a26d5d6a1b309465a3f04a705..8387f1ddf65e52e7da2aeacef1335d900387c72a 100644 (file)
@@ -136,7 +136,7 @@ public class AddressbookUserActivityLogMessageBean extends BaseAddressbookDataba
                }
 
                // Make user instance managed
-               final User managedUser = this.getManaged(userActivity.getActivityUser());
+               final User managedUser = this.createManaged(userActivity.getActivityUser());
 
                // Set it back
                userActivity.setActivityUser(managedUser);