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;
*/
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;
* <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();
+++ /dev/null
-/*
- * 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));
- }
- }
-
-}
/**
* 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 ... ;-)