Search in sources :

Example 11 with PurchasingItemBase

use of org.kuali.kfs.module.purap.businessobject.PurchasingItemBase in project cu-kfs by CU-CommunityApps.

the class PurchasingCommodityCodeValidation method validateCommodityCodes.

/**
 * Validates whether the commodity code existed on the item, and if existed, whether the
 * commodity code on the item existed in the database, and if so, whether the commodity
 * code is active. Display error if any of these 3 conditions are not met.
 *
 * @param item  The PurApItem containing the commodity code to be validated.
 * @return boolean false if the validation fails and true otherwise.
 */
protected boolean validateCommodityCodes(PurApItem item, boolean commodityCodeRequired) {
    boolean valid = true;
    String identifierString = item.getItemIdentifierString();
    PurchasingItemBase purItem = (PurchasingItemBase) item;
    // check to see if item is unordered and commodity code is required, if so, assign a default commodity code and return true
    if (commodityCodeRequired && purItem.getItemTypeCode().equals("UNOR")) {
        ParameterService parameterService = SpringContext.getBean(ParameterService.class);
        String unorderedItemDefaultCommodityCode = parameterService.getParameterValueAsString(PurapConstants.PURAP_NAMESPACE, "LineItemReceiving", UNORDERED_ITEM_DEFAULT_COMMODITY_CODE);
        purItem.setPurchasingCommodityCode(unorderedItemDefaultCommodityCode);
        valid = true;
    }
    // This validation is only needed if the commodityCodeRequired system parameter is true
    if (commodityCodeRequired && StringUtils.isBlank(purItem.getPurchasingCommodityCode())) {
        // This is the case where the commodity code is required but the item does not currently contain the commodity code.
        valid = false;
        String attributeLabel = businessObjectDictionaryService.getBusinessObjectEntry(CommodityCode.class.getName()).getAttributeDefinition(PurapPropertyConstants.ITEM_COMMODITY_CODE).getLabel();
        GlobalVariables.getMessageMap().putError(PurapPropertyConstants.ITEM_COMMODITY_CODE, KFSKeyConstants.ERROR_REQUIRED, attributeLabel + " in " + identifierString);
    } else if (StringUtils.isNotBlank(purItem.getPurchasingCommodityCode())) {
        // Find out whether the commodity code has existed in the database
        Map<String, String> fieldValues = new HashMap<String, String>();
        fieldValues.put(PurapPropertyConstants.ITEM_COMMODITY_CODE, purItem.getPurchasingCommodityCode());
        if (businessObjectService.countMatching(CommodityCode.class, fieldValues) != 1) {
            // This is the case where the commodity code on the item does not exist in the database.
            valid = false;
            GlobalVariables.getMessageMap().putError(PurapPropertyConstants.ITEM_COMMODITY_CODE, PurapKeyConstants.PUR_COMMODITY_CODE_INVALID, " in " + identifierString);
        } else {
            valid &= validateThatCommodityCodeIsActive(item);
        }
    }
    return valid;
}
Also used : ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) PurchasingItemBase(org.kuali.kfs.module.purap.businessobject.PurchasingItemBase) CommodityCode(org.kuali.kfs.vnd.businessobject.CommodityCode) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PurchasingItemBase (org.kuali.kfs.module.purap.businessobject.PurchasingItemBase)11 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CommodityCode (org.kuali.kfs.vnd.businessobject.CommodityCode)3 List (java.util.List)2 Map (java.util.Map)2 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)2 PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)2 PurchaseOrderItem (org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem)2 PurchasingFavoriteAccountLineBuilderForDistribution (edu.cornell.kfs.module.purap.util.PurchasingFavoriteAccountLineBuilderForDistribution)1 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 ConfigurationService (org.kuali.kfs.core.api.config.property.ConfigurationService)1 CapitalAssetSystem (org.kuali.kfs.integration.purap.CapitalAssetSystem)1 WorkflowDocument (org.kuali.kfs.kew.api.WorkflowDocument)1 MaintenanceDocument (org.kuali.kfs.kns.document.MaintenanceDocument)1 PersistableBusinessObject (org.kuali.kfs.krad.bo.PersistableBusinessObject)1 Document (org.kuali.kfs.krad.document.Document)1 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)1