Search in sources :

Example 1 with VendorDefaultAddress

use of org.kuali.kfs.vnd.businessobject.VendorDefaultAddress in project cu-kfs by CU-CommunityApps.

the class VendorRule method refreshSubObjects.

/**
 * Refreshes the references of vendor detail and its sub objects
 *
 * @param vendor VendorDetail document
 */
protected void refreshSubObjects(VendorDetail vendor) {
    if (vendor == null) {
        return;
    }
    // division vendor
    if (!vendor.isVendorParentIndicator()) {
        vendor.refreshNonUpdateableReferences();
        vendor.getVendorHeader().refreshNonUpdateableReferences();
    } else {
        // Retrieve the references objects of the vendor header of this vendor.
        List<String> headerFieldNames = getObjectReferencesListFromBOClass(VendorHeader.class);
        vendor.getVendorHeader().refreshNonUpdateableReferences();
        getPersistenceService().retrieveReferenceObjects(vendor.getVendorHeader(), headerFieldNames);
        // We still need to retrieve all the other references of this vendor in addition to
        // vendor header. Since this is a parent vendor, whose vendor header saving is handled manually,
        // we have already retrieved references for vendor header's attributes above, so we should
        // exclude retrieving reference objects of vendor header.
        List<String> detailFieldNames = getObjectReferencesListFromBOClass(vendor.getClass());
        detailFieldNames.remove(VendorConstants.VENDOR_HEADER_ATTR);
        getPersistenceService().retrieveReferenceObjects(vendor, detailFieldNames);
    }
    // refresh addresses
    if (vendor.getVendorAddresses() != null) {
        for (VendorAddress address : vendor.getVendorAddresses()) {
            address.refreshNonUpdateableReferences();
            if (address.getVendorDefaultAddresses() != null) {
                for (VendorDefaultAddress defaultAddress : address.getVendorDefaultAddresses()) {
                    defaultAddress.refreshNonUpdateableReferences();
                }
            }
        }
    }
    // refresh contacts
    if (vendor.getVendorContacts() != null) {
        for (VendorContact contact : vendor.getVendorContacts()) {
            contact.refreshNonUpdateableReferences();
            // ==== CU Customization ====
            if (contact.getVendorContactPhoneNumbers() != null) {
                for (VendorContactPhoneNumber contactPhoneNumber : contact.getVendorContactPhoneNumbers()) {
                    contactPhoneNumber.refreshNonUpdateableReferences();
                }
            }
        // ==== End of CU Customization Section ====
        }
    }
    // refresh contracts
    if (vendor.getVendorContracts() != null) {
        for (VendorContract contract : vendor.getVendorContracts()) {
            contract.refreshNonUpdateableReferences();
        }
    }
}
Also used : VendorContactPhoneNumber(org.kuali.kfs.vnd.businessobject.VendorContactPhoneNumber) VendorContract(org.kuali.kfs.vnd.businessobject.VendorContract) VendorContact(org.kuali.kfs.vnd.businessobject.VendorContact) VendorDefaultAddress(org.kuali.kfs.vnd.businessobject.VendorDefaultAddress) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress)

Example 2 with VendorDefaultAddress

use of org.kuali.kfs.vnd.businessobject.VendorDefaultAddress in project cu-kfs by CU-CommunityApps.

the class VendorRule method processCustomAddCollectionLineBusinessRules.

/**
 * Validates business rules for VendorDetail document collection add lines. Add lines are the initial lines on a
 * collections, i.e. the ones next to the "Add" button
 */
