]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Mon, 11 May 2020 02:04:04 +0000 (04:04 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 10 Jun 2020 17:21:16 +0000 (19:21 +0200)
- updateFooEntity() must not allow null primary keys or those below 1

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jcontactsbusiness/model/department/PizzaAdminDepartmentSessionBean.java

index 0fbfe5cef565c2e47ae3e2325c0ec6f6790fc1c0..a090c058965b873f927ed85111d6b5787da64ccd 100644 (file)
@@ -143,6 +143,51 @@ public class PizzaAdminDepartmentSessionBean extends BasePizzaEnterpriseBean imp
                return department;
        }
 
+       @Override
+       public Department updateDepartment (final Department department) throws DepartmentNotFoundException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateDepartment(): 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() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("department.departmentId is null"); //NOI18N
+               } else if (department.getDepartmentId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("department.departmentId={0} is not valid", department.getDepartmentId())); //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 DepartmentNotFoundException(department);
+               }
+
+               // Merge data
+               final Department updatedDepartment = this.mergeDepartmentData(department);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateDepartment(): updatedDepartment={1} - EXIT!", this.getClass().getSimpleName(), updatedDepartment));
+
+               // Return updated instance
+               return updatedDepartment;
+       }
+
        /**
         * Checks if given department's address is already persisted. The whole
         * (persisted) list is being loaded and each address is being matched