X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fjjobs%2Fbeans%2Fbusiness%2Fbranchoffice%2FJobsAdminBranchOfficeWebRequestBean.java;h=be6b6734e676f9bb70fd22b184e18618c55b55d4;hb=0a610c77a15ac473b1cfcd2bb51d1ec425e2d9a1;hp=2e5aa9399b5babc30342345266506eda09f95c8a;hpb=020b01201cdad7d309a510edbd08ab2912a7bb42;p=jjobs-war.git diff --git a/src/java/org/mxchange/jjobs/beans/business/branchoffice/JobsAdminBranchOfficeWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/business/branchoffice/JobsAdminBranchOfficeWebRequestBean.java index 2e5aa939..be6b6734 100644 --- a/src/java/org/mxchange/jjobs/beans/business/branchoffice/JobsAdminBranchOfficeWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/business/branchoffice/JobsAdminBranchOfficeWebRequestBean.java @@ -16,9 +16,12 @@ */ 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; @@ -32,6 +35,9 @@ import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; 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; @@ -46,7 +52,7 @@ import org.mxchange.jusercore.model.user.User; * @author Roland Häder */ @Named ("adminBranchOfficeController") -@RequestScoped +@SessionScoped public class JobsAdminBranchOfficeWebRequestBean extends BaseJobsBean implements JobsAdminBranchOfficeWebRequestController { /** @@ -108,6 +114,11 @@ public class JobsAdminBranchOfficeWebRequestBean extends BaseJobsBean implements @Inject private JobsBranchOfficeWebRequestController branchOfficeController; + /** + * Opening times of this branch office + */ + private static List branchOpeningTimes; + /** * Store */ @@ -163,12 +174,38 @@ public class JobsAdminBranchOfficeWebRequestBean extends BaseJobsBean implements */ 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); + } } /** @@ -204,10 +241,50 @@ public class JobsAdminBranchOfficeWebRequestBean extends BaseJobsBean implements // 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 *

@@ -334,6 +411,26 @@ public class JobsAdminBranchOfficeWebRequestBean extends BaseJobsBean implements this.branchNumber = branchNumber; } + /** + * Getter for opening times of this branch office + *

+ * @return Opening times + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getBranchOpeningTimes () { + return branchOpeningTimes; + } + + /** + * Setter for opening times of this branch office + *

+ * @param branchOpeningTimes Opening times + */ + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setBranchOpeningTimes (final List branchOpeningTimes) { + FinancialsAdminBranchOfficeWebRequestBean.branchOpeningTimes = branchOpeningTimes; + } + /** * Getter for store *

@@ -532,6 +629,116 @@ public class JobsAdminBranchOfficeWebRequestBean extends BaseJobsBean implements this.landLineNumber = landLineNumber; } + /** + * Getter for ending week day + *

+ * @return Ending week day + */ + public DayOfTheWeek getOpeningEndDay () { + return this.openingEndDay; + } + + /** + * Setter for ending week day + *

+ * @param openingEndDay Ending week day + */ + public void setOpeningEndDay (final DayOfTheWeek openingEndDay) { + this.openingEndDay = openingEndDay; + } + + /** + * Getter for ending time + *

+ * @return Ending time + */ + @SuppressWarnings ("ReturnOfDateField") + public Date getOpeningEndTime () { + return this.openingEndTime; + } + + /** + * Getter for ending time + *

+ * @param openingEndTime Ending time + */ + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setOpeningEndTime (final Date openingEndTime) { + this.openingEndTime = openingEndTime; + } + + /** + * Getter for starting week day + *

+ * @return Starting week day + */ + public DayOfTheWeek getOpeningStartDay () { + return this.openingStartDay; + } + + /** + * Getter for starting week day + *

+ * @param openingStartDay Starting week day + */ + public void setOpeningStartDay (final DayOfTheWeek openingStartDay) { + this.openingStartDay = openingStartDay; + } + + /** + * Getter for starting time + *

+ * @return Starting time + */ + @SuppressWarnings ("ReturnOfDateField") + public Date getOpeningStartTime () { + return this.openingStartTime; + } + + /** + * Getter for starting time + *

+ * @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 @@ -596,11 +803,31 @@ public class JobsAdminBranchOfficeWebRequestBean extends BaseJobsBean implements // 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. + *

+ * @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 @@ -632,4 +859,29 @@ public class JobsAdminBranchOfficeWebRequestBean extends BaseJobsBean implements return isFound; } + /** + * Checks if given opening time is already added + *

+ * @param openingTime Opening time to be checked + *

+ * @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; + } + }