Search in sources :

Example 1 with PurchaseOrderTransmissionMethodDataRulesService

use of edu.cornell.kfs.module.purap.document.service.PurchaseOrderTransmissionMethodDataRulesService in project cu-kfs by CU-CommunityApps.

the class CuVendorRule method validateVendorAddressForMethodOfPOTransmission.

/**
 * This routine verifies that the data necessary for the Method of PO Transmission chosen exists and that data
 * is in the proper format on the VendorAddress section of the Vendor maintenance document.
 * If the data does not exist or is not in the proper format, the field(s) in question on that maintenance
 * document is/are noted as being in error.
 *
 * NOTE: This method call the same rule checks (PurchaseOrderTransmissionMethodDataRulesService)
 * for each data element on this maintenance document as the REQ, PO, and POA.
 */
private boolean validateVendorAddressForMethodOfPOTransmission(VendorAddress address, String propertyScope) {
    boolean valid = true;
    String propertyName;
    String[] parameters;
    String transmissionMethod = ((CuVendorAddressExtension) address.getExtension()).getPurchaseOrderTransmissionMethodCode();
    String addressTypeCode = address.getVendorAddressTypeCode();
    PurchaseOrderTransmissionMethodDataRulesService purchaseOrderTransmissionMethodDataRulesService = SpringContext.getBean(PurchaseOrderTransmissionMethodDataRulesService.class);
    if ((transmissionMethod == null) || (StringUtils.isBlank(transmissionMethod))) {
    // no-op, nothing to verify, default return value is valid
    } else if ((StringUtils.isBlank(addressTypeCode)) || (transmissionMethod.equalsIgnoreCase(CUPurapConstants.POTransmissionMethods.CONVERSION))) {
    // no-op, nothing to verify, default return value is valid
    } else if (transmissionMethod.equalsIgnoreCase(PurapConstants.POTransmissionMethods.FAX)) {
        // requires fax number is entered in format (xxx-xxx-xxxx)
        if (!purchaseOrderTransmissionMethodDataRulesService.isFaxNumberValid(address.getVendorFaxNumber())) {
            propertyName = new String(propertyScope + VendorPropertyConstants.VENDOR_FAX_NUMBER);
            putFieldError(propertyName, CUVendorKeyConstants.ERROR_PO_TRANSMISSION_REQUIRES_FAX_NUMBER);
            valid &= false;
        }
    } else if (transmissionMethod.equalsIgnoreCase(CUPurapConstants.POTransmissionMethods.EMAIL)) {
        // requires an email address is entered
        if (!purchaseOrderTransmissionMethodDataRulesService.isEmailAddressValid(address.getVendorAddressEmailAddress())) {
            propertyName = new String(propertyScope + CUVendorPropertyConstants.VENDOR_ADDRESS_EMAIL_ADDRESS);
            putFieldError(propertyName, CUVendorKeyConstants.ERROR_PO_TRANSMISSION_REQUIRES_EMAIL);
            valid &= false;
        }
    } else if (transmissionMethod.equalsIgnoreCase(CUPurapConstants.POTransmissionMethods.MANUAL)) {
        // has all the required data been entered?
        if (!purchaseOrderTransmissionMethodDataRulesService.isCountryCodeValid(address.getVendorCountryCode())) {
            propertyName = new String(propertyScope + VendorPropertyConstants.VENDOR_ADDRESS_COUNTRY);
            putFieldError(propertyName, CUVendorKeyConstants.ERROR_PO_TRANSMISSION_REQUIRES_US_POSTAL);
            valid &= false;
        }
        if (!purchaseOrderTransmissionMethodDataRulesService.isStateCodeValid(address.getVendorStateCode())) {
            propertyName = new String(propertyScope + VendorPropertyConstants.VENDOR_ADDRESS_STATE_CODE);
            putFieldError(propertyName, CUVendorKeyConstants.ERROR_PO_TRANSMISSION_REQUIRES_US_POSTAL);
            valid &= false;
        }
        if (!purchaseOrderTransmissionMethodDataRulesService.isZipCodeValid(address.getVendorZipCode())) {
            propertyName = new String(propertyScope + VendorPropertyConstants.VENDOR_ADDRESS_ZIP);
            putFieldError(propertyName, CUVendorKeyConstants.ERROR_PO_TRANSMISSION_REQUIRES_US_POSTAL);
            valid &= false;
        }
        if (!purchaseOrderTransmissionMethodDataRulesService.isAddress1Valid(address.getVendorLine1Address())) {
            propertyName = new String(propertyScope + VendorPropertyConstants.VENDOR_ADDRESS_LINE_1);
            putFieldError(propertyName, CUVendorKeyConstants.ERROR_PO_TRANSMISSION_REQUIRES_US_POSTAL);
            valid &= false;
        }
        if (!purchaseOrderTransmissionMethodDataRulesService.isCityValid(address.getVendorCityName())) {
            propertyName = new String(propertyScope + VendorPropertyConstants.VENDOR_ADDRESS_CITY);
            putFieldError(propertyName, CUVendorKeyConstants.ERROR_PO_TRANSMISSION_REQUIRES_US_POSTAL);
            valid &= false;
        }
        if (valid) {
            // user entered all the data, now verify relationships in the data
            // verify US, state and zip are valid as they are related to each other, error message taken care of in called routine
            valid &= SpringContext.getBean(PostalCodeValidationService.class).validateAddress(address.getVendorCountryCode(), address.getVendorStateCode(), address.getVendorZipCode(), propertyScope + VendorPropertyConstants.VENDOR_ADDRESS_STATE, propertyScope + VendorPropertyConstants.VENDOR_ADDRESS_ZIP);
        }
    } else {
        // Method of PO Transmission maintenance table has a value that is not coded for processing
        parameters = new String[] { transmissionMethod };
        propertyName = new String(propertyScope + CUVendorPropertyConstants.VENDOR_ADDRESS_METHOD_OF_PO_TRANSMISSION);
        putFieldError(propertyName, CUVendorKeyConstants.ERROR_PO_TRANSMISSION_METHOD_UNKNOWN, parameters);
        valid &= false;
    }
    return valid;
}
Also used : CuVendorAddressExtension(edu.cornell.kfs.vnd.businessobject.CuVendorAddressExtension) PurchaseOrderTransmissionMethodDataRulesService(edu.cornell.kfs.module.purap.document.service.PurchaseOrderTransmissionMethodDataRulesService)

Aggregations

PurchaseOrderTransmissionMethodDataRulesService (edu.cornell.kfs.module.purap.document.service.PurchaseOrderTransmissionMethodDataRulesService)1 CuVendorAddressExtension (edu.cornell.kfs.vnd.businessobject.CuVendorAddressExtension)1