@Override
public boolean processCustomAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject bo) {
    boolean success = true;
    // this incoming bo needs to be refreshed because it doesn't have its subobjects setup
    bo.refreshNonUpdateableReferences();
    if (bo instanceof VendorAddress) {
        VendorAddress address = (VendorAddress) bo;
        success = checkAddressCountryEmptyStateZip(address);
    }
    if (bo instanceof VendorContract) {
        VendorContract contract = (VendorContract) bo;
        success &= validateVendorContractBeginEndDates(contract);
        success &= processContractB2BValidation(contract, -1);
    }
    if (bo instanceof VendorContractOrganization) {
        VendorContractOrganization contractOrg = (VendorContractOrganization) bo;
        success &= validateVendorContractOrganization(contractOrg, 0);
    }
    if (bo instanceof VendorCustomerNumber) {
        VendorCustomerNumber customerNumber = (VendorCustomerNumber) bo;
        success &= validateVendorCustomerNumber(customerNumber);
    }
    if (bo instanceof VendorDefaultAddress) {
        VendorDefaultAddress defaultAddress = (VendorDefaultAddress) bo;
        String parentName = StringUtils.substringBeforeLast(collectionName, ".");
        VendorAddress parent = (VendorAddress) ObjectUtils.getPropertyValue(this.getNewBo(), parentName);
        VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getBusinessObject();
        success &= checkDefaultAddressCampus(vendorDetail, defaultAddress, parent);
    }
    if (bo instanceof VendorCommodityCode) {
        VendorCommodityCode commodityCode = (VendorCommodityCode) bo;
        String purchasingCommodityCode = commodityCode.getPurchasingCommodityCode();
        boolean found = ObjectUtils.isNotNull(commodityCode) && StringUtils.isNotBlank(purchasingCommodityCode) && checkVendorCommodityCode(commodityCode);
        if (!found) {
            GlobalVariables.getMessageMap().putError(VendorPropertyConstants.PURCHASING_COMMODITY_CODE, KFSKeyConstants.ERROR_EXISTENCE, purchasingCommodityCode);
        }
        success &= found;
    }
    return success;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorContract(org.kuali.kfs.vnd.businessobject.VendorContract) VendorCustomerNumber(org.kuali.kfs.vnd.businessobject.VendorCustomerNumber) VendorContractOrganization(org.kuali.kfs.vnd.businessobject.VendorContractOrganization) VendorDefaultAddress(org.kuali.kfs.vnd.businessobject.VendorDefaultAddress) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress) VendorCommodityCode(org.kuali.kfs.vnd.businessobject.VendorCommodityCode)

Example 3 with VendorDefaultAddress

use of org.kuali.kfs.vnd.businessobject.VendorDefaultAddress in project cu-kfs by CU-CommunityApps.

the class VendorRule method validateDefaultAddressCampus.

/**
 * Checks if the allow default indicator is set to false for this address the default indicator cannot be set to
 * true/yes. If "allow default indicator" is set to true/yes for address type, one address must have the default
 * indicator set (no more, no less) and only one campus to be set as default for this address.
 *
 * @param vendorDetail VendorDetail document
 * @return boolean false or true
 */
