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.jfinancials.beans.business.opening_time;
19 import java.util.Date;
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;
35 * An administrative bean for openingTimes
37 * @author Roland Häder<roland@mxchange.org>
39 @Named ("adminOpeningTimeController")
41 public class FinancialsAdminOpeningTimeWebRequestBean extends BaseFinancialsBean implements FinancialsAdminOpeningTimeWebRequestController {
46 private static final long serialVersionUID = 5_028_697_360_463L;
49 * EJB for administrative purposes
51 @EJB (lookup = "java:global/jfinancials-ejb/adminOpeningTimes!org.mxchange.jcontactsbusiness.model.opening_time.AdminOpeningTimeSessionBeanRemote")
52 private AdminOpeningTimeSessionBeanRemote adminOpeningTimeBean;
57 private DayOfTheWeek openingEndDay;
62 private Date openingEndTime;
67 private DayOfTheWeek openingStartDay;
72 private Date openingStartTime;
75 * An event being fired when a openingTime has been successfully added
79 private Event<ObservableOpeningTimeAddedEvent> openingTimeAddedEvent;
84 public FinancialsAdminOpeningTimeWebRequestBean () {
85 // Call super constructor
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.
94 * @return Redirect outcome
96 public String addOpeningTimes () {
98 final OpeningTime openingTime = this.createOpeningTimes();
100 // Call EJB and return updated instance
101 final OpeningTime updatedOpeningTimes = this.adminOpeningTimeBean.addOpeningTime(openingTime);
104 this.openingTimeAddedEvent.fire(new OpeningTimeAddedEvent(updatedOpeningTimes));
107 return "admin_list_opening_time"; //NOI18N
111 * Getter for ending week day
113 * @return Ending week day
115 public DayOfTheWeek getOpeningEndDay () {
116 return this.openingEndDay;
120 * Setter for ending week day
122 * @param openingEndDay Ending week day
124 public void setOpeningEndDay (final DayOfTheWeek openingEndDay) {
125 this.openingEndDay = openingEndDay;
129 * Getter for ending time
131 * @return Ending time
133 @SuppressWarnings ("ReturnOfDateField")
134 public Date getOpeningEndTime () {
135 return this.openingEndTime;
139 * Getter for ending time
141 * @param openingEndTime Ending time
143 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
144 public void setOpeningEndTime (final Date openingEndTime) {
145 this.openingEndTime = openingEndTime;
149 * Getter for starting week day
151 * @return Starting week day
153 public DayOfTheWeek getOpeningStartDay () {
154 return this.openingStartDay;
158 * Getter for starting week day
160 * @param openingStartDay Starting week day
162 public void setOpeningStartDay (final DayOfTheWeek openingStartDay) {
163 this.openingStartDay = openingStartDay;
167 * Getter for starting time
169 * @return Starting time
171 @SuppressWarnings ("ReturnOfDateField")
172 public Date getOpeningStartTime () {
173 return this.openingStartTime;
177 * Getter for starting time
179 * @param openingStartTime Starting time
181 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
182 public void setOpeningStartTime (final Date openingStartTime) {
183 this.openingStartTime = openingStartTime;
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.
191 * @return An instance of a OpeningTimes class (entity)
193 private OpeningTime createOpeningTimes () {
194 // Create new openingTime instance
195 final OpeningTime openingTime = new BusinessOpeningTime(this.getOpeningEndDay(), this.getOpeningEndTime(), this.getOpeningStartDay(), this.getOpeningStartTime());
197 // Return fully prepared instance