Search in sources :

Example 1 with AbstractValidationRule

use of com.globalcollect.gateway.sdk.client.android.sdk.model.validation.AbstractValidationRule in project connect-sdk-client-android by Ingenico-ePayments.

the class DataRestrictions method getValidationRules.

public List<AbstractValidationRule> getValidationRules() {
    validationRules.clear();
    if (validators.getExpirationDate() != null) {
        AbstractValidationRule validationRule = new ValidationRuleExpirationDate("expirationDate", ValidationType.EXPIRATIONDATE);
        validationRules.add(validationRule);
    }
    if (validators.getFixedList() != null) {
        if (validators.getFixedList().getAllowedValues() != null) {
            AbstractValidationRule validationRule = new ValidationRuleFixedList(validators.getFixedList().getAllowedValues(), "fixedList", ValidationType.FIXEDLIST);
            validationRules.add(validationRule);
        }
    }
    if (validators.getLength() != null) {
        if (validators.getLength().getMinLength() != null && validators.getLength().getMaxLength() != null) {
            AbstractValidationRule validationRule = new ValidationRuleLength(validators.getLength().getMinLength(), validators.getLength().getMaxLength(), "length", ValidationType.LENGTH);
            validationRules.add(validationRule);
        }
    }
    if (validators.getLuhn() != null) {
        AbstractValidationRule validationRule = new ValidationRuleLuhn("luhn", ValidationType.LUHN);
        validationRules.add(validationRule);
    }
    if (validators.getRange() != null) {
        if (validators.getRange().getMinValue() != null && validators.getRange().getMaxValue() != null) {
            AbstractValidationRule validationRule = new ValidationRuleRange(validators.getRange().getMinValue(), validators.getRange().getMaxValue(), "range", ValidationType.RANGE);
            validationRules.add(validationRule);
        }
    }
    if (validators.getTermsAndConditions() != null) {
        AbstractValidationRule validationRule = new ValidationRuleTermsAndConditions("termsAndConditions", ValidationType.TERMSANDCONDITIONS);
        validationRules.add(validationRule);
    }
    if (validators.getRegularExpression() != null) {
        if (validators.getRegularExpression().getRegularExpression() != null) {
            AbstractValidationRule validationRule = new ValidationRuleRegex(validators.getRegularExpression().getRegularExpression(), "regularExpression", ValidationType.REGULAREXPRESSION);
            validationRules.add(validationRule);
        }
    }
    if (validators.getEmailAddress() != null) {
        AbstractValidationRule validationRule = new ValidationRuleEmailAddress("emailAddress", ValidationType.EMAILADDRESS);
        validationRules.add(validationRule);
    }
    if (validators.getBoletoBancarioRequiredness() != null) {
        if (validators.getBoletoBancarioRequiredness().getFiscalNumberLength() != null) {
            AbstractValidationRule validationRule = new ValidationRuleBoletoBancarioRequiredness(validators.getBoletoBancarioRequiredness().getFiscalNumberLength(), "boletobancariorequiredness", ValidationType.BOLETOBANCARIOREQUIREDNESS);
            validationRules.add(validationRule);
        }
    }
    return validationRules;
}
Also used : ValidationRuleLength(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleLength) ValidationRuleRegex(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleRegex) ValidationRuleFixedList(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleFixedList) ValidationRuleLuhn(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleLuhn) AbstractValidationRule(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.AbstractValidationRule) ValidationRuleRange(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleRange) ValidationRuleEmailAddress(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleEmailAddress) ValidationRuleBoletoBancarioRequiredness(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleBoletoBancarioRequiredness) ValidationRuleExpirationDate(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleExpirationDate) ValidationRuleTermsAndConditions(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleTermsAndConditions)

Example 2 with AbstractValidationRule

use of com.globalcollect.gateway.sdk.client.android.sdk.model.validation.AbstractValidationRule in project connect-sdk-client-android by Ingenico-ePayments.

the class PaymentProductField method validateValue.

/**
 * Gets all errormessagecodes for this field's value.
 * This list is filled after doing isValid() on this field
 * @param paymentRequest, The fully filled PaymentRequest, that holds all the values that the payment
 *                        will be made with.
 * @return A list of error messages that apply to this field. If the list is empty you can
 * assume that the field value is a valid value.
 */
public List<ValidationErrorMessage> validateValue(PaymentRequest paymentRequest) {
    // Get the value from the paymentRequest
    String value = paymentRequest.getValue(id);
    // Remove possible existing errors
    errorMessageIds.clear();
    // check required first
    if (dataRestrictions.isRequired() && valueNullOrEmpty(value)) {
        // If field is required, but has no value, add to the the errormessage list
        errorMessageIds.add(new ValidationErrorMessage("required", id, null));
    } else {
        // BoletoBancarioRequiredness validator do need to be validated.
        if (!valueNullOrEmpty(value) || containsBoletoBancarioRequirednessValidator()) {
            for (AbstractValidationRule rule : dataRestrictions.getValidationRules()) {
                if (!rule.validate(paymentRequest, id)) {
                    // If an invalid fieldvalue is found, add to the the errormessage list
                    errorMessageIds.add(new ValidationErrorMessage(rule.getMessageId(), id, rule));
                }
            }
        }
    }
    return errorMessageIds;
}
Also used : AbstractValidationRule(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.AbstractValidationRule) ValidationErrorMessage(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationErrorMessage)

Aggregations

AbstractValidationRule (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.AbstractValidationRule)2 ValidationErrorMessage (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationErrorMessage)1 ValidationRuleBoletoBancarioRequiredness (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleBoletoBancarioRequiredness)1 ValidationRuleEmailAddress (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleEmailAddress)1 ValidationRuleExpirationDate (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleExpirationDate)1 ValidationRuleFixedList (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleFixedList)1 ValidationRuleLength (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleLength)1 ValidationRuleLuhn (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleLuhn)1 ValidationRuleRange (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleRange)1 ValidationRuleRegex (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleRegex)1 ValidationRuleTermsAndConditions (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleTermsAndConditions)1