protected boolean validateDefaultAddressCampus(VendorDetail vendorDetail) {
    List<VendorAddress> vendorAddresses = vendorDetail.getVendorAddresses();
    String addressTypeCode;
    String addressTypeDesc;
    String campusCode;
    boolean valid = true;
    boolean previousValue = false;
    // This is a HashMap to store the default Address Type Codes and their associated default Indicator
    HashMap<String, Boolean> addressTypeCodeDefaultIndicator = new HashMap<>();
    // This is a HashMap to store Address Type Codes and Address Campus Codes for Default Addresses
    HashMap<String, String> addressTypeDefaultCampus = new HashMap<>();
    // This is a HashSet for storing only the Address Type Codes which have at least one default Indicator set to
    // true
    HashSet<String> addressTypesHavingDefaultTrue = new HashSet<>();
    int i = 0;
    for (VendorAddress address : vendorAddresses) {
        addressTypeCode = address.getVendorAddressTypeCode();
        addressTypeDesc = address.getVendorAddressType().getVendorAddressTypeDescription();
        String errorPath = MAINTAINABLE_ERROR_PREFIX + VendorPropertyConstants.VENDOR_ADDRESS + "[" + i + "]";
        GlobalVariables.getMessageMap().addToErrorPath(errorPath);
        String[] parameters = new String[] { addressTypeCode };
        // set to true/yes.
        if (findAllowDefaultAddressIndicatorHelper(address)) {
            if (address.isVendorDefaultAddressIndicator()) {
                addressTypesHavingDefaultTrue.add(addressTypeCode);
            }
            if (!addressTypeCodeDefaultIndicator.isEmpty() && addressTypeCodeDefaultIndicator.containsKey(addressTypeCode)) {
                previousValue = addressTypeCodeDefaultIndicator.get(addressTypeCode);
            }
            if (addressTypeCodeDefaultIndicator.put(addressTypeCode, address.isVendorDefaultAddressIndicator()) != null && previousValue && address.isVendorDefaultAddressIndicator()) {
                GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_DEFAULT_ADDRESS_INDICATOR, VendorKeyConstants.ERROR_ADDRESS_DEFAULT_INDICATOR, addressTypeDesc);
                valid = false;
            }
        } else {
            // set to true/yes.
            if (address.isVendorDefaultAddressIndicator()) {
                GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_DEFAULT_ADDRESS_INDICATOR, VendorKeyConstants.ERROR_ADDRESS_DEFAULT_ADDRESS_NOT_ALLOWED, parameters);
                valid = false;
            }
        }
        List<VendorDefaultAddress> vendorDefaultAddresses = address.getVendorDefaultAddresses();
        // If "allow default indicator" is set to true/yes for address type, a campus can only be set on one of
        // each type of Address.
        // For example, Bloomington can not be included in the campus list for two PO type addresses.
        // Each campus can only have one default address.
        int j = 0;
        for (VendorDefaultAddress defaultAddress : vendorDefaultAddresses) {
            campusCode = addressTypeDefaultCampus.put(addressTypeCode, defaultAddress.getVendorCampusCode());
            if (StringUtils.isNotBlank(campusCode) && campusCode.equalsIgnoreCase(defaultAddress.getVendorCampusCode())) {
                String[] newParameters = new String[] { defaultAddress.getVendorCampusCode(), addressTypeCode };
                GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_DEFAULT_ADDRESS + "[" + j + "]." + VendorPropertyConstants.VENDOR_DEFAULT_ADDRESS_CAMPUS, VendorKeyConstants.ERROR_ADDRESS_DEFAULT_CAMPUS, newParameters);
                valid = false;
            }
            j++;
        }
        i++;
        GlobalVariables.getMessageMap().removeFromErrorPath(errorPath);
    }
    // indicator set to true
    if (!addressTypeCodeDefaultIndicator.isEmpty()) {
        Set<String> addressTypes = addressTypeCodeDefaultIndicator.keySet();
        for (String addressType : addressTypes) {
            if (!addressTypesHavingDefaultTrue.contains(addressType)) {
                int addressIndex = 0;
                for (VendorAddress address : vendorAddresses) {
                    String[] parameters = new String[] { address.getVendorAddressType().getVendorAddressTypeDescription() };
                    String propertyName = VendorPropertyConstants.VENDOR_ADDRESS + "[" + addressIndex + "]." + VendorPropertyConstants.VENDOR_DEFAULT_ADDRESS_INDICATOR;
                    if (address.getVendorAddressType().getVendorAddressTypeCode().equalsIgnoreCase(addressType)) {
                        putFieldError(propertyName, VendorKeyConstants.ERROR_ADDRESS_DEFAULT_INDICATOR, parameters);
                        break;
                    }
                    addressIndex++;
                }
                valid = false;
            }
        }
    }
    return valid;
}
Also used : HashMap(java.util.HashMap) VendorDefaultAddress(org.kuali.kfs.vnd.businessobject.VendorDefaultAddress) VendorAddress(org.kuali.kfs.vnd.businessobject.VendorAddress) HashSet(java.util.HashSet)

