]> git.mxchange.org Git - jjobs-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>
Wed, 10 Jun 2020 17:59:21 +0000 (19:59 +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/jjobs/beans/business/branchoffice/action/JobsAdminDepartmentActionWebRequestBean.java
src/java/org/mxchange/jjobs/beans/business/department/list/JobsDepartmentListWebViewBean.java
web/WEB-INF/faces-config.xml

index 60422207b9ffa0149d58b8fe6674adf670d3df41..6c62b4125d0ea9799a90ac645b02fd58fb8c7caa 100644 (file)
@@ -356,7 +356,6 @@ public class JobsAdminDepartmentActionWebRequestBean extends BaseJobsBean implem
                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 JobsAdminDepartmentActionWebRequestBean extends BaseJobsBean implem
                }
 
                // 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 JobsAdminDepartmentActionWebRequestBean extends BaseJobsBean implem
                // 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 JobsAdminDepartmentActionWebRequestBean extends BaseJobsBean implem
                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 82328f79d65a166adb7eb9658358b0316bbc8928..5c7dc8f6b33229e87e9315f22bce8ae35f966d36 100644 (file)
@@ -19,8 +19,10 @@ package org.mxchange.jjobs.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 JobsDepartmentListWebViewBean extends BaseJobsBean implements JobsD
        }
 
        /**
-        * 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 JobsDepartmentListWebViewBean extends BaseJobsBean implements JobsD
                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 51b054015904ce744cd3b92ae1135597251e77a3..a11596a36a654c65dc478e7275ec7532e4245451 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>