use of org.apache.ojb.broker.util.collections.RemovalAwareCollection 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;
}
Aggregations