Example 4 with VendorDefaultAddress

use of org.kuali.kfs.vnd.businessobject.VendorDefaultAddress in project cu-kfs by CU-CommunityApps.

the class VendorRule method checkDefaultAddressCampus.

/**
 * If add button is selected on Default Address, checks if the allow default indicator is set to false for this
 * address type then it does not allow user to select a default address for this address and if it is true then it
 * allows only one campus to be default for this address.
 *
 * @param vendorDetail        VendorDetail document
 * @param addedDefaultAddress VendorDefaultAddress which is being added
 * @param vendorAddress       The VendorAddress which we are adding a default address to it
 * @return boolean false or true
 */
protected boolean checkDefaultAddressCampus(VendorDetail vendorDetail, VendorDefaultAddress addedDefaultAddress, VendorAddress vendorAddress) {
    if (ObjectUtils.isNull(vendorAddress)) {
        return false;
    }
    int j = vendorDetail.getVendorAddresses().indexOf(vendorAddress);
    String errorPath = MAINTAINABLE_ERROR_PREFIX + VendorPropertyConstants.VENDOR_ADDRESS + "[" + j + "]";
    GlobalVariables.getMessageMap().addToErrorPath(errorPath);
    // Retrieving the Default Address Indicator for this Address Type:
    boolean allowDefaultAddressIndicator = findAllowDefaultAddressIndicatorHelper(vendorAddress);
    String addedAddressCampusCode = addedDefaultAddress.getVendorCampusCode();
    String addedAddressTypeCode = vendorAddress.getVendorAddressTypeCode();
    // select the default indicator or add any campuses to the address
    if (!allowDefaultAddressIndicator) {
        String[] parameters = new String[] { addedAddressTypeCode };
        GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_DEFAULT_ADDRESS + "[" + 0 + "]." + VendorPropertyConstants.VENDOR_DEFAULT_ADDRESS_CAMPUS, VendorKeyConstants.ERROR_ADDRESS_DEFAULT_CAMPUS_NOT_ALLOWED, parameters);
        return false;
    }
    List<VendorDefaultAddress> vendorDefaultAddresses = vendorAddress.getVendorDefaultAddresses();
    for (int i = 0; i < vendorDefaultAddresses.size(); i++) {
        VendorDefaultAddress vendorDefaultAddress = vendorDefaultAddresses.get(i);
        if (vendorDefaultAddress.getVendorCampusCode().equalsIgnoreCase(addedAddressCampusCode)) {
            GlobalVariables.getMessageMap().clearErrorPath();
            GlobalVariables.getMessageMap().addToErrorPath(errorPath);
            String[] parameters = new String[] { addedAddressCampusCode, addedAddressTypeCode };
            GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_DEFAULT_ADDRESS + "[" + i + "]." + VendorPropertyConstants.VENDOR_DEFAULT_ADDRESS_CAMPUS, VendorKeyConstants.ERROR_ADDRESS_DEFAULT_CAMPUS, parameters);
            return false;
        }
    }
    return true;
}
Also used : VendorDefaultAddress(org.kuali.kfs.vnd.businessobject.VendorDefaultAddress)

Aggregations

VendorDefaultAddress (org.kuali.kfs.vnd.businessobject.VendorDefaultAddress)4 VendorAddress (org.kuali.kfs.vnd.businessobject.VendorAddress)3 VendorContract (org.kuali.kfs.vnd.businessobject.VendorContract)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 VendorCommodityCode (org.kuali.kfs.vnd.businessobject.VendorCommodityCode)1 VendorContact (org.kuali.kfs.vnd.businessobject.VendorContact)1 VendorContactPhoneNumber (org.kuali.kfs.vnd.businessobject.VendorContactPhoneNumber)1 VendorContractOrganization (org.kuali.kfs.vnd.businessobject.VendorContractOrganization)1 VendorCustomerNumber (org.kuali.kfs.vnd.businessobject.VendorCustomerNumber)1 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)1