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