]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/de/chotime/jratecalc/beans/customer/RateCalcAdminCustomerWebRequestBean.java
fixed JNDI name
[pizzaservice-war.git] / src / java / de / chotime / jratecalc / beans / customer / RateCalcAdminCustomerWebRequestBean.java
1 /*
2  * Copyright (C) 2016 Cho-Time GmbH
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package de.chotime.jratecalc.beans.customer;
18
19 import de.chotime.jratecalc.model.customer.RateCalcAdminCustomerSessionBeanRemote;
20 import java.util.Collections;
21 import java.util.List;
22 import javax.annotation.PostConstruct;
23 import javax.enterprise.context.RequestScoped;
24 import javax.faces.view.facelets.FaceletException;
25 import javax.inject.Named;
26 import javax.naming.Context;
27 import javax.naming.InitialContext;
28 import javax.naming.NamingException;
29 import org.mxchange.jcustomercore.model.customer.Customer;
30
31 /**
32  * Administrative customer bean (controller)
33  * <p>
34  * @author Roland Haeder<rhaeder@cho-time.de>
35  */
36 @Named ("adminCustomerController")
37 @RequestScoped
38 public class RateCalcAdminCustomerWebRequestBean implements RateCalcAdminCustomerWebRequestController {
39
40         /**
41          * Serial number
42          */
43         private static final long serialVersionUID = 12_487_062_487_527_913L;
44
45         /**
46          * Administrative customer EJB
47          */
48         private RateCalcAdminCustomerSessionBeanRemote adminCustomerBean;
49
50         /**
51          * A list of all customers
52          */
53         private List<Customer> customerList;
54
55         /**
56          * Default constructor
57          */
58         public RateCalcAdminCustomerWebRequestBean () {
59                 // Try it
60                 try {
61                         // Get initial context
62                         Context context = new InitialContext();
63
64                         // Try to lookup
65                         this.adminCustomerBean = (RateCalcAdminCustomerSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/admincustomer!de.chotime.jratecalc.model.customer.RateCalcAdminCustomerSessionBeanRemote"); //NOI18N
66                 } catch (final NamingException e) {
67                         // Throw again
68                         throw new FaceletException(e);
69                 }
70         }
71
72         @Override
73         public List<Customer> allCustomers () {
74                 // Return it
75                 return Collections.unmodifiableList(this.customerList);
76         }
77
78         @Override
79         public boolean hasCustomers () {
80                 return (!this.allCustomers().isEmpty());
81         }
82
83         /**
84          * Post-initialization of this class
85          */
86         @PostConstruct
87         public void init () {
88                 // Initialize customer list
89                 this.customerList = this.adminCustomerBean.allCustomers();
90         }
91
92 }