2 * Copyright (C) 2017 Roland 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.branchoffice;
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.branchoffice.BranchOffice;
30 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote;
31 import org.mxchange.pizzaapplication.beans.BasePizzaController;
34 * A general bean for branch offices
36 * @author Roland Häder<roland@mxchange.org>
38 @Named ("branchOfficeController")
40 public class PizzaBranchOfficeWebRequestBean extends BasePizzaController implements PizzaBranchOfficeWebRequestController {
45 private static final long serialVersionUID = 5_028_697_360_461L;
48 * EJB for administrative purposes
50 @EJB (lookup = "java:global/jfinancials-ejb/branchOffice!org.mxchange.jcontactsbusiness.branchoffice.BranchOfficeSessionBeanRemote")
51 private BranchOfficeSessionBeanRemote branchOfficeBean;
54 * A list of all branch offices (globally)
57 @NamedCache (cacheName = "branchOfficeCache")
58 private Cache<Long, BranchOffice> branchOfficeCache;
63 public PizzaBranchOfficeWebRequestBean () {
64 // Call super constructor
69 * Returns a list of all branch offices
71 * @return A list of all branch offices
73 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
74 public List<BranchOffice> allBranchOffices () {
76 final List<BranchOffice> list = new LinkedList<>();
79 final Iterator<Cache.Entry<Long, BranchOffice>> iterator = this.branchOfficeCache.iterator();
82 while (iterator.hasNext()) {
84 final Cache.Entry<Long, BranchOffice> next = iterator.next();
87 list.add(next.getValue());
98 public void initializeList () {
100 if (!this.branchOfficeCache.iterator().hasNext()) {
102 final List<BranchOffice> list = this.branchOfficeBean.allBranchOffices();
105 for (final Iterator<BranchOffice> iterator = list.iterator(); iterator.hasNext();) {
107 final BranchOffice next = iterator.next();
110 this.branchOfficeCache.put(next.getBranchId(), next);