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