1 package org.kuali.ole.license.lookup;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.license.bo.OleLicenseRequestBo;
6 import org.kuali.ole.license.bo.OleLicenseRequestItemTitle;
7 import org.kuali.ole.license.controller.LicenceRoutingRuleDelegationMaintainable;
8 import org.kuali.ole.service.OleLicenseRequestService;
9 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
10 import org.kuali.rice.kew.doctype.bo.DocumentType;
11 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
12 import org.kuali.rice.krad.lookup.LookupableImpl;
13 import org.kuali.rice.krad.service.BusinessObjectService;
14 import org.kuali.rice.krad.service.KRADServiceLocator;
15 import org.kuali.rice.krad.uif.UifConstants;
16 import org.kuali.rice.krad.uif.UifParameters;
17 import org.kuali.rice.krad.uif.view.LookupView;
18 import org.kuali.rice.krad.util.*;
19 import org.kuali.rice.krad.web.form.LookupForm;
20
21 import java.text.SimpleDateFormat;
22 import java.util.*;
23
24
25
26
27 public class OleLicenseRequestLookupableImpl extends LookupableImpl {
28
29 private OleLicenseRequestService oleLicenseRequestService;
30
31 private String returnLocation ="";
32
33
34
35
36
37 public String getReturnLocation() {
38 return returnLocation;
39 }
40
41
42
43
44
45 public void setReturnLocation(String returnLocation) {
46 this.returnLocation = returnLocation;
47 }
48
49
50
51
52
53
54
55
56 @Override
57 protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall,
58 List<String> pkNames) {
59 LookupView lookupView = (LookupView) lookupForm.getView();
60
61 Properties props = new Properties();
62 props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
63
64 Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject);
65 for (String primaryKey : primaryKeyValues.keySet()) {
66 String primaryKeyValue = primaryKeyValues.get(primaryKey);
67
68 props.put(primaryKey, primaryKeyValue);
69 }
70
71 if (StringUtils.isNotBlank(lookupForm.getReturnLocation())) {
72 props.put(KRADConstants.RETURN_LOCATION_PARAMETER, lookupForm.getReturnLocation());
73 returnLocation = lookupForm.getReturnLocation();
74 }
75
76 props.put(UifParameters.DATA_OBJECT_CLASS_NAME, lookupForm.getDataObjectClassName());
77 props.put(UifParameters.VIEW_TYPE_NAME, UifConstants.ViewType.MAINTENANCE.name());
78
79 String maintenanceMapping = "oleLicenseRequest";
80
81 return UrlFactory.parameterizeUrl(maintenanceMapping, props);
82 }
83
84
85
86
87
88
89
90
91 @Override
92 public Collection<?> performSearch(LookupForm form, Map<String, String> criteria, boolean bounded) {
93 returnLocation = form.getReturnLocation();
94 SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
95 String createdDateFrom = criteria.get(OLEConstants.OleLicenseRequest.CREATED_FROM_DATE);
96 String createdDateTo = criteria.get(OLEConstants.OleLicenseRequest.CREATED_TO_DATE);
97 String lastModifiedDateFrom = criteria.get(OLEConstants.OleLicenseRequest.LAST_MOD_FROM_DATE);
98 String lastModifiedDateTo = criteria.get(OLEConstants.OleLicenseRequest.LAST_MOD_TO_DATE);
99
100
101
102
103
104
105 if(!createdDateFrom.equalsIgnoreCase("") && !createdDateTo.equalsIgnoreCase("")) {
106 if (createdDateFrom.compareTo(createdDateTo) >0) {
107 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleLicenseRequest.ERROR_DATE_FROM_EXCEEDS_DATE_TO);
108 return Collections.emptyList();
109 }
110 }
111 if(!lastModifiedDateFrom.equalsIgnoreCase("") && !lastModifiedDateTo.equalsIgnoreCase("")) {
112 if (lastModifiedDateFrom.compareTo(lastModifiedDateTo) >0) {
113 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OleLicenseRequest.ERROR_DATE_FROM_EXCEEDS_DATE_TO);
114 return Collections.emptyList();
115 }
116 }
117
118
119
120
121 Collection<?> displayList = getOleLicenseRequestservice().findLicenseRequestByCriteria(criteria);
122 if(displayList.size()==0){
123 GlobalVariables.getMessageMap().putInfo(OLEConstants.OleLicenseRequest.ERROR_NOT_FOUND,OLEConstants.OleLicenseRequest.ERROR_NOT_FOUND);
124 }
125 return displayList;
126
127 }
128
129
130
131
132
133
134
135 public String viewParticularDocument(Object object) {
136 OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo)object;
137 String url = "";
138 if(returnLocation != null & !returnLocation.isEmpty())
139 url = returnLocation.substring(0,returnLocation.indexOf("portal.do"));
140 return url +"kew/DocHandler.do?command=displayDocSearchView&docId="+oleLicenseRequestBo.getDocumentNumber();
141 }
142
143
144
145
146
147 public OleLicenseRequestService getOleLicenseRequestservice() {
148 if(oleLicenseRequestService == null ) {
149 oleLicenseRequestService = GlobalResourceLoader.getService("oleLicenseRequestService");
150 }
151 return oleLicenseRequestService;
152 }
153
154 }