From 8bbca0dcefbbbb9d5b898b2b3c3834576fa1ba09 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 8 Oct 2017 02:07:03 +0200 Subject: [PATCH] Please cherry-pick: - renamed companyEmployee to employee as there was no need for - also renamed EJB name and backing beans - half-added event for being fired (and fully observed by general bean) when an employee has been added - if an employee's displayed name is being rendered, also try to render an assigned department (if any) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../JobsBusinessDataWebRequestBean.java | 3 +- .../JobsBranchOfficeWebRequestBean.java | 3 +- .../JobsDepartmentWebRequestBean.java | 3 +- ...obsAdminCompanyEmployeeWebRequestBean.java | 17 ++- ...inCompanyEmployeeWebRequestController.java | 2 +- .../JobsCompanyEmployeeWebRequestBean.java | 100 +++++++++++++----- ...bsCompanyEmployeeWebSessionController.java | 2 +- .../helper/JobsWebRequestHelperBean.java | 8 ++ .../JobsMobileProviderWebRequestBean.java | 3 +- .../JobsCompanyEmployeeConverter.java | 2 +- .../JobsCompanyHeadquartersConverter.java | 2 +- .../localization/bundle_de_DE.properties | 3 + .../localization/bundle_en_US.properties | 3 + .../admin_form_basic_company_data.tpl | 4 +- .../admin_form_branch_office_data.tpl | 2 +- .../department/admin_form_department_data.tpl | 2 +- .../employee/admin_form_employee_data.tpl | 20 ++-- .../admin_basic_company_data_list.xhtml | 4 +- .../admin_branch_office_list.xhtml | 2 +- .../department/admin_department_list.xhtml | 8 +- web/admin/employee/admin_employee_list.xhtml | 6 +- 21 files changed, 132 insertions(+), 67 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/business/basicdata/JobsBusinessDataWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/business/basicdata/JobsBusinessDataWebRequestBean.java index 6d0bd39b..c443c278 100644 --- a/src/java/org/mxchange/jjobs/beans/business/basicdata/JobsBusinessDataWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/business/basicdata/JobsBusinessDataWebRequestBean.java @@ -407,8 +407,7 @@ public class JobsBusinessDataWebRequestBean extends BaseJobsBean implements Jobs public int compare (final BusinessBasicData o1, final BusinessBasicData o2) { return o1.getBasicDataId() > o2.getBasicDataId() ? 1 : o1.getBasicDataId() < o2.getBasicDataId() ? -1 : 0; } - } - ); + }); } } diff --git a/src/java/org/mxchange/jjobs/beans/business/branchoffice/JobsBranchOfficeWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/business/branchoffice/JobsBranchOfficeWebRequestBean.java index 7f365473..be301316 100644 --- a/src/java/org/mxchange/jjobs/beans/business/branchoffice/JobsBranchOfficeWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/business/branchoffice/JobsBranchOfficeWebRequestBean.java @@ -178,8 +178,7 @@ public class JobsBranchOfficeWebRequestBean extends BaseJobsBean implements Jobs public int compare (final BranchOffice o1, final BranchOffice o2) { return o1.getBranchId() > o2.getBranchId() ? 1 : o1.getBranchId() < o2.getBranchId() ? -1 : 0; } - } - ); + }); } } diff --git a/src/java/org/mxchange/jjobs/beans/business/department/JobsDepartmentWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/business/department/JobsDepartmentWebRequestBean.java index 967255c0..2676e98c 100644 --- a/src/java/org/mxchange/jjobs/beans/business/department/JobsDepartmentWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/business/department/JobsDepartmentWebRequestBean.java @@ -178,8 +178,7 @@ public class JobsDepartmentWebRequestBean extends BaseJobsBean implements JobsDe public int compare (final Department o1, final Department o2) { return o1.getDepartmentId() > o2.getDepartmentId() ? 1 : o1.getDepartmentId() < o2.getDepartmentId() ? -1 : 0; } - } - ); + }); } } diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestBean.java index 1c396b7a..aae86ee9 100644 --- a/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestBean.java @@ -18,8 +18,12 @@ package org.mxchange.jjobs.beans.business.employee; import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.inject.Any; +import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jcontactsbusiness.events.employee.added.ObservableEmployeeAddedEvent; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; import org.mxchange.jcontactsbusiness.model.department.Department; @@ -34,15 +38,22 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -@Named ("adminCompanyEmployeeController") +@Named ("adminEmployeeController") @RequestScoped -public class JobsAdminCompanyEmployeeWebRequestBean extends BaseJobsBean implements JobsAdminCompanyEmployeeWebRequestController { +public class JobsAdminEmployeeWebRequestBean extends BaseJobsBean implements JobsAdminEmployeeWebRequestController { /** * Serial number */ private static final long serialVersionUID = 12_886_968_547_360L; + /** + * An event being fired when an employee has been added + */ + @Inject + @Any + private Event addedEmployeeEvent; + /** * EJB for administrative company employee purposes */ @@ -107,7 +118,7 @@ public class JobsAdminCompanyEmployeeWebRequestBean extends BaseJobsBean impleme /** * Default constructor */ - public JobsAdminCompanyEmployeeWebRequestBean () { + public JobsAdminEmployeeWebRequestBean () { // Call super constructor super(); } diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestController.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestController.java index dbbe98ea..c8f55a7b 100644 --- a/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestController.java +++ b/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestController.java @@ -23,6 +23,6 @@ import java.io.Serializable; *

