1 package org.kuali.ole.select.lookup;
2
3
4 import org.hsqldb.lib.StringUtil;
5 import org.kuali.ole.DocumentUniqueIDPrefix;
6 import org.kuali.ole.OleLookupableImpl;
7 import org.kuali.ole.select.businessobject.OLEPurchaseOrderItemSearch;
8 import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
9 import org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl;
10 import org.kuali.rice.krad.bo.BusinessObject;
11 import org.kuali.rice.krad.lookup.LookupableImpl;
12 import org.kuali.rice.krad.web.form.LookupForm;
13
14 import java.util.*;
15
16 public class OLEPurchaseOrderItemLookupableHelperServiceImpl extends OleLookupableImpl {
17
18 protected List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {
19 Map<String, String> criteria = new HashMap<String, String>();
20 List<OLEPurchaseOrderItemSearch> searchResults = new ArrayList<OLEPurchaseOrderItemSearch>();
21 List<OlePurchaseOrderItem> purchaseOrderItems = new ArrayList<OlePurchaseOrderItem>();
22 if(searchCriteria.get("vendorDetailAssignedIdentifier")!=null && !searchCriteria.get("vendorDetailAssignedIdentifier").isEmpty()){
23 criteria.put("purchaseOrder.vendorDetailAssignedIdentifier",searchCriteria.get("vendorDetailAssignedIdentifier"));
24 }
25 if(searchCriteria.get("vendorHeaderGeneratedIdentifier")!=null && !searchCriteria.get("vendorHeaderGeneratedIdentifier").isEmpty()){
26 criteria.put("purchaseOrder.vendorHeaderGeneratedIdentifier",searchCriteria.get("vendorHeaderGeneratedIdentifier"));
27 }
28 if (StringUtil.isEmpty(searchCriteria.get("purapDocumentIdentifier"))) {
29 purchaseOrderItems = (List<OlePurchaseOrderItem>)getBusinessObjectService().findMatching(OlePurchaseOrderItem.class, criteria);
30 }
31 else if(isNumber(searchCriteria.get("purapDocumentIdentifier"))){
32 if(searchCriteria.get("purapDocumentIdentifier")!=null && !searchCriteria.get("purapDocumentIdentifier").isEmpty()){
33 criteria.put("purchaseOrder.purapDocumentIdentifier",searchCriteria.get("purapDocumentIdentifier"));
34 }
35 purchaseOrderItems = (List<OlePurchaseOrderItem>)getBusinessObjectService().findMatching(OlePurchaseOrderItem.class,criteria);
36 }
37 OLEPurchaseOrderItemSearch poItemSearch;
38 for (OlePurchaseOrderItem poItem : purchaseOrderItems) {
39 if (poItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
40 if(poItem.getItemTitleId()!=null){
41 poItem.setDocFormat(DocumentUniqueIDPrefix.getBibFormatType(poItem.getItemTitleId()));
42 }
43 poItemSearch = new OLEPurchaseOrderItemSearch();
44 poItemSearch.setPurchaseOrderItemID(poItem.getItemIdentifier());
45 poItemSearch.setPurapDocumentIdentifier(poItem.getPurapDocument() != null &&
46 poItem.getPurapDocument().getPurapDocumentIdentifier() != null ? poItem.getPurapDocument().getPurapDocumentIdentifier().toString() : "");
47 poItemSearch.setTempItemIdentifier(poItem.getItemIdentifier());
48 poItemSearch.setItemDescription(poItem.getItemDescription());
49 poItemSearch.setLocalId(poItem.getItemTitleId());
50 poItemSearch.setAccountsPayableLinkIdentifier(poItem.getPurapDocument() != null &&
51 poItem.getPurapDocument().getAccountsPayablePurchasingDocumentLinkIdentifier() != null ?
52 poItem.getPurapDocument().getAccountsPayablePurchasingDocumentLinkIdentifier() : Integer.valueOf("0"));
53 poItemSearch.setPoItemPrice(poItem.getExtendedPrice() != null ? poItem.getExtendedPrice().toString() : "0.00");
54 poItemSearch.setItemLineNumber(poItem.getItemLineNumber());
55 poItemSearch.setDocFormat(poItem.getDocFormat());
56 searchResults.add(poItemSearch);
57 }
58 }
59 return searchResults;
60 }
61 public static boolean isNumber(String actionInterval) {
62 String actStr = actionInterval;
63 for (int i = 0; i < actStr.length(); i++) {
64 if (!Character.isDigit(actStr.charAt(i)))
65 return false;
66 }
67 return true;
68 }
69
70 @Override
71 public Map<String, String> performClear(LookupForm form, Map<String, String> searchCriteria) {
72 super.performClear(form,searchCriteria);
73
74 Map<String, String> clearedSearchCriteria = new HashMap<String, String>();
75 for (Map.Entry<String, String> searchKeyValue : searchCriteria.entrySet()) {
76 String searchPropertyName = searchKeyValue.getKey();
77 if(searchPropertyName.equals("vendorDetailAssignedIdentifier") ||
78 searchPropertyName.equals("vendorHeaderGeneratedIdentifier") ||
79 searchPropertyName.equals("vendorName")) {
80 clearedSearchCriteria.put(searchPropertyName,searchKeyValue.getValue());
81 }
82 }
83 return clearedSearchCriteria;
84 }
85 }