Search in sources :

Example 1 with CuVendorSupplierDiversityExtension

use of edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension in project cu-kfs by CU-CommunityApps.

the class CuVendorRule method processAddCollectionLineBusinessRules.

public boolean processAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject bo) {
    boolean success = super.processAddCollectionLineBusinessRules(document, collectionName, bo);
    if (collectionName.equals(VendorConstants.VENDOR_HEADER_ATTR + "." + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES)) {
        VendorDetail vendorDetail = (VendorDetail) document.getDocumentBusinessObject();
        VendorHeader vendorHeader = vendorDetail.getVendorHeader();
        List<VendorSupplierDiversity> vendorSupplierDiversities = vendorHeader.getVendorSupplierDiversities();
        if (vendorSupplierDiversities.size() > 0) {
            int i = 0;
            for (VendorSupplierDiversity vendor : vendorSupplierDiversities) {
                if (((CuVendorSupplierDiversityExtension) vendor.getExtension()).getVendorSupplierDiversityExpirationDate() == null) {
                    success = false;
                    putFieldError(VendorConstants.VENDOR_HEADER_ATTR + "." + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES + "[" + i + "]." + CUVendorPropertyConstants.SUPPLIER_DIVERSITY_EXPRIATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_SUPPLIER_DIVERSITY_DATE_BLANK);
                } else if (((CuVendorSupplierDiversityExtension) vendor.getExtension()).getVendorSupplierDiversityExpirationDate().before(new Date())) {
                    // Only check expiration date on new vendors
                    if (document.isNew()) {
                        success = false;
                        putFieldError(VendorConstants.VENDOR_HEADER_ATTR + "." + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES + "[" + i + "]." + CUVendorPropertyConstants.SUPPLIER_DIVERSITY_EXPRIATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_SUPPLIER_DIVERSITY_DATE_IN_PAST);
                    }
                }
                i++;
            }
        }
        if (!success) {
            return success;
        }
    }
    if (collectionName.equals("vendorCommodities")) {
        VendorCommodityCode codeToBeValidated = (VendorCommodityCode) bo;
        CommodityCode persistedCommodity = commodityCodeService.getByPrimaryId(codeToBeValidated.getPurchasingCommodityCode());
        if (persistedCommodity == null) {
            // a commodity code entered by a user does not exist
            putFieldError("add.vendorCommodities.purchasingCommodityCode", CUVendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_DOES_NOT_EXIST, codeToBeValidated.getPurchasingCommodityCode());
            success = false;
        }
        if (codeToBeValidated.isCommodityDefaultIndicator()) {
            VendorDetail vendorDetail = (VendorDetail) document.getDocumentBusinessObject();
            List<VendorCommodityCode> vendorCommodities = vendorDetail.getVendorCommodities();
            Iterator<VendorCommodityCode> commodities = vendorCommodities.iterator();
            int indice = 0;
            while (commodities.hasNext()) {
                VendorCommodityCode commodity = (VendorCommodityCode) commodities.next();
                if (commodity.isCommodityDefaultIndicator()) {
                    // more than one "default" commodity code has been specified
                    putFieldError("add.vendorCommodities.commodityDefaultIndicator", CUVendorKeyConstants.ERROR_DEFAULT_VENDOR_COMMODITY_CODE_ALREADY_EXISTS, Integer.toString(indice));
                    success = false;
                }
                indice++;
            }
        }
        VendorDetail vendorDetail = (VendorDetail) document.getDocumentBusinessObject();
        boolean commodityAlreadyAssignedToThisVendor = false;
        Iterator<VendorCommodityCode> codes = vendorDetail.getVendorCommodities().iterator();
        while (codes.hasNext()) {
            VendorCommodityCode vcc = codes.next();
            if (vcc.getPurchasingCommodityCode().equals(codeToBeValidated.getPurchasingCommodityCode())) {
                commodityAlreadyAssignedToThisVendor = true;
                break;
            }
        }
        if (commodityAlreadyAssignedToThisVendor) {
            putFieldError("add.vendorCommodities.purchasingCommodityCode", CUVendorKeyConstants.ERROR_VENDOR_COMMODITY_CODE_ALREADY_ASSIGNED_TO_VENDOR);
            success = false;
        }
        return success;
    }
    return success;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorHeader(org.kuali.kfs.vnd.businessobject.VendorHeader) VendorCommodityCode(org.kuali.kfs.vnd.businessobject.VendorCommodityCode) CommodityCode(org.kuali.kfs.vnd.businessobject.CommodityCode) CuVendorSupplierDiversityExtension(edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension) VendorSupplierDiversity(org.kuali.kfs.vnd.businessobject.VendorSupplierDiversity) Date(java.util.Date) VendorCommodityCode(org.kuali.kfs.vnd.businessobject.VendorCommodityCode)

Example 2 with CuVendorSupplierDiversityExtension

use of edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension in project cu-kfs by CU-CommunityApps.

the class CuVendorRule method checkSupplierDiversityExpirationDate.

protected boolean checkSupplierDiversityExpirationDate(MaintenanceDocument document) {
    boolean success = true;
    VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getBusinessObject();
    VendorHeader vendorHeader = vendorDetail.getVendorHeader();
    List<VendorSupplierDiversity> vendorSupplierDiversities = vendorHeader.getVendorSupplierDiversities();
    if (vendorSupplierDiversities.size() > 0) {
        int i = 0;
        for (VendorSupplierDiversity vendor : vendorSupplierDiversities) {
            if (((CuVendorSupplierDiversityExtension) vendor.getExtension()).getVendorSupplierDiversityExpirationDate() == null) {
                success = false;
                putFieldError(VendorConstants.VENDOR_HEADER_ATTR + "." + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES + "[" + i + "]." + CUVendorPropertyConstants.SUPPLIER_DIVERSITY_EXPRIATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_SUPPLIER_DIVERSITY_DATE_BLANK);
            } else if (((CuVendorSupplierDiversityExtension) vendor.getExtension()).getVendorSupplierDiversityExpirationDate().before(new Date())) {
                // Only check expiration date on new vendors
                if (document.isNew()) {
                    success = false;
                    putFieldError(VendorConstants.VENDOR_HEADER_ATTR + "." + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES + "[" + i + "]." + CUVendorPropertyConstants.SUPPLIER_DIVERSITY_EXPRIATION, CUVendorKeyConstants.ERROR_DOCUMENT_VNDMAINT_SUPPLIER_DIVERSITY_DATE_IN_PAST);
                }
            }
            i++;
        }
    }
    return success;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) VendorHeader(org.kuali.kfs.vnd.businessobject.VendorHeader) CuVendorSupplierDiversityExtension(edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension) VendorSupplierDiversity(org.kuali.kfs.vnd.businessobject.VendorSupplierDiversity) Date(java.util.Date)

Example 3 with CuVendorSupplierDiversityExtension

use of edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension in project cu-kfs by CU-CommunityApps.

the class CuVendorMaintainableImpl method populateGeneratedHerderId.

private void populateGeneratedHerderId(VendorHeader vendorHeader) {
    if (vendorHeader.getVendorHeaderGeneratedIdentifier() == null) {
        Integer generatedHeaderId = SpringContext.getBean(SequenceAccessorService.class).getNextAvailableSequenceNumber(HEADER_ID_SEQ).intValue();
        vendorHeader.setVendorHeaderGeneratedIdentifier(generatedHeaderId.intValue());
        ((CuVendorHeaderExtension) vendorHeader.getExtension()).setVendorHeaderGeneratedIdentifier(generatedHeaderId);
    }
    if (CollectionUtils.isNotEmpty(vendorHeader.getVendorSupplierDiversities())) {
        for (VendorSupplierDiversity supplierDiversity : vendorHeader.getVendorSupplierDiversities()) {
            supplierDiversity.setVendorHeaderGeneratedIdentifier(vendorHeader.getVendorHeaderGeneratedIdentifier());
            ((CuVendorSupplierDiversityExtension) supplierDiversity.getExtension()).setVendorHeaderGeneratedIdentifier(vendorHeader.getVendorHeaderGeneratedIdentifier());
            ((CuVendorSupplierDiversityExtension) supplierDiversity.getExtension()).setVendorSupplierDiversityCode(supplierDiversity.getVendorSupplierDiversityCode());
        }
    }
}
Also used : CuVendorHeaderExtension(edu.cornell.kfs.vnd.businessobject.CuVendorHeaderExtension) CuVendorSupplierDiversityExtension(edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension) VendorSupplierDiversity(org.kuali.kfs.vnd.businessobject.VendorSupplierDiversity)

Example 4 with CuVendorSupplierDiversityExtension

use of edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension in project cu-kfs by CU-CommunityApps.

the class VendorBatchServiceImpl method getVendorSupplierDiversities.

/*
     * populate list of vendor batch supplier diversities to vendor supplier diversities
     */
private List<VendorSupplierDiversity> getVendorSupplierDiversities(List<VendorBatchSupplierDiversity> supplierDiversitys) {
    List<VendorSupplierDiversity> vendorSupplierDiversitys = new ArrayList<VendorSupplierDiversity>();
    if (CollectionUtils.isNotEmpty(supplierDiversitys)) {
        for (VendorBatchSupplierDiversity diversity : supplierDiversitys) {
            LOG.info("addVendor diversity " + diversity);
            VendorSupplierDiversity vDiversity = new VendorSupplierDiversity();
            vDiversity.setVendorSupplierDiversityCode(diversity.getVendorSupplierDiversityCode());
            if (StringUtils.isNotBlank(diversity.getVendorSupplierDiversityExpirationDate())) {
                ((CuVendorSupplierDiversityExtension) vDiversity.getExtension()).setVendorSupplierDiversityExpirationDate(new java.sql.Date(getFormatDate(diversity.getVendorSupplierDiversityExpirationDate()).getTime()));
            }
            vDiversity.setActive(StringUtils.equalsIgnoreCase(YES, diversity.getActive()));
            vendorSupplierDiversitys.add(vDiversity);
        }
    }
    return vendorSupplierDiversitys;
}
Also used : ArrayList(java.util.ArrayList) VendorBatchSupplierDiversity(edu.cornell.kfs.vnd.businessobject.VendorBatchSupplierDiversity) CuVendorSupplierDiversityExtension(edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension) VendorSupplierDiversity(org.kuali.kfs.vnd.businessobject.VendorSupplierDiversity)

Example 5 with CuVendorSupplierDiversityExtension

use of edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension in project cu-kfs by CU-CommunityApps.

the class VendorBatchServiceImpl method updateVendorSupplierDiversitys.

/*
     * update existing vendor supplier diversity or create a new one if it does not exist.
     */
private void updateVendorSupplierDiversitys(List<VendorBatchSupplierDiversity> supplierDiversitys, VendorDetail vendor, VendorDetail vDetail) {
    ArrayList<VendorSupplierDiversity> vendorSupplierDiversitys = new ArrayList<VendorSupplierDiversity>();
    if (CollectionUtils.isNotEmpty(supplierDiversitys)) {
        for (VendorBatchSupplierDiversity diversity : supplierDiversitys) {
            LOG.info("updateVendor diversity " + diversity);
            VendorSupplierDiversity vDiversity = getVendorSupplierDiversity(vDetail.getVendorHeader(), diversity.getVendorSupplierDiversityCode());
            boolean isExist = StringUtils.isNotBlank(vDiversity.getVendorSupplierDiversityCode());
            vDiversity.setVendorSupplierDiversityCode(diversity.getVendorSupplierDiversityCode());
            if (StringUtils.isNotBlank(diversity.getVendorSupplierDiversityExpirationDate())) {
                ((CuVendorSupplierDiversityExtension) vDiversity.getExtension()).setVendorSupplierDiversityExpirationDate(new java.sql.Date(getFormatDate(diversity.getVendorSupplierDiversityExpirationDate()).getTime()));
            }
            vDiversity.setActive(StringUtils.equalsIgnoreCase(YES, diversity.getActive()));
            if (!isExist) {
                vDetail.getVendorHeader().getVendorSupplierDiversities().add(vDiversity);
                vendor.getVendorHeader().getVendorSupplierDiversities().add(new VendorSupplierDiversity());
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) VendorBatchSupplierDiversity(edu.cornell.kfs.vnd.businessobject.VendorBatchSupplierDiversity) CuVendorSupplierDiversityExtension(edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension) VendorSupplierDiversity(org.kuali.kfs.vnd.businessobject.VendorSupplierDiversity)

Aggregations

CuVendorSupplierDiversityExtension (edu.cornell.kfs.vnd.businessobject.CuVendorSupplierDiversityExtension)6 VendorSupplierDiversity (org.kuali.kfs.vnd.businessobject.VendorSupplierDiversity)6 VendorBatchSupplierDiversity (edu.cornell.kfs.vnd.businessobject.VendorBatchSupplierDiversity)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)2 VendorHeader (org.kuali.kfs.vnd.businessobject.VendorHeader)2 CuVendorHeaderExtension (edu.cornell.kfs.vnd.businessobject.CuVendorHeaderExtension)1 CommodityCode (org.kuali.kfs.vnd.businessobject.CommodityCode)1 VendorCommodityCode (org.kuali.kfs.vnd.businessobject.VendorCommodityCode)1