* @author Roland Häder */ -public interface JobsAdminCompanyEmployeeWebRequestController extends Serializable { +public interface JobsAdminEmployeeWebRequestController extends Serializable { } diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebRequestBean.java index 5f03b7a4..ae48e17a 100644 --- a/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebRequestBean.java @@ -17,6 +17,8 @@ package org.mxchange.jjobs.beans.business.employee; 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; @@ -24,8 +26,10 @@ import javax.annotation.PostConstruct; import javax.cache.Cache; import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Observes; import javax.inject.Inject; import javax.inject.Named; +import org.mxchange.jcontactsbusiness.events.employee.added.ObservableEmployeeAddedEvent; import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote; import org.mxchange.jcontactsbusiness.model.employee.Employee; import org.mxchange.jjobs.beans.BaseJobsBean; @@ -35,27 +39,32 @@ import org.mxchange.jjobs.beans.BaseJobsBean; *

* @author Roland Häder */ -@Named ("companyEmployeeController") +@Named ("employeeController") @RequestScoped -public class JobsCompanyEmployeeWebRequestBean extends BaseJobsBean implements JobsCompanyEmployeeWebRequestController { +public class JobsEmployeeWebRequestBean extends BaseJobsBean implements JobsEmployeeWebRequestController { /** * Serial number */ private static final long serialVersionUID = 12_886_968_547_361L; + /** + * List of all employees + */ + private final List allEmployees; + /** * EJB for general company employee purposes */ - @EJB (lookup = "java:global/jjobs-ejb/companyEmployee!org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote") - private CompanyEmployeeSessionBeanRemote companyEmployeeBean; + @EJB (lookup = "java:global/jjobs-ejb/employee!org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote") + private CompanyEmployeeSessionBeanRemote employeeBean; /** * List of all company employees */ @Inject @NamedCache (cacheName = "companyEmployeeCache") - private Cache companyEmployeeCache; + private Cache employeeCache; /** * A list of filtered employees @@ -65,9 +74,37 @@ public class JobsCompanyEmployeeWebRequestBean extends BaseJobsBean implements J /** * Default constructor */ - public JobsCompanyEmployeeWebRequestBean () { + public JobsEmployeeWebRequestBean () { // Call super constructor super(); + + // Init list + this.allEmployees = new LinkedList<>(); + } + + /** + * Observes events being fired when an employee has been added + *

+ * @param event Event being fired + */ + public void afterEmployeeAddedEvent (@Observes final ObservableEmployeeAddedEvent event) { + // Validate parameter + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getEmployee() == null) { + // Throw it again + throw new NullPointerException("event.employee is null"); //NOI18N + } else if (event.getEmployee().getEmployeeId() == null) { + // Throw it again + throw new NullPointerException("event.employee.employeeId is null"); //NOI18N + } else if (event.getEmployee().getEmployeeId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("event.employee.employeeId={0} is invalid", event.getEmployee().getEmployeeId())); //NOI18N + } + + // Add employee to cache and list + this.employeeCache.put(event.getEmployee().getEmployeeId(), event.getEmployee()); } /** @@ -77,23 +114,7 @@ public class JobsCompanyEmployeeWebRequestBean extends BaseJobsBean implements J */ @SuppressWarnings ("ReturnOfCollectionOrArrayField") public List allCompanyEmployees () { - // Init list - final List list = new LinkedList<>(); - - // Get iterator - final Iterator> iterator = this.companyEmployeeCache.iterator(); - - // Loop over all - while (iterator.hasNext()) { - // Get next entry - final Cache.Entry next = iterator.next(); - - // Add value to list - list.add(next.getValue()); - } - - // Return it - return list; + return this.allEmployees; } /** @@ -102,7 +123,7 @@ public class JobsCompanyEmployeeWebRequestBean extends BaseJobsBean implements J * @return Filtered list of employees */ @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getFilteredEmployees () { + public List getFilteredEmployees () { //NOI18N return this.filteredEmployees; } @@ -112,7 +133,7 @@ public class JobsCompanyEmployeeWebRequestBean extends BaseJobsBean implements J * @param filteredEmployees Filtered list of employees */ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") - public void setFilteredEmployees (final List filteredEmployees) { + public void setFilteredEmployees (final List filteredEmployees) { //NOI18N this.filteredEmployees = filteredEmployees; } @@ -122,9 +143,9 @@ public class JobsCompanyEmployeeWebRequestBean extends BaseJobsBean implements J @PostConstruct public void init () { // Is cache there? - if (!this.companyEmployeeCache.iterator().hasNext()) { + if (!this.employeeCache.iterator().hasNext()) { // Get whole list - final List list = this.companyEmployeeBean.allCompanyEmployees(); + final List list = this.employeeBean.allCompanyEmployees(); // Add all for (final Iterator iterator = list.iterator(); iterator.hasNext();) { @@ -132,9 +153,32 @@ public class JobsCompanyEmployeeWebRequestBean extends BaseJobsBean implements J final Employee next = iterator.next(); // Add it to cache - this.companyEmployeeCache.put(next.getEmployeeId(), next); + this.employeeCache.put(next.getEmployeeId(), next); } } + + // Is cache filled and list is empty + if ((this.employeeCache.iterator().hasNext()) && (this.allEmployees.isEmpty())) { + // Get iterator + final Iterator> iterator = this.employeeCache.iterator(); + + // Build up list + while (iterator.hasNext()) { + // GEt next element + final Cache.Entry next = iterator.next(); + + // Add to list + this.allEmployees.add(next.getValue()); + } + + // Sort list + this.allEmployees.sort(new Comparator() { + @Override + public int compare (final Employee o1, final Employee o2) { + return o1.getEmployeeId() > o2.getEmployeeId() ? 1 : o1.getEmployeeId() < o2.getEmployeeId() ? -1 : 0; + } + }); + } } } diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebSessionController.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebSessionController.java index 2a9d39b5..02ceaa8a 100644 --- a/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebSessionController.java @@ -23,6 +23,6 @@ import java.io.Serializable; *

* @author Roland Häder */ -public interface JobsCompanyEmployeeWebSessionController extends Serializable { +public interface JobsEmployeeWebRequestController extends Serializable { } diff --git a/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java b/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java index 876608a0..b334ecda 100644 --- a/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java +++ b/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java @@ -537,6 +537,14 @@ public class JobsWebRequestHelperBean extends BaseJobsBean implements JobsWebReq // Then create name sb.append(employee.getEmployeeNumber()); + // Is a department found? + if (employee.getEmployeeDepartment() instanceof Department) { + // Then add it's name to it + sb.append(" ("); //NOI18N + sb.append(this.renderDepartment(employee.getEmployeeDepartment())); + sb.append(")"); //NOI18N + } + // Is contact data found? if (employee.getEmployeePersonalData() instanceof Contact) { // Yes, then render it diff --git a/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsMobileProviderWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsMobileProviderWebRequestBean.java index 76ce49c9..8c796220 100644 --- a/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsMobileProviderWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsMobileProviderWebRequestBean.java @@ -176,8 +176,7 @@ public class JobsMobileProviderWebRequestBean extends BaseJobsBean implements Jo public int compare (final MobileProvider o1, final MobileProvider o2) { return o1.getProviderId() > o2.getProviderId() ? 1 : o1.getProviderId() < o2.getProviderId() ? -1 : 0; } - } - ); + }); } } } diff --git a/src/java/org/mxchange/jjobs/converter/business/company_employee/JobsCompanyEmployeeConverter.java b/src/java/org/mxchange/jjobs/converter/business/company_employee/JobsCompanyEmployeeConverter.java index fc87f3d8..10f02451 100644 --- a/src/java/org/mxchange/jjobs/converter/business/company_employee/JobsCompanyEmployeeConverter.java +++ b/src/java/org/mxchange/jjobs/converter/business/company_employee/JobsCompanyEmployeeConverter.java @@ -52,7 +52,7 @@ public class JobsCompanyEmployeeConverter implements Converter { final Context initial = new InitialContext(); // Lookup EJB - EMPLOYEE_BEAN = (CompanyEmployeeSessionBeanRemote) initial.lookup("java:global/jjobs-ejb/companyEmployee!org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote"); //NOI18N + EMPLOYEE_BEAN = (CompanyEmployeeSessionBeanRemote) initial.lookup("java:global/jjobs-ejb/employee!org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote"); //NOI18N } catch (final NamingException ex) { // Throw it again throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex); //NOI18N diff --git a/src/java/org/mxchange/jjobs/converter/business/headquarters/JobsCompanyHeadquartersConverter.java b/src/java/org/mxchange/jjobs/converter/business/headquarters/JobsCompanyHeadquartersConverter.java index aaf6755c..cd521dc5 100644 --- a/src/java/org/mxchange/jjobs/converter/business/headquarters/JobsCompanyHeadquartersConverter.java +++ b/src/java/org/mxchange/jjobs/converter/business/headquarters/JobsCompanyHeadquartersConverter.java @@ -52,7 +52,7 @@ public class JobsCompanyHeadquartersConverter implements Converter - + @@ -70,7 +70,7 @@ > - + diff --git a/web/WEB-INF/templates/admin/branch_office/admin_form_branch_office_data.tpl b/web/WEB-INF/templates/admin/branch_office/admin_form_branch_office_data.tpl index 778e60a7..7e2c72b7 100644 --- a/web/WEB-INF/templates/admin/branch_office/admin_form_branch_office_data.tpl +++ b/web/WEB-INF/templates/admin/branch_office/admin_form_branch_office_data.tpl @@ -35,7 +35,7 @@ > - + diff --git a/web/WEB-INF/templates/admin/department/admin_form_department_data.tpl b/web/WEB-INF/templates/admin/department/admin_form_department_data.tpl index fb18bf89..838c2a91 100644 --- a/web/WEB-INF/templates/admin/department/admin_form_department_data.tpl +++ b/web/WEB-INF/templates/admin/department/admin_form_department_data.tpl @@ -62,7 +62,7 @@ > - + diff --git a/web/WEB-INF/templates/admin/employee/admin_form_employee_data.tpl b/web/WEB-INF/templates/admin/employee/admin_form_employee_data.tpl index 2ebc4023..8a2bf917 100644 --- a/web/WEB-INF/templates/admin/employee/admin_form_employee_data.tpl +++ b/web/WEB-INF/templates/admin/employee/admin_form_employee_data.tpl @@ -15,7 +15,7 @@ @@ -41,7 +41,7 @@ @@ -53,7 +53,7 @@ @@ -63,13 +63,13 @@ - + - + @@ -79,12 +79,12 @@ - + @@ -96,7 +96,7 @@ @@ -106,7 +106,7 @@ - + diff --git a/web/admin/basic_company_data/admin_basic_company_data_list.xhtml b/web/admin/basic_company_data/admin_basic_company_data_list.xhtml index e3059b2c..0fb9c237 100644 --- a/web/admin/basic_company_data/admin_basic_company_data_list.xhtml +++ b/web/admin/basic_company_data/admin_basic_company_data_list.xhtml @@ -98,7 +98,7 @@ > - + @@ -123,7 +123,7 @@ > - + diff --git a/web/admin/branch_office/admin_branch_office_list.xhtml b/web/admin/branch_office/admin_branch_office_list.xhtml index 1b0fca22..26bd0c68 100644 --- a/web/admin/branch_office/admin_branch_office_list.xhtml +++ b/web/admin/branch_office/admin_branch_office_list.xhtml @@ -122,7 +122,7 @@ > - + diff --git a/web/admin/department/admin_department_list.xhtml b/web/admin/department/admin_department_list.xhtml index dfe8a967..d131c45b 100644 --- a/web/admin/department/admin_department_list.xhtml +++ b/web/admin/department/admin_department_list.xhtml @@ -57,7 +57,7 @@ - + @@ -99,7 +99,7 @@ - + @@ -116,7 +116,7 @@ > - + diff --git a/web/admin/employee/admin_employee_list.xhtml b/web/admin/employee/admin_employee_list.xhtml index bd6be330..3ac1c784 100644 --- a/web/admin/employee/admin_employee_list.xhtml +++ b/web/admin/employee/admin_employee_list.xhtml @@ -21,11 +21,11 @@ -- 2.39.5