1 package org.kuali.ole.deliver.lookup;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.OLEParameterConstants;
5 import org.kuali.ole.deliver.bo.OleItemSearch;
6 import org.kuali.ole.describe.service.DocstoreHelperService;
7 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.Location;
8 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.LocationLevel;
9 import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
10 import org.kuali.rice.krad.lookup.LookupableImpl;
11 import org.kuali.rice.krad.service.KRADServiceLocator;
12 import org.kuali.rice.krad.util.GlobalVariables;
13 import org.kuali.rice.krad.util.KRADConstants;
14 import org.kuali.rice.krad.web.form.LookupForm;
15
16 import java.util.*;
17
18
19
20
21 public class OleItemSearchLookupableImpl extends LookupableImpl {
22
23
24 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleItemSearchLookupableImpl.class);
25
26 @Override
27 public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean bounded) {
28 LOG.debug("Inside performSearch()");
29 DocstoreHelperService docstoreHelperService = new DocstoreHelperService();
30
31 boolean searchFlag = true;
32 for (Map.Entry<String, String> entry : searchCriteria.entrySet()) {
33 if (!entry.getValue().trim().equals("")) {
34 searchFlag = false;
35 break;
36 }
37 }
38 if (searchFlag) {
39 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ITM_BLANK_SEARCH_ERROR_MSG);
40 return new ArrayList<Object>();
41 }
42 searchCriteria.put("rowSize", getParameter(OLEParameterConstants.ITM_SEARCH_DOCSTORE_ROW_SIZE_VALUE));
43 List<OleItemSearch> oleItemSearchList = docstoreHelperService.getOleItemSearchList(searchCriteria);
44 searchCriteria.remove("rowSize");
45
46 if (oleItemSearchList.size() == 0) {
47 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
48 }
49 return oleItemSearchList;
50 }
51
52 private String getShelvingLocation(Location oleLocation) {
53 if (oleLocation == null) {
54 return "";
55 }
56 LocationLevel locationLevel =
57 oleLocation.getLocationLevel();
58 while (locationLevel.getLocationLevel() != null && !locationLevel.getLevel().equalsIgnoreCase(OLEConstants.OleDeliverRequest.SHELVING)) {
59 locationLevel = locationLevel.getLocationLevel();
60 }
61 return locationLevel.getName();
62 }
63
64 public String getHoldingLinkURL(String holdingUuid, String bibUuid) {
65 String url = "";
66 try {
67 url = "editorcontroller?viewId=EditorView&methodToCall=load&docCategory=work&docType=holdings&editable=false&docFormat=oleml&docId=" + holdingUuid + "&bibId=" + bibUuid;
68 } catch (Exception e) {
69 LOG.error(e, e);
70 }
71 return url;
72 }
73
74 public String getParameter(String name) {
75 String parameter = "";
76 try {
77 Map<String, String> criteriaMap = new HashMap<String, String>();
78 criteriaMap.put("namespaceCode", OLEConstants.DLVR_NMSPC);
79 criteriaMap.put("componentCode", OLEConstants.DLVR_CMPNT);
80 criteriaMap.put("name", name);
81 List<ParameterBo> parametersList = (List<ParameterBo>) KRADServiceLocator.getBusinessObjectService().findMatching(ParameterBo.class, criteriaMap);
82 for (ParameterBo parameterBo : parametersList) {
83 parameter = parameterBo.getValue();
84 }
85 } catch (Exception e) {
86 LOG.error(e, e);
87 }
88 return parameter;
89 }
90
91 }