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.addressbook.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.addressbook.beans.BaseAddressbookBean;
30 import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote;
31 import org.mxchange.jcontactsbusiness.model.employee.Employee;
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 AddressbookCompanyEmployeeWebRequestBean extends BaseAddressbookBean implements AddressbookCompanyEmployeeWebRequestController {
45 private static final long serialVersionUID = 12_886_968_547_361L;
48 * EJB for general company employee purposes
50 @EJB (lookup = "java:global/addressbook-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;
63 public AddressbookCompanyEmployeeWebRequestBean () {
64 // Call super constructor
69 * Returns a list of all company employees
71 * @return List of all company employees
73 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
74 public List<Employee> allCompanyEmployees () {
76 final List<Employee> list = new LinkedList<>();
79 final Iterator<Cache.Entry<Long, Employee>> iterator = this.companyEmployeeCache.iterator();
82 while (iterator.hasNext()) {
84 final Cache.Entry<Long, Employee> next = iterator.next();
87 list.add(next.getValue());
95 * Initialization method
100 if (!this.companyEmployeeCache.iterator().hasNext()) {
102 final List<Employee> list = this.companyEmployeeBean.allCompanyEmployees();
105 for (final Iterator<Employee> iterator = list.iterator(); iterator.hasNext();) {
107 final Employee next = iterator.next();
110 this.companyEmployeeCache.put(next.getEmployeeId(), next);