]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Mon, 11 May 2020 05:32:28 +0000 (07:32 +0200)
committerRoland Häder <roland@mxchange.org>
Mon, 11 May 2020 05:32:28 +0000 (07:32 +0200)
- fixed redirection outcome
- implemented observer for administrative updates on departments, including
  uniqueAddDepartment()

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jfinancials/beans/business/department/action/FinancialsAdminDepartmentActionWebRequestBean.java
src/java/org/mxchange/jfinancials/beans/business/department/list/FinancialsDepartmentListWebViewBean.java
web/WEB-INF/faces-config.xml

index e5834f26b8f116455c6c8e855d3b921f8919f062..383b76e7490943b2e87fd733ac1e93debab03ff6 100644 (file)
@@ -356,7 +356,6 @@ public class FinancialsAdminDepartmentActionWebRequestBean extends BaseFinancial
                final Department department = this.createDepartment();
 
                // Does current (not updated) and just created (maybe updated) match?
-               System.out.println("this.currentDepartment.departmentLead=" + this.getCurrentDepartment().getDepartmentLead() + ",department.departmentLead=" + department.getDepartmentLead() + " - BEFORE!");
                if (Objects.equals(this.getCurrentDepartment(), department)) {
                        // Yes, then output message
                        this.showFacesMessage("form-admin-edit-department:departmentI18nKey", "ADMIN_DEPARTMENT_NOT_UPDATED", FacesMessage.SEVERITY_WARN); //NOI18N
@@ -366,7 +365,9 @@ public class FinancialsAdminDepartmentActionWebRequestBean extends BaseFinancial
                }
 
                // Copy all fields
-               Departments.copyDepartmentData(this.getCurrentDepartment(), department);
+               System.out.println("departmentLead=" + this.getCurrentDepartment().getDepartmentLead() + " - BEFORE!");
+               Departments.copyDepartmentData(department, this.getCurrentDepartment());
+               System.out.println("departmentLead=" + this.getCurrentDepartment().getDepartmentLead() + " - AFTER!");
 
                // Initialize updated instance
                final Department updatedDepartment;
@@ -374,7 +375,7 @@ public class FinancialsAdminDepartmentActionWebRequestBean extends BaseFinancial
                // Try it
                try {
                        // Invoke EJB
-                       updatedDepartment = this.adminDepartmentBean.updateDepartment(department);
+                       updatedDepartment = this.adminDepartmentBean.updateDepartment(this.getCurrentDepartment());
                } catch (final DepartmentNotFoundException ex) {
                        // Throw as a cause
                        throw new FacesException(ex);
@@ -402,6 +403,7 @@ public class FinancialsAdminDepartmentActionWebRequestBean extends BaseFinancial
                department.setDepartmentBranchOffice(this.getDepartmentBranchOffice());
                department.setDepartmentHeadquarter(this.getDepartmentHeadquarter());
                department.setDepartmentId(this.getDepartmentId());
+               System.out.println("this.departmentLead=" + this.getDepartmentLead());
                department.setDepartmentLead(this.getDepartmentLead());
                department.setDepartmentUserOwner(this.getDepartmentUserOwner());
 
index 7408d4f8ade04009ef977880091d5a58ef0224da..be23270b6bf7ed58d7af28c1e56ded5a9aba8811 100644 (file)
@@ -19,8 +19,10 @@ package org.mxchange.jfinancials.beans.business.department.list;
 import fish.payara.cdi.jsr107.impl.NamedCache;
 import java.text.MessageFormat;
 import java.util.Comparator;
+import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Objects;
 import javax.annotation.PostConstruct;
 import javax.cache.Cache;
 import javax.ejb.EJB;
@@ -29,6 +31,7 @@ import javax.faces.view.ViewScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 import org.mxchange.jcontactsbusiness.events.department.added.ObservableAdminDepartmentAddedEvent;
+import org.mxchange.jcontactsbusiness.events.department.updated.ObservableAdminDepartmentUpdatedEvent;
 import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentNotFoundException;
 import org.mxchange.jcontactsbusiness.model.department.Department;
 import org.mxchange.jcontactsbusiness.model.department.DepartmentSessionBeanRemote;
@@ -89,33 +92,59 @@ public class FinancialsDepartmentListWebViewBean extends BaseFinancialsBean impl
        }
 
        /**
-        * Observes events being fired when a department has been added.
+        * Observes events being fired when a department has been added by an
+        * administrator.
         * <p>
         * @param event Event being fired
-        * <p>
-        * @throws NullPointerException If the parameter or it's carried instance is
-        * null
-        * @throws IllegalArgumentException If the branchId is zero or lower
         */
