*/
package org.mxchange.jjobs.beans.business.branchoffice;
+import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
+import java.util.Objects;
import javax.ejb.EJB;
-import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Event;
import javax.enterprise.inject.Any;
import javax.inject.Inject;
import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices;
import org.mxchange.jcontactsbusiness.model.branchoffice.CompanyBranchOffice;
import org.mxchange.jcontactsbusiness.model.employee.Employee;
+import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime;
+import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
+import org.mxchange.jcontactsbusiness.model.opening_time.dayofweek.DayOfTheWeek;
import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jjobs.beans.BaseJobsBean;
import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
* @author Roland Häder<roland@mxchange.org>
*/
@Named ("adminBranchOfficeController")
-@RequestScoped
+@SessionScoped
public class JobsAdminBranchOfficeWebRequestBean extends BaseJobsBean implements JobsAdminBranchOfficeWebRequestController {
/**
@Inject
private JobsBranchOfficeWebRequestController branchOfficeController;
+ /**
+ * Opening times of this branch office
+ */
+ private static List<OpeningTime> branchOpeningTimes;
+
/**
* Store
*/
*/
private Long landLineNumber;
+ /**
+ * Ending week day
+ */
+ private DayOfTheWeek openingEndDay;
+
+ /**
+ * Ending time
+ */
+ private Date openingEndTime;
+
+ /**
+ * Starting week day
+ */
+ private DayOfTheWeek openingStartDay;
+
+ /**
+ * Starting time
+ */
+ private Date openingStartTime;
+
/**
* Default constructor
*/
public JobsAdminBranchOfficeWebRequestBean () {
// Call super constructor
super();
+
+ // Is the opening times list there?
+ if (null == branchOpeningTimes) {
+ // Init list
+ branchOpeningTimes = new ArrayList<>(1);
+ }
}
/**
// Fire event
this.branchOfficeAddedEvent.fire(new BranchOfficeAddedEvent(updatedOffice));
+ // Clear this bean
+ this.clear();
+
// Redirect to list
return "admin_list_branch_office"; //NOI18N
}
+ /**
+ * Adds opening time to temporary list which will be sent along with the
+ * branch office data to the EJB.
+ */
+ public void addOpeningTime () {
+ // Validate all required fields
+ if (this.getOpeningEndDay() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.openingEndDay is null"); //NOI18N
+ } else if (this.getOpeningEndTime() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.openingEndTime is null"); //NOI18N
+ } else if (this.getOpeningStartDay() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.openingStartDay is null"); //NOI18N
+ } else if (this.getOpeningStartTime() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.openingStartTime is null"); //NOI18N
+ }
+
+ // Get opening time instance
+ final OpeningTime openingTime = this.createOpeningTimes();
+
+ // Is same found?
+ if (this.isSameOpeningTimeFound(openingTime)) {
+ // Yes then abort here
+ this.showFacesMessage("form-admin-add-branch-opening-time:openingStartDay", "ADMIN_OPENING_TIME_ALREADY_CREATED"); //NOI18N
+ return;
+ }
+
+ // Add to temporary list
+ branchOpeningTimes.add(openingTime);
+
+ // Clear opening time fields
+ this.clearOpeningTime();
+ }
+
/**
* Getter for city
* <p>
this.branchNumber = branchNumber;
}
+ /**
+ * Getter for opening times of this branch office
+ * <p>
+ * @return Opening times
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<OpeningTime> getBranchOpeningTimes () {
+ return branchOpeningTimes;
+ }
+
+ /**
+ * Setter for opening times of this branch office
+ * <p>
+ * @param branchOpeningTimes Opening times
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setBranchOpeningTimes (final List<OpeningTime> branchOpeningTimes) {
+ FinancialsAdminBranchOfficeWebRequestBean.branchOpeningTimes = branchOpeningTimes;
+ }
+
/**
* Getter for store
* <p>
this.landLineNumber = landLineNumber;
}
+ /**
+ * Getter for ending week day
+ * <p>
+ * @return Ending week day
+ */
+ public DayOfTheWeek getOpeningEndDay () {
+ return this.openingEndDay;
+ }
+
+ /**
+ * Setter for ending week day
+ * <p>
+ * @param openingEndDay Ending week day
+ */
+ public void setOpeningEndDay (final DayOfTheWeek openingEndDay) {
+ this.openingEndDay = openingEndDay;
+ }
+
+ /**
+ * Getter for ending time
+ * <p>
+ * @return Ending time
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getOpeningEndTime () {
+ return this.openingEndTime;
+ }
+
+ /**
+ * Getter for ending time
+ * <p>
+ * @param openingEndTime Ending time
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setOpeningEndTime (final Date openingEndTime) {
+ this.openingEndTime = openingEndTime;
+ }
+
+ /**
+ * Getter for starting week day
+ * <p>
+ * @return Starting week day
+ */
+ public DayOfTheWeek getOpeningStartDay () {
+ return this.openingStartDay;
+ }
+
+ /**
+ * Getter for starting week day
+ * <p>
+ * @param openingStartDay Starting week day
+ */
+ public void setOpeningStartDay (final DayOfTheWeek openingStartDay) {
+ this.openingStartDay = openingStartDay;
+ }
+
+ /**
+ * Getter for starting time
+ * <p>
+ * @return Starting time
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getOpeningStartTime () {
+ return this.openingStartTime;
+ }
+
+ /**
+ * Getter for starting time
+ * <p>
+ * @param openingStartTime Starting time
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setOpeningStartTime (final Date openingStartTime) {
+ this.openingStartTime = openingStartTime;
+ }
+
+ /**
+ * Clears this bean data
+ */
+ private void clear () {
+ // Clear all branch office data
+ this.setBranchCity(null);
+ this.setBranchCompany(null);
+ this.setBranchContactEmployee(null);
+ this.setBranchCountry(null);
+ this.setBranchEmailAddress(null);
+ this.setBranchHouseNumber(null);
+ this.setBranchNumber(null);
+ this.setBranchStore(null);
+ this.setBranchStreet(null);
+ this.setBranchSuiteNumber(null);
+ this.setBranchUserOwner(null);
+ this.setBranchZipCode(null);
+ this.setBranchOpeningTimes(null);
+
+ // Extra-clear opening time
+ this.clearOpeningTime();
+ }
+
+ /**
+ * Clears all opening time fields
+ */
+ private void clearOpeningTime () {
+ // Clear all opening time fields
+ this.setOpeningEndDay(null);
+ this.setOpeningEndTime(null);
+ this.setOpeningStartDay(null);
+ this.setOpeningStartTime(null);
+ }
+
/**
* Prepares an instance of a BranchOffice object (entity) with all data from
* this bean. If a complete fax number or land-line number was provided, it
// Set fax number
branchOffice.setBranchFaxNumber(fax);
}
+ // Is the opening times list filled?
+ if (!this.getBranchOpeningTimes().isEmpty()) {
+ // Yes, then set in branch office, too
+ branchOffice.setBranchOpeningTimes(this.getBranchOpeningTimes());
+ }
// Return fully prepared instance
return branchOffice;
}
+ /**
+ * Prepares an instance of a OpeningTimes object (entity) with all data from
+ * this bean. If a complete fax number or land-line number was provided, it
+ * will be set in the instance as well.
+ * <p>
+ * @return An instance of a OpeningTimes class (entity)
+ */
+ private OpeningTime createOpeningTimes () {
+ // Create new openingTime instance
+ final OpeningTime openingTime = new BusinessOpeningTime(this.getOpeningEndDay(), this.getOpeningEndTime(), this.getOpeningStartDay(), this.getOpeningStartTime());
+
+ // Return fully prepared instance
+ return openingTime;
+ }
+
/**
* Checks whether the given branch office's address is already found in
* local cache. Please note that this method fully relies on the cache, so
return isFound;
}
+ /**
+ * Checks if given opening time is already added
+ * <p>
+ * @param openingTime Opening time to be checked
+ * <p>
+ * @return Whether it has been added already
+ */
+ private boolean isSameOpeningTimeFound (final OpeningTime openingTime) {
+ // Default is not found
+ boolean isFound = false;
+
+ // Loop through list
+ for (final OpeningTime ot : this.getBranchOpeningTimes()) {
+ // Check it
+ if (Objects.equals(ot, openingTime)) {
+ // Found same match
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return it
+ return isFound;
+ }
+
}