Search in sources :

Example 21 with VendorDetail

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

the class CuVendorRuleBase method validateParentVendorTaxNumber.

/**
 * Overridden so that when an existing vendor tax number is found when trying to add a new parent vendor,
 * the error message will include the existing vendor detail's ID (in payee ID format).
 *
 * @see org.kuali.kfs.vnd.document.validation.impl.VendorRule#validateParentVendorTaxNumber(org.kuali.kfs.vnd.businessobject.VendorDetail)
 */
@SuppressWarnings("deprecation")
@Override
protected boolean validateParentVendorTaxNumber(VendorDetail vendorDetail) {
    boolean valid = true;
    boolean isParent = vendorDetail.isVendorParentIndicator();
    // ==== CU Customization: Use criteria API instead, due to limited BO service methods with negative criteria. ====
    List<Predicate> criteria = new ArrayList<Predicate>();
    if (ObjectUtils.isNotNull(vendorDetail.getVendorHeader().getVendorTaxTypeCode()) && ObjectUtils.isNotNull(vendorDetail.getVendorHeader().getVendorTaxNumber())) {
        criteria.add(PredicateFactory.equal(VendorPropertyConstants.VENDOR_TAX_TYPE_CODE, vendorDetail.getVendorHeader().getVendorTaxTypeCode()));
        criteria.add(PredicateFactory.equal(VendorPropertyConstants.VENDOR_TAX_NUMBER, vendorDetail.getVendorHeader().getVendorTaxNumber()));
    } else {
        return valid;
    }
    // ==== CU Customization: Use the actual vendor details, not just the count. ====
    List<VendorDetail> existingVendors;
    // excluded from the search
    if (ObjectUtils.isNotNull(vendorDetail.getVendorHeaderGeneratedIdentifier())) {
        // ==== CU Customization: Use CriteriaLookupService instead, since BO service doesn't allow negative criteria in non-count methods. ====
        criteria.add(PredicateFactory.notEqual(VendorPropertyConstants.VENDOR_HEADER_GENERATED_ID, vendorDetail.getVendorHeaderGeneratedIdentifier()));
        existingVendors = SpringContext.getBean(CriteriaLookupService.class).lookup(VendorDetail.class, QueryByCriteria.Builder.fromPredicates(criteria.toArray(new Predicate[criteria.size()]))).getResults();
    } else {
        // If this is creating a new vendor, we can't include the header generated id
        // in the negative criteria because it's null, so we'll only look for existing
        // vendors with the same tax # and tax type regardless of the vendor header generated id.
        // ==== CU Customization: Use CriteriaLookupService instead, since BO service doesn't allow negative criteria in non-count methods. ====
        existingVendors = SpringContext.getBean(CriteriaLookupService.class).lookup(VendorDetail.class, QueryByCriteria.Builder.fromPredicates(criteria.toArray(new Predicate[criteria.size()]))).getResults();
    }
    if (!existingVendors.isEmpty()) {
        if (isParent) {
            // ==== CU Customization: Print a different error message that also includes the existing vendor's ID. ====
            if (KFSConstants.SYSTEM_USER.equals(GlobalVariables.getUserSession().getActualPerson().getPrincipalName())) {
                // Only print new message when the actual KFS system user is in place (and not someone backdoored), to keep it specific to batch runs.
                VendorDetail existingVendor = existingVendors.get(0);
                // Parent vendor takes precedence when printing the error message.
                for (int i = 1; !existingVendor.isVendorParentIndicator() && i < existingVendors.size(); i++) {
                    existingVendor = existingVendors.get(i);
                }
                putFieldError(VendorPropertyConstants.VENDOR_TAX_NUMBER, CUVendorKeyConstants.ERROR_VENDOR_TAX_TYPE_AND_NUMBER_COMBO_EXISTS_AND_PRINT_EXISTING, new String[] { existingVendor.getVendorHeaderGeneratedIdentifier().toString(), existingVendor.getVendorDetailAssignedIdentifier().toString() });
            } else {
                // Just use standard KFS-delivered message for general users who are trying to submit a regular vendor maintenance document.
                putFieldError(VendorPropertyConstants.VENDOR_TAX_NUMBER, VendorKeyConstants.ERROR_VENDOR_TAX_TYPE_AND_NUMBER_COMBO_EXISTS);
            }
        } else {
            putFieldError(VendorPropertyConstants.VENDOR_TAX_NUMBER, VendorKeyConstants.ERROR_VENDOR_PARENT_NEEDS_CHANGED);
        }
        valid &= false;
    }
    return valid;
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) ArrayList(java.util.ArrayList) CriteriaLookupService(org.kuali.rice.core.api.criteria.CriteriaLookupService) Predicate(org.kuali.rice.core.api.criteria.Predicate)

