]> git.mxchange.org Git - jfinancials-war.git/blob
bbdc934c5c4a543ae07f8869bdbbb30fdb4a63b8
[jfinancials-war.git] /
1 /*
2  * Copyright (C) 2017 - 2020 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          */
94         public void addOpeningTime () {
95                 // Get instance
96                 final OpeningTime openingTime = this.createOpeningTimes();
97
98                 // Call EJB and return updated instance
99                 final OpeningTime updatedOpeningTimes = this.adminOpeningTimeBean.addOpeningTime(openingTime);
100
101                 // Fire event
102                 this.openingTimeAddedEvent.fire(new OpeningTimeAddedEvent(updatedOpeningTimes));
103         }
104
105         /**
106          * Getter for ending week day
107          * <p>
108          * @return Ending week day
109          */
110         public DayOfTheWeek getOpeningEndDay () {
111                 return this.openingEndDay;
112         }
113
114         /**
115          * Setter for ending week day
116          * <p>
117          * @param openingEndDay Ending week day
118          */
119         public void setOpeningEndDay (final DayOfTheWeek openingEndDay) {
120                 this.openingEndDay = openingEndDay;
121         }
122
123         /**
124          * Getter for ending time
125          * <p>
126          * @return Ending time
127          */
128         @SuppressWarnings ("ReturnOfDateField")
129         public Date getOpeningEndTime () {
130                 return this.openingEndTime;
131         }
132
133         /**
134          * Getter for ending time
135          * <p>
136          * @param openingEndTime Ending time
137          */
138         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
139         public void setOpeningEndTime (final Date openingEndTime) {
140                 this.openingEndTime = openingEndTime;
141         }
142
143         /**
144          * Getter for starting week day
145          * <p>
146          * @return Starting week day
147          */
148         public DayOfTheWeek getOpeningStartDay () {
149                 return this.openingStartDay;
150         }
151
152         /**
153          * Getter for starting week day
154          * <p>
155          * @param openingStartDay Starting week day
156          */
157         public void setOpeningStartDay (final DayOfTheWeek openingStartDay) {
158                 this.openingStartDay = openingStartDay;
159         }
160
161         /**
162          * Getter for starting time
163          * <p>
164          * @return Starting time
165          */
166         @SuppressWarnings ("ReturnOfDateField")
167         public Date getOpeningStartTime () {
168                 return this.openingStartTime;
169         }
170
171         /**
172          * Getter for starting time
173          * <p>
174          * @param openingStartTime Starting time
175          */
176         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
177         public void setOpeningStartTime (final Date openingStartTime) {
178                 this.openingStartTime = openingStartTime;
179         }
180
181         /**
182          * Prepares an instance of a OpeningTimes object (entity) with all data from
183          * this bean. If a complete fax number or land-line number was provided, it
184          * will be set in the instance as well.
185          * <p>
186          * @return An instance of a OpeningTimes class (entity)
187          */
188         private OpeningTime createOpeningTimes () {
189                 // Create new openingTime instance
190                 final OpeningTime openingTime = new BusinessOpeningTime(this.getOpeningEndDay(), this.getOpeningEndTime(), this.getOpeningStartDay(), this.getOpeningStartTime());
191
192                 // Return fully prepared instance
193                 return openingTime;
194         }
195
196 }