View Javadoc

1   package org.kuali.ole.select.lookup;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.deliver.lookup.OleItemSearchLookupableImpl;
5   import org.kuali.ole.describe.service.DocstoreHelperService;
6   import org.kuali.ole.select.bo.OLEInstanceSearch;
7   import org.kuali.rice.krad.lookup.LookupableImpl;
8   import org.kuali.rice.krad.util.GlobalVariables;
9   import org.kuali.rice.krad.util.KRADConstants;
10  import org.kuali.rice.krad.util.ObjectUtils;
11  import org.kuali.rice.krad.web.form.LookupForm;
12  
13  import java.util.ArrayList;
14  import java.util.Collection;
15  import java.util.List;
16  import java.util.Map;
17  
18  /**
19   * Created with IntelliJ IDEA.
20   * User: arunag
21   * Date: 7/4/13
22   * Time: 11:33 AM
23   * To change this template use File | Settings | File Templates.
24   */
25  public class OLEInstanceSearchLookupableImpl extends LookupableImpl {
26  
27  
28      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleItemSearchLookupableImpl.class);
29  
30      @Override
31      public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean bounded) {
32          LOG.debug("Inside performSearch()");
33          DocstoreHelperService docstoreHelperService = new DocstoreHelperService();
34  
35          boolean searchFlag = true;
36          for (Map.Entry<String, String> entry : searchCriteria.entrySet()) {
37              if (!entry.getValue().trim().equals("")) {
38                  searchFlag = false;
39                  break;
40              }
41          }
42          if (searchFlag) {
43              GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.INSTANCE_BLANK_SEARCH_ERROR_MSG);
44              return new ArrayList<Object>();
45          }
46  
47          List<OLEInstanceSearch> oleInstanceSearchList = docstoreHelperService.getOleInstanceSearchList(searchCriteria);
48  
49          List<OLEInstanceSearch> finalOleInstanceSearchList = new ArrayList<OLEInstanceSearch>();
50  
51          OLEInstanceSearch instanceSearch = null;
52          String location = null;
53          for (OLEInstanceSearch oleInstanceSearch : oleInstanceSearchList) {
54              for (String instanceId : oleInstanceSearch.getInstanceIdList()) {
55                  if (oleInstanceSearch.getInstanceIdList().size() > 0) {
56                      instanceSearch = (OLEInstanceSearch) ObjectUtils.deepCopy(oleInstanceSearch);
57                  } else {
58                      instanceSearch = oleInstanceSearch;
59                  }
60                  instanceSearch.setInstanceId(instanceId);
61                  location = docstoreHelperService.getInstanceLocation(instanceId);
62                  instanceSearch.setLocation(location);
63                  CharSequence instancePrefix = "wno";
64                  if(instanceSearch.getInstanceId().contains(instancePrefix)){
65                      finalOleInstanceSearchList.add(instanceSearch);
66                  }
67              }
68          }
69          if (finalOleInstanceSearchList.size() == 0) {
70              GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
71          }
72          return finalOleInstanceSearchList;
73      }
74  
75  
76  }