Search in sources :

Example 1 with ValidationRuleLength

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

the class RenderValidationHelper method renderValidationMessageOnScreen.

private void renderValidationMessageOnScreen(ValidationErrorMessage validationResult, PaymentItem paymentItem) {
    String fieldId = validationResult.getPaymentProductFieldId();
    // Get the correct view of the invalid inputfield
    View view = parentView.findViewWithTag(fieldId);
    if (!canErrorMessageBeRendered(view, fieldId)) {
        return;
    }
    String validationMessage;
    if ("length".equals(validationResult.getErrorMessage()) && validationResult.getRule() instanceof ValidationRuleLength) {
        validationMessage = getCorrectMessageForLength(validationResult);
    } else {
        validationMessage = translator.getValidationMessage(validationResult.getErrorMessage());
    }
    if (validationResult.getRule() != null && paymentItem != null) {
        // Find the correct validationRule and format its message with variables attributes
        for (PaymentProductField field : paymentItem.getPaymentProductFields()) {
            if (field.getId().equals(validationResult.getPaymentProductFieldId())) {
                ValidationRule rule = validationResult.getRule();
                // if ValidationRuleLength, then add extra information to the errormessage
                if (rule instanceof ValidationRuleLength) {
                    // Replace the generic placeholders with Java specific placeholders, e.g. {maxlength} becomes {0}
                    validationMessage = formatMessagePlaceHolders(validationMessage);
                    // Show only the maxlength message if there is only one placeholder, else show minlenght and maxlength
                    if (validationMessage.split("\\{").length == 2) {
                        validationMessage = MessageFormat.format(validationMessage, ((ValidationRuleLength) rule).getMaxLength());
                    } else if (validationMessage.split("\\{").length == 3) {
                        validationMessage = MessageFormat.format(validationMessage, ((ValidationRuleLength) rule).getMinLength(), ((ValidationRuleLength) rule).getMaxLength());
                    }
                }
                // if ValidationRuleRange,then add extra information to the errormessage
                if (rule instanceof ValidationRuleRange) {
                    // Replace the generic placeholders with Java specific placeholders, e.g. {maxlength} becomes {0}
                    validationMessage = formatMessagePlaceHolders(validationMessage);
                    // Show only the maxvalue if there is only one placeholder, else show minvalue and maxvalue
                    if (validationMessage.split("\\{").length == 2) {
                        validationMessage = MessageFormat.format(validationMessage, ((ValidationRuleRange) rule).getMaxValue());
                    } else if (validationMessage.split("\\{").length == 3) {
                        validationMessage = MessageFormat.format(validationMessage, ((ValidationRuleRange) rule).getMinValue(), ((ValidationRuleRange) rule).getMaxValue());
                    }
                }
            }
        }
    }
    validationMessageRenderer.renderValidationMessage(validationMessage, (ViewGroup) view.getParent(), validationResult.getPaymentProductFieldId());
}
Also used : ValidationRuleLength(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleLength) PaymentProductField(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductField) ValidationRuleRange(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleRange) View(android.view.View) ValidationRule(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRule)

Example 2 with ValidationRuleLength

use of com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleLength 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 3 with ValidationRuleLength

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

the class ValidationTest method testInvalidLength.

@Test
public void testInvalidLength() {
    PaymentRequest paymentRequest = new TestPaymentRequest();
    paymentRequest.setValue("length", invalidLength);
    ValidationRuleLength rule = new ValidationRuleLength(minLength, maxLength, "", ValidationType.LENGTH);
    assertEquals(false, rule.validate(paymentRequest, "length"));
}
Also used : ValidationRuleLength(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleLength) PaymentRequest(com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentRequest) Test(org.junit.Test)

Example 4 with ValidationRuleLength

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

the class ValidationTest method testValidLength.

// Test length validator
@Test
public void testValidLength() {
    PaymentRequest paymentRequest = new TestPaymentRequest();
    paymentRequest.setValue("length", validLength);
    ValidationRuleLength rule = new ValidationRuleLength(minLength, maxLength, "", ValidationType.LENGTH);
    assertEquals(true, rule.validate(paymentRequest, "length"));
}
Also used : ValidationRuleLength(com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleLength) PaymentRequest(com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentRequest) Test(org.junit.Test)

Aggregations

ValidationRuleLength (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleLength)4 PaymentRequest (com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentRequest)2 ValidationRuleRange (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleRange)2 Test (org.junit.Test)2 View (android.view.View)1 PaymentProductField (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductField)1 AbstractValidationRule (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.AbstractValidationRule)1 ValidationRule (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRule)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 ValidationRuleLuhn (com.globalcollect.gateway.sdk.client.android.sdk.model.validation.ValidationRuleLuhn)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