]> git.mxchange.org Git - pizzaservice-war.git/blob
bf17316dc3ea422e15e6d1168ae5df46e6bfbc73
[pizzaservice-war.git] /
1 /*
2  * Copyright (C) 2017 RRoland Häder
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 org.mxchange.pizzaapplication.beans.business.employee;
18
19 import java.util.LinkedList;
20 import java.util.List;
21 import javax.annotation.PostConstruct;
22 import javax.enterprise.context.SessionScoped;
23 import javax.faces.view.facelets.FaceletException;
24 import javax.inject.Named;
25 import javax.naming.Context;
26 import javax.naming.InitialContext;
27 import javax.naming.NamingException;
28 import org.mxchange.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote;
29 import org.mxchange.jcontactsbusiness.employee.Employee;
30 import org.mxchange.pizzaapplication.beans.BasePizzaController;
31
32 /**
33  * A request-scoped bean for general purposes for company employees.
34  * <p>
35  * @author Roland Häder<roland@mxchange.org>
36  */
37 @Named ("companyEmployeeController")
38 @SessionScoped
39 public class PizzaCompanyEmployeeWebRequestBean extends BasePizzaController implements PizzaCompanyEmployeeWebSessionController {
40
41         /**
42          * Serial number
43          */
44         private static final long serialVersionUID = 12_886_968_547_361L;
45
46         /**
47          * EJB for general company employee purposes
48          */
49         private CompanyEmployeeSessionBeanRemote companyEmployeeBean;
50
51         /**
52          * List of all company employees
53          */
54         private final List<Employee> companyEmployees;
55
56         /**
57          * Default constructor
58          */
59         public PizzaCompanyEmployeeWebRequestBean () {
60                 // Call super constructor
61                 super();
62
63                 // Init list instance
64                 this.companyEmployees = new LinkedList<>();
65         }
66
67         /**
68          * Returns a list of all company employees
69          * <p>
70          * @return List of all company employees
71          */
72         @SuppressWarnings ("ReturnOfCollectionOrArrayField")
73         public List<Employee> allCompanyEmployees () {
74                 return this.companyEmployees;
75         }
76
77         /**
78          * Initialization method
79          */
80         @PostConstruct
81         public void init () {
82                 // Try it
83                 try {
84                         // Get initial context
85                         Context context = new InitialContext();
86
87                         // Try to lookup
88                         this.companyEmployeeBean = (CompanyEmployeeSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/companyEmployee!org.mxchange.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote"); //NOI18N
89                 } catch (final NamingException e) {
90                         // Throw again
91                         throw new FaceletException(e);
92                 }
93
94                 // Get all entries from remote bean
95                 List<Employee> employees = this.companyEmployeeBean.allCompanyEmployees();
96
97                 // Copy it to main list
98                 this.companyEmployees.addAll(employees);
99         }
100
101 }