1 package org.kuali.ole.deliver.lookup;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
6 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
7 import org.kuali.ole.sys.context.SpringContext;
8 import org.kuali.ole.util.DocstoreUtil;
9 import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
10 import org.kuali.rice.krad.lookup.LookupableImpl;
11 import org.kuali.rice.krad.service.KRADServiceLocator;
12 import org.kuali.rice.krad.uif.UifConstants;
13 import org.kuali.rice.krad.uif.UifParameters;
14 import org.kuali.rice.krad.uif.view.LookupView;
15 import org.kuali.rice.krad.util.GlobalVariables;
16 import org.kuali.rice.krad.util.KRADConstants;
17 import org.kuali.rice.krad.util.KRADUtils;
18 import org.kuali.rice.krad.util.UrlFactory;
19 import org.kuali.rice.krad.web.form.LookupForm;
20
21 import java.util.*;
22
23
24
25
26
27
28
29
30
31 public class OleDeliverRequestLookupableImpl extends LookupableImpl {
32 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleDeliverRequestLookupableImpl.class);
33 private OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService = new OleDeliverRequestDocumentHelperServiceImpl();
34 private String itemTitle;
35
36 private String firstName;
37 private String lastName;
38 private String itemId;
39 private String borrowerId;
40 private String borrowerBarcode;
41 private DocstoreUtil docstoreUtil;
42 public DocstoreUtil getDocstoreUtil() {
43
44 if (docstoreUtil == null) {
45 docstoreUtil = SpringContext.getBean(DocstoreUtil.class);
46
47 }
48 return docstoreUtil;
49 }
50
51
52 @Override
53 protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall,
54 List<String> pkNames) {
55 LOG.debug("Inside getActionUrlHref()");
56 LookupView lookupView = (LookupView) lookupForm.getView();
57
58 Properties props = new Properties();
59 props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
60 Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
61 for (String primaryKey : primaryKeyValues.keySet()) {
62 String primaryKeyValue = primaryKeyValues.get(primaryKey);
63
64 props.put(primaryKey, primaryKeyValue);
65 }
66
67 if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
68 props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
69 }
70
71 props.put(UifParameters.DATA_OBJECT_CLASS_NAME, OleDeliverRequestBo.class.getName());
72 props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
73
74 String maintenanceMapping = OLEConstants.OleDeliverRequest.DELIVER_REQUEST_MAINTENANCE_ACTION_LINK;
75
76 return UrlFactory.parameterizeUrl(maintenanceMapping, props);
77 }
78
79
80 @Override
81 public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean bounded) {
82 LOG.debug("Inside performSearch()");
83 Map<String, String> lookupcriteria = form.getLookupCriteria();
84 HashMap<String, String> requestParameters = (HashMap<String, String>) form.getInitialRequestParameters();
85 if (requestParameters.containsKey(OLEConstants.OleDeliverRequest.FLAG)) {
86 if (requestParameters.get(OLEConstants.OleDeliverRequest.FLAG).equalsIgnoreCase("true")) {
87 String id = requestParameters.get(OLEConstants.OleDeliverRequest.ITEM_ID);
88 searchCriteria.put(OLEConstants.OleDeliverRequest.ITEM_ID, id);
89 lookupcriteria.put(OLEConstants.OleDeliverRequest.ITEM_ID, id);
90 form.setLookupCriteria(lookupcriteria);
91 }
92 }
93 itemTitle = searchCriteria.get(OLEConstants.TITLE) != null ? searchCriteria.get(OLEConstants.TITLE) : "";
94
95 firstName = searchCriteria.get(OLEConstants.OlePatron.PATRON_FIRST_NAME) != null ? searchCriteria.get(OLEConstants.OlePatron.PATRON_FIRST_NAME) : "";
96 lastName = searchCriteria.get(OLEConstants.OlePatron.PATRON_LAST_NAME) != null ? searchCriteria.get(OLEConstants.OlePatron.PATRON_LAST_NAME) : "";
97 itemId = searchCriteria.get(OLEConstants.OleDeliverRequest.ITEM_ID) != null ? searchCriteria.get(OLEConstants.OleDeliverRequest.ITEM_ID) : "";
98 borrowerId = searchCriteria.get(OLEConstants.OleDeliverRequest.BORROWER_ID) != null ? searchCriteria.get(OLEConstants.OleDeliverRequest.BORROWER_ID) : "";
99 borrowerBarcode = searchCriteria.get(OLEConstants.OleDeliverRequest.BORROWER_BARCODE) != null ? searchCriteria.get(OLEConstants.OleDeliverRequest.BORROWER_BARCODE) : "";
100
101
102
103
104
105 searchCriteria.remove(OLEConstants.TITLE);
106 searchCriteria.remove(OLEConstants.OlePatron.PATRON_FIRST_NAME);
107 searchCriteria.remove(OLEConstants.OlePatron.PATRON_LAST_NAME);
108 List<OleDeliverRequestBo> displayList = new ArrayList<OleDeliverRequestBo>();
109
110 List<EntityNameBo> entityNameBos = new ArrayList<EntityNameBo>();
111
112 String modifiedBorrowerFirstName = firstName.trim();
113 String modifiedBorrowerLastName = lastName.trim();
114
115
116
117
118
119 if ((borrowerBarcode.equals("")) && (!modifiedBorrowerFirstName.equals("") || !modifiedBorrowerLastName.equals(""))) {
120 Map<String, String> patronMap = new HashMap<String, String>();
121 if (!modifiedBorrowerFirstName.equals("") && modifiedBorrowerFirstName != null) {
122 patronMap.put(OLEConstants.OlePatron.PATRON_FIRST_NAME, modifiedBorrowerFirstName);
123 }
124 if (!modifiedBorrowerLastName.equals("") && modifiedBorrowerLastName != null) {
125 patronMap.put(OLEConstants.OlePatron.PATRON_LAST_NAME, modifiedBorrowerLastName);
126 }
127
128 entityNameBos = (List<EntityNameBo>) getLookupService().findCollectionBySearchHelper(EntityNameBo.class, patronMap, true);
129
130 if (entityNameBos.size() == 0) {
131 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
132 }
133 if (entityNameBos.size() > 0) {
134 for (int i = 0; i < entityNameBos.size(); i++) {
135
136 searchCriteria.put(OLEConstants.OleDeliverRequest.BORROWER_ID, entityNameBos.get(i).getEntityId());
137 displayList.addAll((List<OleDeliverRequestBo>) super.performSearch(form, searchCriteria, bounded));
138 searchCriteria.remove(OLEConstants.OleDeliverRequest.BORROWER_ID);
139 }
140 }
141 } else {
142 displayList = (List<OleDeliverRequestBo>) super.performSearch(form, searchCriteria, bounded);
143 }
144 searchCriteria.put(OLEConstants.TITLE, itemTitle);
145
146 searchCriteria.put(OLEConstants.OlePatron.PATRON_FIRST_NAME, firstName);
147 searchCriteria.put(OLEConstants.OlePatron.PATRON_LAST_NAME, lastName);
148
149 OleDeliverRequestBo oleDeliverRequestBo;
150 List<OleDeliverRequestBo> oleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
151 try {
152 for (int i = 0; i < displayList.size(); i++) {
153 displayList.get(i).setItemType(null);
154 oleDeliverRequestBo = displayList.get(i);
155
156 getDocstoreUtil().isItemAvailableInDocStore(oleDeliverRequestBo);
157 if (itemTitle != null && !itemTitle.isEmpty() && !oleDeliverRequestBo.getTitle().toUpperCase().equals(itemTitle.toUpperCase())) {
158
159 } else {
160 Map<String, String> patronMap = new HashMap<String, String>();
161 patronMap.put(OLEConstants.OlePatron.PATRON_FIRST_NAME, displayList.get(i).getFirstName());
162 patronMap.put(OLEConstants.OlePatron.PATRON_LAST_NAME, displayList.get(i).getLastName());
163 entityNameBos = (List<EntityNameBo>) KRADServiceLocator.getBusinessObjectService().findMatching(EntityNameBo.class, patronMap);
164 if (entityNameBos.size() > 0) {
165 displayList.get(i).setFirstName(displayList.get(i).getFirstName());
166 displayList.get(i).setLastName(displayList.get(i).getLastName());
167 }
168 oleDeliverRequestBoList.add(displayList.get(i));
169 }
170
171 }
172 } catch (Exception e) {
173 LOG.error("Not able to retrieve data:" + e.getMessage(), e);
174 }
175 if (oleDeliverRequestBoList.size() == 0) {
176 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
177 }
178
179 return oleDeliverRequestBoList;
180 }
181
182 }
183
184