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.pizzaapplication.beans.business.employee;
19 import java.util.Iterator;
20 import java.util.LinkedList;
21 import java.util.List;
22 import javax.annotation.PostConstruct;
23 import javax.cache.Cache;
25 import javax.enterprise.context.RequestScoped;
26 import javax.inject.Inject;
27 import javax.inject.Named;
28 import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote;
29 import org.mxchange.jcontactsbusiness.model.employee.Employee;
30 import org.mxchange.pizzaapplication.beans.BasePizzaController;
33 * A request-scoped bean for general purposes for company employees.
35 * @author Roland Häder<roland@mxchange.org>
37 @Named ("companyEmployeeController")
39 public class PizzaCompanyEmployeeWebRequestBean extends BasePizzaController implements PizzaCompanyEmployeeWebRequestController {
44 private static final long serialVersionUID = 12_886_968_547_361L;
47 * EJB for general company employee purposes
49 @EJB (lookup = "java:global/pizzaservice-ejb/companyEmployee!org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote")
50 private CompanyEmployeeSessionBeanRemote companyEmployeeBean;
53 * List of all company employees
56 @Cached(cacheName = "companyEmployeeCache")
57 private transient Cache<Long, Employee> companyEmployeeCache;
62 public PizzaCompanyEmployeeWebRequestBean () {
63 // Call super constructor
68 * Returns a list of all company employees
70 * @return List of all company employees
72 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
73 public List<Employee> allCompanyEmployees () {
75 List<Employee> list = new LinkedList<>();
78 Iterator<Cache.Entry<Long, Employee>> iterator = this.companyEmployeeCache.iterator();
81 while (iterator.hasNext()) {
83 final Cache.Entry<Long, Employee> next = iterator.next();
86 list.add(next.getValue());
94 * Initialization method
99 if (!this.companyEmployeeCache.iterator().hasNext()) {
101 List<Employee> list = this.companyEmployeeBean.allCompanyEmployees();
104 for (final Iterator<Employee> iterator = list.iterator(); iterator.hasNext();) {
106 final Employee next = iterator.next();
109 this.companyEmployeeCache.put(next.getEmployeeId(), next);