From: Roland Häder Date: Mon, 11 May 2020 05:32:28 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=230f6b664f3323da924db1b7ce2c015db58f8ae5;p=jfinancials-war.git Please cherry-pick: - fixed redirection outcome - implemented observer for administrative updates on departments, including uniqueAddDepartment() Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/business/department/action/FinancialsAdminDepartmentActionWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/business/department/action/FinancialsAdminDepartmentActionWebRequestBean.java index e5834f26..383b76e7 100644 --- a/src/java/org/mxchange/jfinancials/beans/business/department/action/FinancialsAdminDepartmentActionWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/business/department/action/FinancialsAdminDepartmentActionWebRequestBean.java @@ -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()); diff --git a/src/java/org/mxchange/jfinancials/beans/business/department/list/FinancialsDepartmentListWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/business/department/list/FinancialsDepartmentListWebViewBean.java index 7408d4f8..be23270b 100644 --- a/src/java/org/mxchange/jfinancials/beans/business/department/list/FinancialsDepartmentListWebViewBean.java +++ b/src/java/org/mxchange/jfinancials/beans/business/department/list/FinancialsDepartmentListWebViewBean.java @@ -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. *

* @param event Event being fired - *

- * @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. + *

+ * @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 + *

+ * @param department Department being uniquely added + */ + private void uniqueAddDepartment (final Department department) { + // Get iterator + final Iterator 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); + } } diff --git a/web/WEB-INF/faces-config.xml b/web/WEB-INF/faces-config.xml index 2264dd82..abe9b286 100644 --- a/web/WEB-INF/faces-config.xml +++ b/web/WEB-INF/faces-config.xml @@ -894,8 +894,8 @@ /admin/contact/admin_contact_show.xhtml - admin_assign_department_employee - /admin/department/admin_assign_department_employee.xhtml + admin_assign_department_lead + /admin/department/admin_assign_department_lead.xhtml admin_assign_department_user