]> git.mxchange.org Git - jfinancials-war.git/blob
203c17c1e68ddefa11150d317fb0cf15c37f5bbe
[jfinancials-war.git] /
1 /*
2  * Copyright (C) 2017, 2018 Free Software Foundation
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.jfinancials.beans.business.opening_time;
18
19 import java.util.Date;
20 import javax.ejb.EJB;
21 import javax.enterprise.context.RequestScoped;
22 import javax.enterprise.event.Event;
23 import javax.enterprise.inject.Any;
24 import javax.inject.Inject;
25 import javax.inject.Named;
26 import org.mxchange.jcontactsbusiness.events.opening_time.added.ObservableOpeningTimeAddedEvent;
27 import org.mxchange.jcontactsbusiness.events.opening_time.added.OpeningTimeAddedEvent;
28 import org.mxchange.jcontactsbusiness.model.opening_time.AdminOpeningTimeSessionBeanRemote;
29 import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime;
30 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
31 import org.mxchange.jcontactsbusiness.model.opening_time.dayofweek.DayOfTheWeek;
32 import org.mxchange.jfinancials.beans.BaseFinancialsBean;
33
34 /**
35  * An administrative bean for openingTimes
36  * <p>
37  * @author Roland Häder<roland@mxchange.org>
38  */
39 @Named ("adminOpeningTimeController")
40 @RequestScoped
41 public class FinancialsAdminOpeningTimeWebRequestBean extends BaseFinancialsBean implements FinancialsAdminOpeningTimeWebRequestController {
42
43         /**
44          * Serial number
45          */
46         private static final long serialVersionUID = 5_028_697_360_463L;
47
48         /**
49          * EJB for administrative purposes
50          */
51         @EJB (lookup = "java:global/jfinancials-ejb/adminOpeningTimes!org.mxchange.jcontactsbusiness.model.opening_time.AdminOpeningTimeSessionBeanRemote")
52         private AdminOpeningTimeSessionBeanRemote adminOpeningTimeBean;
53
54         /**
55          * Ending week day
56          */
57         private DayOfTheWeek openingEndDay;
58
59         /**
60          * Ending time
61          */
62         private Date openingEndTime;
63
64         /**
65          * Starting week day
66          */
67         private DayOfTheWeek openingStartDay;
68
69         /**
70          * Starting time
71          */
72         private Date openingStartTime;
73
74         /**
75          * An event being fired when a openingTime has been successfully added
76          */
77         @Inject
78         @Any
79         private Event<ObservableOpeningTimeAddedEvent> openingTimeAddedEvent;
80
81         /**
82          * Default constructor
83          */
84         public FinancialsAdminOpeningTimeWebRequestBean () {
85                 // Call super constructor
86                 super();
87         }
88
89         /**
90          * Adds openingTime with all data from this backing bean. First this action
91          * method will validate if the openingTime's address is already registered
92          * and if found, it will output a proper faces message.
93          * <p>
94          * @return Redirect outcome
95          */
96         public String addOpeningTimes () {
97                 // Get instance
98                 final OpeningTime openingTime = this.createOpeningTimes();
99
100                 // Call EJB and return updated instance
101                 final OpeningTime updatedOpeningTimes = this.adminOpeningTimeBean.addOpeningTime(openingTime);
102
103                 // Fire event
104                 this.openingTimeAddedEvent.fire(new OpeningTimeAddedEvent(updatedOpeningTimes));
105
106                 // Redirect to list
107                 return "admin_list_opening_time"; //NOI18N
108         }
109
110         /**
111          * Getter for ending week day
112          * <p>
113          * @return Ending week day
114          */
115         public DayOfTheWeek getOpeningEndDay () {
116                 return this.openingEndDay;
117         }
118
119         /**
120          * Setter for ending week day
121          * <p>
122          * @param openingEndDay Ending week day
123          */
124         public void setOpeningEndDay (final DayOfTheWeek openingEndDay) {
125                 this.openingEndDay = openingEndDay;
126         }
127
128         /**
129          * Getter for ending time
130          * <p>
131          * @return Ending time
132          */
133         @SuppressWarnings ("ReturnOfDateField")
134         public Date getOpeningEndTime () {
135                 return this.openingEndTime;
136         }
137
138         /**
139          * Getter for ending time
140          * <p>
141          * @param openingEndTime Ending time
142          */
143         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
144         public void setOpeningEndTime (final Date openingEndTime) {
145                 this.openingEndTime = openingEndTime;
146         }
147
148         /**
149          * Getter for starting week day
150          * <p>
151          * @return Starting week day
152          */
153         public DayOfTheWeek getOpeningStartDay () {
154                 return this.openingStartDay;
155         }
156
157         /**
158          * Getter for starting week day
159          * <p>
160          * @param openingStartDay Starting week day
161          */
162         public void setOpeningStartDay (final DayOfTheWeek openingStartDay) {
163                 this.openingStartDay = openingStartDay;
164         }
165
166         /**
167          * Getter for starting time
168          * <p>
169          * @return Starting time
170          */
171         @SuppressWarnings ("ReturnOfDateField")
172         public Date getOpeningStartTime () {
173                 return this.openingStartTime;
174         }
175
176         /**
177          * Getter for starting time
178          * <p>
179          * @param openingStartTime Starting time
180          */
181         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
182         public void setOpeningStartTime (final Date openingStartTime) {
183                 this.openingStartTime = openingStartTime;
184         }
185
186         /**
187          * Prepares an instance of a OpeningTimes object (entity) with all data from
188          * this bean. If a complete fax number or land-line number was provided, it
189          * will be set in the instance as well.
190          * <p>
191          * @return An instance of a OpeningTimes class (entity)
192          */
193         private OpeningTime createOpeningTimes () {
194                 // Create new openingTime instance
195                 final OpeningTime openingTime = new BusinessOpeningTime(this.getOpeningEndDay(), this.getOpeningEndTime(), this.getOpeningStartDay(), this.getOpeningStartTime());
196
197                 // Return fully prepared instance
198                 return openingTime;
199         }
200
201 }