Example 22 with VendorDetail

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

the class CuVendorDaoOjb method getSearchResults.

public List<BusinessObject> getSearchResults(Map<String, String> fieldValues) {
    List results = new ArrayList();
    Map<String, VendorDetail> nonDupResults = new HashMap<String, VendorDetail>();
    RemovalAwareCollection rac = new RemovalAwareCollection();
    Criteria header = new Criteria();
    Criteria detail = new Criteria();
    Criteria taxNum = new Criteria();
    Criteria name = new Criteria();
    Criteria alias = new Criteria();
    Criteria active = new Criteria();
    Criteria type = new Criteria();
    Criteria state = new Criteria();
    Criteria commodityCode = new Criteria();
    Criteria supplierDiversity = new Criteria();
    Criteria vendorOwnershipCode = new Criteria();
    Criteria vendorSupplierDiversityExpirationDate = new Criteria();
    String headerVal = fieldValues.get(VendorPropertyConstants.VENDOR_HEADER_GENERATED_ID);
    String detailVal = fieldValues.get(VendorPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID);
    String taxNumVal = fieldValues.get(VendorPropertyConstants.VENDOR_TAX_NUMBER);
    String activeVal = fieldValues.get(ACTIVE_INDICATOR);
    String nameVal = fieldValues.get(VendorPropertyConstants.VENDOR_NAME);
    String typeVal = fieldValues.get(VendorPropertyConstants.VENDOR_TYPE_CODE);
    String stateVal = fieldValues.get(VendorPropertyConstants.VENDOR_ADDRESS + "." + VendorPropertyConstants.VENDOR_ADDRESS_STATE);
    String supplierDiversityVal = fieldValues.get(VendorPropertyConstants.VENDOR_HEADER_PREFIX + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITY_CODE);
    String vendorOwnershipCodeVal = fieldValues.get(VendorPropertyConstants.VENDOR_OWNERSHIP_CODE);
    String commodityCodeVal = fieldValues.get(VendorPropertyConstants.VENDOR_COMMODITIES_CODE_PURCHASING_COMMODITY_CODE);
    String vendorSupplierDiversityExpirationDateVal = fieldValues.get(VendorPropertyConstants.VENDOR_HEADER_PREFIX + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES + "." + CUVendorPropertyConstants.SUPPLIER_DIVERSITY_EXPRIATION);
    // KFSPTS-1891
    String defaultPaymentMethod = fieldValues.get("extension.defaultB2BPaymentMethodCode");
    if (StringUtils.isNotBlank(headerVal)) {
        // 
        header.addEqualTo("vendorHeaderGeneratedIdentifier", headerVal);
    }
    if (StringUtils.isNotBlank(detailVal)) {
        detail.addEqualTo("vendorDetailAssignedIdentifier", detailVal);
        header.addAndCriteria(detail);
    }
    if (StringUtils.isNotBlank(taxNumVal)) {
        // THIS IS ENCRYPTED IN THE DB, COMES OFF HDR TABLE
        taxNum.addEqualTo("vendorHeader.vendorTaxNumber", taxNumVal);
        header.addAndCriteria(taxNum);
    }
    if (StringUtils.isNotBlank(activeVal)) {
        // VNDR_DTL
        active.addEqualTo(ACTIVE_INDICATOR, activeVal);
        header.addAndCriteria(active);
    }
    if (StringUtils.isNotBlank(nameVal) && nameVal.contains("*")) {
        String upperVendorName = getDbPlatform().getUpperCaseFunction() + "( vendorName )";
        String upperNameVal = nameVal.toUpperCase();
        name.addLike(upperVendorName, upperNameVal);
        alias.addLike(getDbPlatform().getUpperCaseFunction() + "( " + VendorPropertyConstants.VENDOR_ALIAS_NAME_FULL_PATH + " )", upperNameVal);
        alias.addEqualTo(VendorPropertyConstants.VENDOR_ALIAS_ACTIVE, "Y");
        Criteria t = new Criteria();
        t.addOrCriteria(name);
        t.addOrCriteria(alias);
        header.addAndCriteria(t);
    }
    if (StringUtils.isNotBlank(nameVal) && !nameVal.contains("*")) {
        name.addEqualTo(VendorPropertyConstants.VENDOR_NAME, nameVal);
        alias.addEqualTo(VendorPropertyConstants.VENDOR_ALIAS_NAME_FULL_PATH, nameVal);
        alias.addEqualTo(VendorPropertyConstants.VENDOR_ALIAS_ACTIVE, "Y");
        Criteria t = new Criteria();
        t.addOrCriteria(name);
        t.addOrCriteria(alias);
        header.addAndCriteria(t);
    }
    if (StringUtils.isNotBlank(typeVal)) {
        // VNDR_HDR
        type.addEqualTo(VendorPropertyConstants.VENDOR_TYPE_CODE, typeVal);
        header.addAndCriteria(type);
    }
    if (StringUtils.isNotBlank(stateVal)) {
        // THIS COMES OUT OF PUR_VND_ADDR_T
        state.addEqualTo(VendorPropertyConstants.VENDOR_ADDRESS_STATE_CODE, stateVal);
        header.addAndCriteria(state);
    }
    if (StringUtils.isNotBlank(commodityCodeVal)) {
        // THIS COMES OUT OF PUR_VNDR_COMM_T
        commodityCode.addEqualTo(VendorPropertyConstants.VENDOR_COMMODITIES_CODE_PURCHASING_COMMODITY_CODE, commodityCodeVal);
        header.addAndCriteria(commodityCode);
    }
    if (StringUtils.isNotBlank(supplierDiversityVal)) {
        // THIS COMES OUT OF PUR_VNDR_SUPP_DVRST_T
        supplierDiversity.addEqualTo(CUVendorPropertyConstants.VENDOR_HEADER_SUPPLIER_DIVERSITY_CODE, supplierDiversityVal);
        header.addAndCriteria(supplierDiversity);
    }
    if (StringUtils.isNotBlank(vendorOwnershipCodeVal)) {
        // VNDR_HDR
        vendorOwnershipCode.addEqualTo(VendorPropertyConstants.VENDOR_OWNERSHIP_CODE, vendorOwnershipCodeVal);
        header.addAndCriteria(vendorOwnershipCode);
    }
    if (StringUtils.isNotBlank(vendorSupplierDiversityExpirationDateVal)) {
        try {
            Date date = new java.sql.Date(new SimpleDateFormat("MM/dd/yyyy").parse(vendorSupplierDiversityExpirationDateVal).getTime());
            vendorSupplierDiversityExpirationDate.addGreaterOrEqualThan(VendorPropertyConstants.VENDOR_HEADER_PREFIX + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES + "." + CUVendorPropertyConstants.SUPPLIER_DIVERSITY_EXPRIATION, date);
            header.addAndCriteria(vendorSupplierDiversityExpirationDate);
        } catch (ParseException e) {
            LOG.error("unable to parse date");
        }
    }
    // KFSPTS-1891
    if (StringUtils.isNotBlank(defaultPaymentMethod)) {
        // 
        header.addEqualTo("extension.defaultB2BPaymentMethodCode", defaultPaymentMethod);
    }
    Long val = new Long(getPersistenceBrokerTemplate().getCount(QueryFactory.newQuery(VendorDetail.class, header)));
    Integer searchResultsLimit = LookupUtils.getSearchResultsLimit(VendorDetail.class);
    if (val.intValue() > searchResultsLimit.intValue()) {
        LookupUtils.applySearchResultsLimit(VendorDetail.class, header, getDbPlatform());
    }
    QueryByCriteria qbc = new QueryByCriteria(VendorDetail.class, header);
    rac = (RemovalAwareCollection) getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
    Criteria children = new Criteria();
    Iterator it = rac.iterator();
    while (it.hasNext()) {
        VendorDetail vd = (VendorDetail) it.next();
        String key = vd.getVendorNumber();
        if (!nonDupResults.containsKey(key)) {
            Criteria c = new Criteria();
            c.addEqualTo("vendorHeaderGeneratedIdentifier", vd.getVendorHeaderGeneratedIdentifier());
            children.addOrCriteria(c);
            nonDupResults.put(key, vd);
            results.add(vd);
        }
    }
    // THE CHILDREN OF ANY MATCHING VENDOR DETAIL OBJECT MUST BE FOUND AND ADDED TO THE RESULTS LIST
    if (nonDupResults.size() > 0) {
        qbc = new QueryByCriteria(VendorDetail.class, children);
        rac = (RemovalAwareCollection) getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
        it = rac.iterator();
        while (it.hasNext()) {
            VendorDetail vd = (VendorDetail) it.next();
            String key = vd.getVendorNumber();
            if (!nonDupResults.containsKey(key)) {
                nonDupResults.put(key, vd);
                results.add(vd);
            }
        }
    }
    CollectionIncomplete resultsTruncated = new CollectionIncomplete((Collection) results, new Long(results.size()));
    if (val.intValue() > searchResultsLimit.intValue()) {
        resultsTruncated.setActualSizeIfTruncated(new Long(-1));
    }
    return resultsTruncated;
}
Also used : CollectionIncomplete(org.kuali.kfs.krad.lookup.CollectionIncomplete) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) QueryByCriteria(org.apache.ojb.broker.query.QueryByCriteria) Criteria(org.apache.ojb.broker.query.Criteria) Date(java.sql.Date) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) QueryByCriteria(org.apache.ojb.broker.query.QueryByCriteria) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) RemovalAwareCollection(org.apache.ojb.broker.util.collections.RemovalAwareCollection)