-       public void afterDepartmentAddedEvent (@Observes final ObservableAdminDepartmentAddedEvent event) {
+       public void afterAdminDepartmentAddedEvent (@Observes final ObservableAdminDepartmentAddedEvent event) {
                // Validate parameter
                if (null == event) {
                        // Throw NPE
                        throw new NullPointerException("event is null"); //NOI18N
                } else if (event.getAddedDepartment() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("event.department is null"); //NOI18N
+                       throw new NullPointerException("event.addedDepartment is null"); //NOI18N
                } else if (event.getAddedDepartment().getDepartmentId() == null) {
                        // Throw it again
-                       throw new NullPointerException("event.department.branchId is null"); //NOI18N
+                       throw new NullPointerException("event.addedDepartment.branchId is null"); //NOI18N
                } else if (event.getAddedDepartment().getDepartmentId() < 1) {
                        // Throw IAE
-                       throw new IllegalArgumentException(MessageFormat.format("event.department.branchId={0} is not valid", event.getAddedDepartment().getDepartmentId())); //NOI18N
+                       throw new IllegalArgumentException(MessageFormat.format("event.addedDepartment.branchId={0} is not valid", event.getAddedDepartment().getDepartmentId())); //NOI18N
                }
 
                // Add instance to cache
                this.departmentCache.put(event.getAddedDepartment().getDepartmentId(), event.getAddedDepartment());
-               this.getAllDepartments().add(event.getAddedDepartment());
+               this.uniqueAddDepartment(event.getAddedDepartment());
+       }
+
+       /**
+        * Observes events being fired when a department has been updated by an
+        * administrator.
+        * <p>
+        * @param event Event being fired
+        */
+       public void afterAdminDepartmentUpdatedEvent (@Observes final ObservableAdminDepartmentUpdatedEvent event) {
+               // Validate parameter
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getUpdatedDepartment() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.updatedDepartment is null"); //NOI18N
+               } else if (event.getUpdatedDepartment().getDepartmentId() == null) {
+                       // Throw it again
+                       throw new NullPointerException("event.updatedDepartment.branchId is null"); //NOI18N
+               } else if (event.getUpdatedDepartment().getDepartmentId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("event.updatedDepartment.branchId={0} is not valid", event.getUpdatedDepartment().getDepartmentId())); //NOI18N
+               }
+
+               // Add instance to cache
+               this.departmentCache.put(event.getUpdatedDepartment().getDepartmentId(), event.getUpdatedDepartment());
+
+               // Uniquely add (update) instance
+               this.uniqueAddDepartment(event.getUpdatedDepartment());
        }
 
        @Override
@@ -238,4 +267,29 @@ public class FinancialsDepartmentListWebViewBean extends BaseFinancialsBean impl
                return isFound;
        }
 
+       /**
+        * Uniquely adds given department instance to full list
+        * <p>
+        * @param department Department being uniquely added
+        */
+       private void uniqueAddDepartment (final Department department) {
+               // Get iterator
+               final Iterator<Department> iterator = this.getAllDepartments().iterator();
+
+               // Loop through all
+               while (iterator.hasNext()) {
+                       // Get current entry
+                       final Department currentDepartment = iterator.next();
+
+                       // Does the primary key match?
+                       if (Objects.equals(department.getDepartmentId(), currentDepartment.getDepartmentId())) {
+                               // Yes, remove it and abort iteration
+                               iterator.remove();
+                               break;
+                       }
+               }
+
+               // (Re-) Add department
+               this.getAllDepartments().add(department);
+       }
 }
index 2264dd82a04efb94cfb16e1d79f259eca6563092..abe9b286b1065c59afebd4c622f34254f1578093 100644 (file)
                        <to-view-id>/admin/contact/admin_contact_show.xhtml</to-view-id>
                </navigation-case>
                <navigation-case>
-                       <from-outcome>admin_assign_department_employee</from-outcome>
-                       <to-view-id>/admin/department/admin_assign_department_employee.xhtml</to-view-id>
+                       <from-outcome>admin_assign_department_lead</from-outcome>
+                       <to-view-id>/admin/department/admin_assign_department_lead.xhtml</to-view-id>
                </navigation-case>
                <navigation-case>
                        <from-outcome>admin_assign_department_user</from-outcome>