1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.docsearch;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Set;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.rice.core.util.KeyValue;
24 import org.kuali.rice.core.util.ConcreteKeyValue;
25 import org.kuali.rice.kew.doctype.ApplicationDocumentStatus;
26 import org.kuali.rice.kew.doctype.bo.DocumentType;
27 import org.kuali.rice.kew.engine.node.RouteNode;
28 import org.kuali.rice.kew.lookup.valuefinder.DocumentRouteStatusValuesFinder;
29 import org.kuali.rice.kew.service.KEWServiceLocator;
30 import org.kuali.rice.kew.util.KEWConstants;
31 import org.kuali.rice.kns.service.DataDictionaryService;
32 import org.kuali.rice.kns.util.FieldUtils;
33 import org.kuali.rice.kns.web.ui.Field;
34 import org.kuali.rice.kns.web.ui.Row;
35
36
37
38
39
40
41
42 public class DocumentLookupCriteriaProcessorKEWAdapter implements
43 DocumentLookupCriteriaProcessor {
44 DocumentSearchCriteriaProcessor criteriaProcessor;
45
46 DataDictionaryService dataDictionaryService;
47
48
49
50
51 public DocumentSearchCriteriaProcessor getCriteriaProcessor() {
52 return this.criteriaProcessor;
53 }
54
55 public void setCriteriaProcessor(
56 DocumentSearchCriteriaProcessor criteriaProcessor) {
57 this.criteriaProcessor = criteriaProcessor;
58 }
59
60 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
61 this.dataDictionaryService = dataDictionaryService;
62 }
63
64
65
66
67 public List<Row> getRows(DocumentType documentType, List<Row> knsRows, boolean detailed, boolean superSearch) {
68 List<Row> rows = new ArrayList<Row>();
69
70 List<Row> searchAttRows = new ArrayList<Row>();
71 List<List<StandardDocSearchCriteriaFieldContainer>> preSearchAttFields;
72 if(!detailed) {
73 preSearchAttFields = criteriaProcessor.getBasicSearchManager().getColumnsPreSearchAttributes();
74 } else {
75 preSearchAttFields = criteriaProcessor.getAdvancedSearchManager().getColumnsPreSearchAttributes();
76 }
77 List<Row> preSearchAttRows = standardNonSearchAttRows(documentType,preSearchAttFields);
78
79 rows.addAll(preSearchAttRows);
80
81
82 if(documentType!=null) {
83
84
85 searchAttRows = searchAttRows(documentType);
86 rows.addAll(searchAttRows);
87 }
88
89
90 List<List<StandardDocSearchCriteriaFieldContainer>> postSearchAttFields;
91 if(!detailed) {
92 postSearchAttFields = criteriaProcessor.getBasicSearchManager().getColumnsPostSearchAttributes();
93 } else {
94 postSearchAttFields = criteriaProcessor.getAdvancedSearchManager().getColumnsPostSearchAttributes();
95 }
96
97
98 List<Row> postSearchAttRows = standardNonSearchAttRows(documentType,postSearchAttFields);
99 rows.addAll(postSearchAttRows);
100
101 Row hidrow = new Row();
102 hidrow.setHidden(true);
103 Field detailedField = new Field();
104 detailedField.setPropertyName("isAdvancedSearch");
105 detailedField.setPropertyValue(detailed?"YES":"NO");
106 detailedField.setFieldType(Field.HIDDEN);
107 Field superUserSearchField = new Field();
108 superUserSearchField.setPropertyName("superUserSearch");
109 superUserSearchField.setPropertyValue(superSearch?"YES":"NO");
110 superUserSearchField.setFieldType(Field.HIDDEN);
111 List<Field> hidFields = new ArrayList<Field>();
112 hidFields.add(detailedField);
113 hidFields.add(superUserSearchField);
114 hidrow.setFields(hidFields);
115 rows.add(hidrow);
116
117 return rows;
118 }
119
120
121
122
123
124
125
126 protected List<Row> standardNonSearchAttRows(DocumentType documentType, List<List<StandardDocSearchCriteriaFieldContainer>> fields) {
127 List<Row> customPreRows = new ArrayList<Row>();
128 for (List<StandardDocSearchCriteriaFieldContainer> list : fields) {
129
130
131 for (StandardDocSearchCriteriaFieldContainer standardDocSearchCriteriaFieldContainer : list) {
132 List<StandardSearchCriteriaField> standardSearchCriteriaFields = standardDocSearchCriteriaFieldContainer.getFields();
133 for (StandardSearchCriteriaField standardSearchCriteriaField : standardSearchCriteriaFields) {
134
135 Row row = new Row();
136 List<Field>knsFields = new ArrayList<Field>();
137 Field field = new Field();
138 boolean skipadd = false;
139
140 String propertyName = "";
141 if(StringUtils.contains(standardSearchCriteriaField.getProperty(), ".")) {
142 propertyName = StringUtils.substringAfterLast(standardSearchCriteriaField.getProperty(), ".");
143 } else {
144 propertyName = standardSearchCriteriaField.getProperty();
145 }
146
147 field.setPropertyName(propertyName);
148
149
150
151 String fieldType = standardSearchCriteriaField.getFieldType();
152
153 String lookupableImplServiceName = standardSearchCriteriaField.getLookupableImplServiceName();
154 if(lookupableImplServiceName!=null) {
155 if(StringUtils.equals("DocumentTypeLookupableImplService", lookupableImplServiceName)) {
156 fieldType = Field.TEXT;
157 field.setWebOnBlurHandler("validateDocTypeAndRefresh");
158
159 field.setQuickFinderClassNameImpl("org.kuali.rice.kew.doctype.bo.DocumentType");
160 field.setFieldConversions("name:"+propertyName);
161 } else if (StringUtils.equals("UserLookupableImplService", lookupableImplServiceName)) {
162 fieldType = Field.TEXT;
163 field.setQuickFinderClassNameImpl("org.kuali.rice.kim.bo.impl.PersonImpl");
164 field.setFieldConversions("principalName:"+propertyName);
165 } else if (StringUtils.equals("WorkGroupLookupableImplService", lookupableImplServiceName)) {
166 field.setQuickFinderClassNameImpl("org.kuali.rice.kim.bo.impl.GroupImpl");
167 fieldType = Field.LOOKUP_READONLY;
168 field.setFieldConversions("groupName:"+propertyName+","+"groupId:"+StandardDocumentSearchCriteriaProcessor.CRITERIA_KEY_WORKGROUP_VIEWER_ID);
169 }
170 }
171 boolean fieldHidden = standardSearchCriteriaField.isHidden();
172 if(fieldHidden) {
173 fieldType = Field.HIDDEN;
174 row.setHidden(true);
175 }
176 field.setFieldType(fieldType);
177
178
179 Integer maxLen = dataDictionaryService.getAttributeMaxLength(DocSearchCriteriaDTO.class, propertyName);
180 if(maxLen != null){
181 field.setMaxLength(maxLen.intValue());
182 }
183 else{
184 field.setMaxLength(40);
185 }
186
187
188 if(StringUtils.equals(StandardSearchCriteriaField.DROPDOWN,fieldType)||
189 StringUtils.equals(StandardSearchCriteriaField.DROPDOWN_HIDE_EMPTY, fieldType)){
190 if(StringUtils.equals(StandardSearchCriteriaField.DROPDOWN_HIDE_EMPTY,fieldType)) {
191
192 field.setFieldType(Field.DROPDOWN);
193 field.setSkipBlankValidValue(true);
194
195 }
196
197 if("documentRouteStatus".equalsIgnoreCase(standardSearchCriteriaField.getOptionsCollectionProperty())) {
198 DocumentRouteStatusValuesFinder values = new DocumentRouteStatusValuesFinder();
199 field.setFieldValidValues(values.getKeyValues());
200 field.setFieldType(Field.MULTISELECT);
201 int size = (values.getKeyValues().size() > 10)?10:values.getKeyValues().size();
202 field.setMaxLength(size);
203 } else if("routeNodes".equalsIgnoreCase(standardSearchCriteriaField.getOptionsCollectionProperty())){
204 if(documentType!=null) {
205
206 List<KeyValue> keyValues = new ArrayList<KeyValue>();
207 List<RouteNode> routeNodes = KEWServiceLocator.getRouteNodeService().getFlattenedNodes(documentType, true);
208 for (RouteNode routeNode : routeNodes) {
209 keyValues.add(new ConcreteKeyValue(routeNode.getRouteNodeId()+"",routeNode.getRouteNodeName()));
210 }
211 field.setFieldValidValues(keyValues);
212
213 field.setSkipBlankValidValue(false);
214 } else {
215 field.setFieldType(Field.READONLY);
216 }
217 } else if("qualifierLogic".equalsIgnoreCase(standardSearchCriteriaField.getOptionsCollectionProperty())){
218 if(documentType==null){
219
220 skipadd=true;
221 }
222
223 List<KeyValue> keyValues = new ArrayList<KeyValue>();
224 Set<String> docStatusKeys = KEWConstants.DOC_SEARCH_ROUTE_STATUS_QUALIFIERS.keySet();
225 for (String string : docStatusKeys) {
226 KeyValue keyLabel = new ConcreteKeyValue(string,KEWConstants.DOC_SEARCH_ROUTE_STATUS_QUALIFIERS.get(string));
227 keyValues.add(keyLabel);
228 }
229 field.setFieldValidValues(keyValues);
230 } else if("validApplicationStatuses".equalsIgnoreCase(standardSearchCriteriaField.getOptionsCollectionProperty())){
231 if(documentType!=null) {
232
233 List<KeyValue> keyValues = new ArrayList<KeyValue>();
234 List<ApplicationDocumentStatus> validStatuses = documentType.getValidApplicationStatuses();
235 for (ApplicationDocumentStatus appStatus : (List<ApplicationDocumentStatus>) validStatuses) {
236 keyValues.add(new ConcreteKeyValue(appStatus.getStatusName(),appStatus.getStatusName()));
237 }
238 field.setFieldValidValues(keyValues);
239
240 field.setSkipBlankValidValue(false);
241 } else {
242 field.setFieldType(Field.READONLY);
243 skipadd=true;
244 }
245
246 } else {
247 field.setFieldValidValues(new ArrayList<KeyValue>());
248 }
249 }
250
251
252 if(StringUtils.isEmpty(field.getFieldLabel())) {
253 String labelMessageKey = dataDictionaryService.getAttributeLabel(DocSearchCriteriaDTO.class,propertyName);
254 field.setFieldLabel(labelMessageKey);
255 }
256
257 boolean hasDatePicker = StringUtils.isNotEmpty(standardSearchCriteriaField.getDatePickerKey());
258 field.setDatePicker(hasDatePicker);
259
260 if(!skipadd) {
261 knsFields.add(field);
262 row.setFields(knsFields);
263 customPreRows.add(row);
264 }
265 }
266 }
267 }
268 return customPreRows;
269 }
270
271
272
273
274
275
276
277 protected List<Row> searchAttRows(DocumentType documentType) {
278 List<Row> customSearchAttRows = new ArrayList<Row>();
279 List<SearchableAttribute> searchAtts = documentType.getSearchableAttributes();
280 for (SearchableAttribute searchableAttribute : searchAtts) {
281 DocumentSearchContext documentSearchContext = DocSearchUtils.getDocumentSearchContext("", documentType.getName(), "");
282 customSearchAttRows.addAll(searchableAttribute.getSearchingRows(documentSearchContext));
283 }
284 List<Row> fixedCustomSearchAttRows = new ArrayList<Row>();
285 for (Row row : customSearchAttRows) {
286 List<Field> fields = row.getFields();
287 for (Field field : fields) {
288
289 if(field.getMaxLength()==0) {
290 field.setMaxLength(100);
291 }
292 if(field.isDatePicker() && field.isRanged()) {
293 Field newDate = FieldUtils.createRangeDateField(field);
294 List<Field> newFields = new ArrayList<Field>();
295 newFields.add(newDate);
296 fixedCustomSearchAttRows.addAll(FieldUtils.wrapFields(newFields));
297 }
298 }
299 fixedCustomSearchAttRows.add(row);
300 }
301
302
303
304
305
306 fixedCustomSearchAttRows.addAll( buildAppDocStatusRows(documentType) );
307
308 return fixedCustomSearchAttRows;
309 }
310
311
312
313
314
315
316 protected List<Row> buildAppDocStatusRows(DocumentType documentType){
317 List<Row> appDocStatusRows = new ArrayList<Row>();
318 List<List<StandardDocSearchCriteriaFieldContainer>> columnList = new ArrayList<List<StandardDocSearchCriteriaFieldContainer>>();
319 List<StandardDocSearchCriteriaFieldContainer> columns = new ArrayList<StandardDocSearchCriteriaFieldContainer>();
320 if (documentType.isAppDocStatusInUse()){
321 StandardDocSearchCriteriaFieldContainer container = new StandardDocSearchCriteriaFieldContainer();
322
323 List<ApplicationDocumentStatus> validStatuses = documentType.getValidApplicationStatuses();
324 if (validStatuses == null || validStatuses.size() == 0){
325
326 container = new StandardDocSearchCriteriaFieldContainer("docSearch.DocumentSearch.criteria.label.appDocStatus", new StandardSearchCriteriaField(DocumentSearchCriteriaProcessor.CRITERIA_KEY_APP_DOC_STATUS,"criteria.appDocStatus",StandardSearchCriteriaField.TEXT,null,null,"DocSearchApplicationDocStatus",false,null,null,false));
327
328 } else {
329
330 container.setLabelMessageKey("docSearch.DocumentSearch.criteria.label.appDocStatus");
331 container.setFieldKey(DocumentSearchCriteriaProcessor.CRITERIA_KEY_APP_DOC_STATUS);
332 StandardSearchCriteriaField dropDown = new StandardSearchCriteriaField(DocumentSearchCriteriaProcessor.CRITERIA_KEY_APP_DOC_STATUS + "_VALUES","criteria.appDocStatus",StandardSearchCriteriaField.DROPDOWN_HIDE_EMPTY,null,null,"DocSearchApplicationDocStatus",false,null,null,false);
333
334 dropDown.setOptionsCollectionProperty("validApplicationStatuses");
335 dropDown.setCollectionKeyProperty("statusName");
336 dropDown.setCollectionLabelProperty("statusName");
337 dropDown.setEmptyCollectionMessage("Select a document status.");
338 container.addField(dropDown);
339
340 }
341
342 List<StandardSearchCriteriaField> dateFields = new ArrayList<StandardSearchCriteriaField>();
343 dateFields.add(new StandardSearchCriteriaField(DocumentSearchCriteriaProcessor.CRITERIA_KEY_STATUS_TRANSITION_DATE + DocumentSearchCriteriaProcessor.CRITERIA_KEYS_SUFFIX_RANGE_LOWER_BOUND,"fromStatusTransitionDate",StandardSearchCriteriaField.TEXT,"fromStatusTransitionDate","docSearch.DocumentSearch.criteria.label.from","DocSearchStatusTransitionDate",false,null,null,false));
344 dateFields.add(new StandardSearchCriteriaField(DocumentSearchCriteriaProcessor.CRITERIA_KEY_STATUS_TRANSITION_DATE + DocumentSearchCriteriaProcessor.CRITERIA_KEYS_SUFFIX_RANGE_UPPER_BOUND,"toStatusTransitionDate",StandardSearchCriteriaField.TEXT,"toStatusTransitionDate","docSearch.DocumentSearch.criteria.label.to",null,false,null,null,false));
345 StandardDocSearchCriteriaFieldContainer dateContainer = new StandardDocSearchCriteriaFieldContainer(DocumentSearchCriteriaProcessor.CRITERIA_KEY_STATUS_TRANSITION_DATE, "docSearch.DocumentSearch.criteria.label.statusTransitionDate", dateFields);
346
347 columns.add( container );
348 columns.add( dateContainer );
349 columnList.add( columns );
350 appDocStatusRows.addAll( standardNonSearchAttRows(documentType,columnList) );
351
352 }
353 return appDocStatusRows;
354 }
355
356
357
358
359
360 public boolean shouldDisplayHeaderNonMaintActions() {
361 return criteriaProcessor.isHeaderBarDisplayed();
362 }
363
364
365
366
367
368 public boolean shouldDisplayLookupCriteria() {
369
370 return criteriaProcessor.isBasicSearchCriteriaDisplayed();
371 }
372 }