Example 23 with VendorDetail

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

the class CuVendorMaintainableImpl method saveBusinessObject.

@Override
public void saveBusinessObject() {
    VendorDetail vendorDetail = (VendorDetail) super.getBusinessObject();
    // a  workaround for now.  headerextension's pk is not linked
    populateGeneratedHerderId(vendorDetail.getVendorHeader());
    populateGeneratedAddressId(vendorDetail);
    vendorDetail.setVendorHeaderGeneratedIdentifier(vendorDetail.getVendorHeader().getVendorHeaderGeneratedIdentifier());
    super.saveBusinessObject();
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail)

Example 24 with VendorDetail

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

the class CUVendorServiceImpl method getVendorByNamePlusLastFourOfTaxID.

/**
 */
public VendorDetail getVendorByNamePlusLastFourOfTaxID(String vendorName, String lastFour) {
    LOG.debug("Entering getVendorByNamePlusLastFourOfTaxID for vendorName:" + vendorName + ", last four :" + lastFour);
    // Map criteria = new HashMap();
    // criteria.put(VendorPropertyConstants.VENDOR_NAME, vendorName);
    // List<VendorDetail> vds = (List) businessObjectService.findMatching(VendorDetail.class, criteria);
    HashMap<String, String> attributes = new HashMap<String, String>();
    attributes.put(VendorPropertyConstants.VENDOR_NAME, "*" + vendorName + "*");
    vendorLookupableHelperServiceImpl.setBusinessObjectClass(VendorDetail.class);
    List<VendorDetail> vds = (List) vendorLookupableHelperServiceImpl.getSearchResults(attributes);
    List<VendorDetail> matches = new ArrayList<VendorDetail>();
    for (VendorDetail detail : vds) {
        String taxId = detail.getVendorHeader().getVendorTaxNumber();
        if (StringUtils.isNotBlank(taxId)) {
            String compareTo = taxId.substring(taxId.length() - 4);
            if (StringUtils.equals(lastFour, compareTo)) {
                matches.add(detail);
            }
        }
    }
    LOG.debug("Exiting getVendorByNamePlusLastFourOfTaxID.");
    if (matches.size() > 1 || matches.isEmpty()) {
        return null;
    }
    return matches.get(0);
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 25 with VendorDetail

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

the class CUVendorServiceImpl method getVendorByVendorName.

/**
 *  @see org.kuali.kfs.vnd.document.service.VendorService#getVendorByDunsNumber(String)
 */
public VendorDetail getVendorByVendorName(String vendorName) {
    LOG.info("Entering getVendorByVendorName for vendorName:" + vendorName);
    Map criteria = new HashMap();
    criteria.put(VendorPropertyConstants.VENDOR_NAME, vendorName);
    List<VendorDetail> vds = (List) businessObjectService.findMatching(VendorDetail.class, criteria);
    LOG.debug("Exiting getVendorByVendorName.");
    if (vds.size() < 1) {
        return null;
    } else {
        return vds.get(0);
    }
}
Also used : VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)54 ArrayList (java.util.ArrayList)14 VendorAddress (org.kuali.kfs.vnd.businessobject.VendorAddress)12 Date (java.util.Date)10 List (java.util.List)10 VendorDetailExtension (edu.cornell.kfs.vnd.businessobject.VendorDetailExtension)9 HashMap (java.util.HashMap)9 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)7 VendorHeader (org.kuali.kfs.vnd.businessobject.VendorHeader)7 VendorService (org.kuali.kfs.vnd.document.service.VendorService)7 Iterator (java.util.Iterator)6 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)5 MessageMap (org.kuali.kfs.krad.util.MessageMap)5 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)5 Person (org.kuali.rice.kim.api.identity.Person)5 IOException (java.io.IOException)4 VendorCommodityCode (org.kuali.kfs.vnd.businessobject.VendorCommodityCode)4 VendorContract (org.kuali.kfs.vnd.businessobject.VendorContract)4 VendorSupplierDiversity (org.kuali.kfs.vnd.businessobject.VendorSupplierDiversity)4 FileNotFoundException (java.io.FileNotFoundException)3