]> git.mxchange.org Git - jjobs-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sun, 25 Sep 2022 20:21:32 +0000 (22:21 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 25 Sep 2022 20:23:21 +0000 (22:23 +0200)
- removed duplicate validator for branch office's email address
- validators should check specific fields, not generic
- arranged code a bit for better readability
- renamed private method

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jjobs/beans/business/department/action/JobsAdminBranchOfficeActionWebRequestBean.java
src/java/org/mxchange/jjobs/validator/business/branchoffice/JobsBranchOfficeEmailAddressValidator.java [deleted file]
src/java/org/mxchange/jjobs/validator/emailaddress/basicdata/JobsBasicDataEmailAddressValidator.java
src/java/org/mxchange/jjobs/validator/emailaddress/branchoffice/JobsBranchOfficeEmailAddressValidator.java
src/java/org/mxchange/jjobs/validator/emailaddress/headquarter/JobsHeadquarterEmailAddressValidator.java

index 2556ad6b778d52f809bfd765fcbc16615def6ae6..59c37566c664bfcf5b53508e460edc87af9aa945 100644 (file)
@@ -257,7 +257,7 @@ public class JobsAdminBranchOfficeActionWebRequestBean extends BaseJobsBean impl
                final BranchOffice branchOffice = this.createBranchOffice();
 
                // Is the branch office not created yet?
-               if (this.isBranchOfficeCreatedByRequiredData(branchOffice)) {
+               if (this.isBranchOfficeCreatedBySameAddress(branchOffice)) {
                        // Then show proper faces message
                        this.showFacesMessage("form-admin-add-branch-office:branchStreet", "ADMIN_BRANCH_OFFICE_ALREADY_CREATED", FacesMessage.SEVERITY_WARN); //NOI18N
                        return;
@@ -1076,7 +1076,12 @@ public class JobsAdminBranchOfficeActionWebRequestBean extends BaseJobsBean impl
         */
        private OpeningTime createOpeningTimes () {
                // Create new openingTime instance
-               final OpeningTime openingTime = new BusinessOpeningTime(this.getOpeningEndDay(), this.getOpeningEndTime(), this.getOpeningStartDay(), this.getOpeningStartTime());
+               final OpeningTime openingTime = new BusinessOpeningTime(
+                                                 this.getOpeningEndDay(),
+                                                 this.getOpeningEndTime(),
+                                                 this.getOpeningStartDay(),
+                                                 this.getOpeningStartTime()
+                                 );
 
                // Return fully prepared instance
                return openingTime;
@@ -1092,7 +1097,7 @@ public class JobsAdminBranchOfficeActionWebRequestBean extends BaseJobsBean impl
         * <p>
         * @return Whether the address has been found
         */
-       private boolean isBranchOfficeCreatedByRequiredData (final BranchOffice branchOffice) {
+       private boolean isBranchOfficeCreatedBySameAddress (final BranchOffice branchOffice) {
                // Get full list from other bean
                final List<BranchOffice> branchOffices = this.branchOfficeListController.getAllBranchOffices();
 
diff --git a/src/java/org/mxchange/jjobs/validator/business/branchoffice/JobsBranchOfficeEmailAddressValidator.java b/src/java/org/mxchange/jjobs/validator/business/branchoffice/JobsBranchOfficeEmailAddressValidator.java
deleted file mode 100644 (file)
index a6409a3..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (C) 2016 - 2022 Free Software Foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jjobs.validator.business.branchoffice;
-
-import java.text.MessageFormat;
-import java.util.regex.Pattern;
-import javax.enterprise.inject.spi.CDI;
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.validator.FacesValidator;
-import javax.faces.validator.ValidatorException;
-import org.mxchange.jcoreee.validator.string.BaseStringValidator;
-import org.mxchange.jjobs.beans.business.branchoffice.list.JobsBranchOfficeListWebViewBean;
-import org.mxchange.jjobs.beans.business.branchoffice.list.JobsBranchOfficeListWebViewController;
-
-/**
- * A validator for branch office email address validation
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@FacesValidator (value = "BranchOfficeEmailAddressValidator")
-public class JobsBranchOfficeEmailAddressValidator extends BaseStringValidator {
-
-       /**
-        * Branch office backing bean
-        */
-       private static JobsBranchOfficeListWebViewController BRANCH_OFFICE_LIST_CONTROLLER;
-
-       /**
-        * Email pattern
-        */
-       private static final String EMAIL_REGEX = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; //NOI18N
-
-       /**
-        * Pattern matcher
-        */
-       private static final Pattern PATTERN_MATCHER = Pattern.compile(JobsBranchOfficeEmailAddressValidator.EMAIL_REGEX);
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 187_536_745_607_196L;
-
-       /**
-        * Whether empty data is allowed
-        */
-       private Boolean allowEmptyRequiredData;
-
-       /**
-        * Default constructor
-        */
-       public JobsBranchOfficeEmailAddressValidator () {
-               this.allowEmptyRequiredData = Boolean.FALSE;
-       }
-
-       /**
-        * Setter for allowEmptyRequiredData flag
-        * <p>
-        * @param allowEmptyRequiredData Whether empty values are allowed
-        */
-       public void setAllowEmptyRequiredData (final Boolean allowEmptyRequiredData) {
-               this.allowEmptyRequiredData = allowEmptyRequiredData;
-       }
-
-       @Override
-       public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
-               // The required field
-               final String[] requiredFields = {"emailAddress", "emailAddressRepeat", "resendEmailAddress"}; //NOI18N
-
-               // Pre-validation (example: not null, not a string, empty string ...)
-               super.preValidate(context, component, value, requiredFields, this.allowEmptyRequiredData);
-
-               // Is the email address empty and allowed?
-               if (null == value && this.allowEmptyRequiredData) {
-                       // Then accept this here
-                       return;
-               } else if (null == value) {
-                       // Abort here
-                       throw new ValidatorException(new FacesMessage("No empty email address allowed.")); //NOI18N
-               }
-
-               // Get string from object ... ;-)
-               // @TODO Add IDN support (GNU lib?) Search for emailAddressRepeat
-               final String emailAddress = String.valueOf(value).trim();
-
-               // Checks if the email address matches a regex ("low-level" check)
-               // @TODO Should also be done by <f:validatorRegex />)
-               final boolean matches = PATTERN_MATCHER.matcher(emailAddress).matches(); //NOI18N
-
-               // Is the email address valid?
-               if (!matches) {
-                       // Generate message
-                       String message = MessageFormat.format("Email address {0} does not match regular expression.", emailAddress); //NOI18N
-
-                       // Not matching
-                       throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message));
-               }
-
-               // Get client id (aka form id)
-               final String clientId = component.getClientId();
-
-               // Is the instance there?
-               if (null == BRANCH_OFFICE_LIST_CONTROLLER) {
-                       // Get bean from CDI directly
-                       BRANCH_OFFICE_LIST_CONTROLLER = CDI.current().select(JobsBranchOfficeListWebViewBean.class).get();
-               }
-
-               // Is it registered?
-               final Boolean isRegistered = BRANCH_OFFICE_LIST_CONTROLLER.isEmailAddressRegistered(emailAddress);
-
-               // Is the email address already registered?
-               if ((!clientId.endsWith("resendEmailAddress")) && (isRegistered)) { //NOI18N
-                       // Generate message
-                       final String message = MessageFormat.format("Email address {0} is already registered.", emailAddress); //NOI18N
-
-                       // No, then abort here
-                       throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
-               } else if ((clientId.endsWith("resendEmailAddress")) && (!isRegistered)) { //NOI18N
-                       // Generate message
-                       final String message = MessageFormat.format("Email address {0} is not registered.", emailAddress); //NOI18N
-
-                       // No, then abort here
-                       throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
-               }
-       }
-
-}
index 8edef4d2da493d0047832b63ff4b2a73f5834365..aec9e121e5c5b84116260fcd5c81f5bc1f773b48 100644 (file)
@@ -68,7 +68,7 @@ public class JobsBasicDataEmailAddressValidator extends BaseStringValidator {
                }
 
                // The required field
-               final String[] requiredFields = {"emailAddress", "emailAddressRepeat", "resendEmailAddress"}; //NOI18N
+               final String[] requiredFields = {"companyEmailAddress"}; //NOI18N
 
                // Pre-validation (example: not null, not a string, empty string ...)
                super.preValidate(context, component, value, requiredFields, Boolean.TRUE);
index 4ea639ae0a7e88b9d3d3e156bfe2468f9f7f2fb2..2baba45e02e85242e03b8e70efd0b2b2b567e99a 100644 (file)
@@ -54,29 +54,44 @@ public class JobsBranchOfficeEmailAddressValidator extends BaseStringValidator {
        /**
         * Serial number
         */
-       private static final long serialVersionUID = 187_536_745_607_195L;
+       private static final long serialVersionUID = 187_536_745_607_196L;
+
+       /**
+        * Whether empty data is allowed
+        */
+       private Boolean allowEmptyRequiredData;
+
+       /**
+        * Default constructor
+        */
+       public FinancialsBranchOfficeEmailAddressValidator () {
+               this.allowEmptyRequiredData = Boolean.FALSE;
+       }
+
+       /**
+        * Setter for allowEmptyRequiredData flag
+        * <p>
+        * @param allowEmptyRequiredData Whether empty values are allowed
+        */
+       public void setAllowEmptyRequiredData (final Boolean allowEmptyRequiredData) {
+               this.allowEmptyRequiredData = allowEmptyRequiredData;
+       }
 
        @Override
        public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
-               // Validate parameter
-               if (null == context) {
-                       // Throw NPE
-                       throw new NullPointerException("Parameter context is null"); //NOI18N
-               } else if (null == component) {
-                       // Throw NPE again
-                       throw new NullPointerException("Parameter component is null"); //NOI18N
-               }
-
                // The required field
-               final String[] requiredFields = {"emailAddress", "emailAddressRepeat", "resendEmailAddress"}; //NOI18N
+               final String[] requiredFields = {"branchEmailAddress"}; //NOI18N
 
                // Pre-validation (example: not null, not a string, empty string ...)
-               super.preValidate(context, component, value, requiredFields, Boolean.TRUE);
+               super.preValidate(context, component, value, requiredFields, this.allowEmptyRequiredData);
 
-               // Is the email address empty?
-               if (null == value) {
+               // Is the email address empty and allowed?
+               if (null == value && this.allowEmptyRequiredData) {
                        // Then accept this here
                        return;
+               } else if (null == value) {
+                       // Abort here
+                       throw new ValidatorException(new FacesMessage("No empty email address allowed.")); //NOI18N
                }
 
                // Get string from object ... ;-)
index c573e1762bb0a3628f5d6f4d6a5f5a45005ea0b5..cda7086a8dc1e69fe37c883b01aa008322e54ec2 100644 (file)
@@ -68,7 +68,7 @@ public class JobsHeadquarterEmailAddressValidator extends BaseStringValidator {
                }
 
                // The required field
-               final String[] requiredFields = {"emailAddress", "emailAddressRepeat", "resendEmailAddress"}; //NOI18N
+               final String[] requiredFields = {"headquarterEmailAddress"}; //NOI18N
 
                // Pre-validation (example: not null, not a string, empty string ...)
                super.preValidate(context, component, value, requiredFields, Boolean.TRUE);