2 * Copyright (C) 2017 RRoland Häder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jfinancials.beans.business.employee;
19 import fish.payara.cdi.jsr107.impl.NamedCache;
20 import java.util.Iterator;
21 import java.util.LinkedList;
22 import java.util.List;
23 import javax.annotation.PostConstruct;
24 import javax.cache.Cache;
26 import javax.enterprise.context.RequestScoped;
27 import javax.inject.Inject;
28 import javax.inject.Named;
29 import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote;
30 import org.mxchange.jcontactsbusiness.model.employee.Employee;
31 import org.mxchange.jfinancials.beans.BaseFinancialsBean;
34 * A request-scoped bean for general purposes for company employees.
36 * @author Roland Häder<roland@mxchange.org>
38 @Named ("companyEmployeeController")
40 public class FinancialsCompanyEmployeeWebRequestBean extends BaseFinancialsBean implements FinancialsCompanyEmployeeWebRequestController {
45 private static final long serialVersionUID = 12_886_968_547_361L;
48 * EJB for general company employee purposes
50 @EJB (lookup = "java:global/jfinancials-ejb/companyEmployee!org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote")
51 private CompanyEmployeeSessionBeanRemote companyEmployeeBean;
54 * List of all company employees
57 @NamedCache (cacheName = "companyEmployeeCache")
58 private Cache<Long, Employee> companyEmployeeCache;
61 * A list of filtered employees
63 private List<Employee> filteredEmployees;
68 public FinancialsCompanyEmployeeWebRequestBean () {
69 // Call super constructor
74 * Returns a list of all company employees
76 * @return List of all company employees
78 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
79 public List<Employee> allCompanyEmployees () {
81 final List<Employee> list = new LinkedList<>();
84 final Iterator<Cache.Entry<Long, Employee>> iterator = this.companyEmployeeCache.iterator();
87 while (iterator.hasNext()) {
89 final Cache.Entry<Long, Employee> next = iterator.next();
92 list.add(next.getValue());
100 * Getter for filtered list of employees
102 * @return Filtered list of employees
104 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
105 public List<Employee> getFilteredEmployees () {
106 return this.filteredEmployees;
110 * Getter for filtered list of employees
112 * @param filteredEmployees Filtered list of employees
114 @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
115 public void setFilteredEmployees (final List<Employee> filteredEmployees) {
116 this.filteredEmployees = filteredEmployees;
120 * Initialization method
123 public void init () {
125 if (!this.companyEmployeeCache.iterator().hasNext()) {
127 final List<Employee> list = this.companyEmployeeBean.allCompanyEmployees();
130 for (final Iterator<Employee> iterator = list.iterator(); iterator.hasNext();) {
132 final Employee next = iterator.next();
135 this.companyEmployeeCache.put(next.getEmployeeId(), next);