| 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.kuali.rice.core.api.uif.RemotableAttributeField; |
| 19 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 20 | |
import org.kuali.rice.kew.framework.document.search.DocumentSearchCriteriaConfiguration; |
| 21 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 22 | |
import org.kuali.rice.kew.api.KewApiConstants; |
| 23 | |
import org.kuali.rice.kns.util.FieldUtils; |
| 24 | |
import org.kuali.rice.kns.web.ui.Field; |
| 25 | |
import org.kuali.rice.kns.web.ui.Row; |
| 26 | |
|
| 27 | |
import java.util.ArrayList; |
| 28 | |
import java.util.List; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | 0 | public class DocumentSearchCriteriaProcessorKEWAdapter implements DocumentSearchCriteriaProcessor { |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
public static final String ADVANCED_SEARCH_FIELD = "isAdvancedSearch"; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public static final String SUPERUSER_SEARCH_FIELD = "superUserSearch"; |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public static final String CLEARSAVED_SEARCH_FIELD = "resetSavedSearch"; |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
private static final String DOCUMENT_ATTRIBUTE_FIELD_MARKER = "DOCUMENT_ATTRIBUTE_FIELD_MARKER"; |
| 56 | |
|
| 57 | |
private static final String APPLICATION_DOCUMENT_STATUS_CODE = "applicationDocumentStatusCode"; |
| 58 | |
private static final String ROUTE_NODE_NAME = "routeNodeName"; |
| 59 | |
private static final String ROUTE_NODE_LOGIC = "routeNodeLogic"; |
| 60 | |
|
| 61 | 0 | private static final String[] BASIC_FIELD_NAMES = { |
| 62 | |
"documentTypeName", |
| 63 | |
"initiatorPrincipalName", |
| 64 | |
"documentId", |
| 65 | |
"dateCreated", |
| 66 | |
DOCUMENT_ATTRIBUTE_FIELD_MARKER, |
| 67 | |
"saveName" |
| 68 | |
}; |
| 69 | |
|
| 70 | 0 | private static final String[] ADVANCED_FIELD_NAMES = { |
| 71 | |
"documentTypeName", |
| 72 | |
"initiatorPrincipalName", |
| 73 | |
"approverPrincipalName", |
| 74 | |
"viewerPrincipalName", |
| 75 | |
"groupViewerName", |
| 76 | |
"groupViewerId", |
| 77 | |
"documentId", |
| 78 | |
"applicationDocumentId", |
| 79 | |
"statusCode", |
| 80 | |
APPLICATION_DOCUMENT_STATUS_CODE, |
| 81 | |
ROUTE_NODE_NAME, |
| 82 | |
ROUTE_NODE_LOGIC, |
| 83 | |
"dateCreated", |
| 84 | |
"dateApproved", |
| 85 | |
"dateLastModified", |
| 86 | |
"dateFinalized", |
| 87 | |
"title", |
| 88 | |
DOCUMENT_ATTRIBUTE_FIELD_MARKER, |
| 89 | |
"saveName" |
| 90 | |
}; |
| 91 | |
|
| 92 | |
@Override |
| 93 | |
public List<Row> getRows(DocumentType documentType, List<Row> defaultRows, boolean advancedSearch, boolean superUserSearch) { |
| 94 | 0 | List<Row> rows = null; |
| 95 | 0 | if(advancedSearch) { |
| 96 | 0 | rows = loadRowsForAdvancedSearch(defaultRows, documentType); |
| 97 | |
} else { |
| 98 | 0 | rows = loadRowsForBasicSearch(defaultRows, documentType); |
| 99 | |
} |
| 100 | 0 | addHiddenFields(rows, advancedSearch, superUserSearch); |
| 101 | 0 | return rows; |
| 102 | |
} |
| 103 | |
|
| 104 | |
protected List<Row> loadRowsForAdvancedSearch(List<Row> defaultRows, DocumentType documentType) { |
| 105 | 0 | List<Row> rows = new ArrayList<Row>(); |
| 106 | 0 | loadRowsWithFields(rows, defaultRows, ADVANCED_FIELD_NAMES, documentType); |
| 107 | 0 | return rows; |
| 108 | |
} |
| 109 | |
|
| 110 | |
protected List<Row> loadRowsForBasicSearch(List<Row> defaultRows, DocumentType documentType) { |
| 111 | 0 | List<Row> rows = new ArrayList<Row>(); |
| 112 | 0 | loadRowsWithFields(rows, defaultRows, BASIC_FIELD_NAMES, documentType); |
| 113 | 0 | return rows; |
| 114 | |
} |
| 115 | |
|
| 116 | |
protected void loadRowsWithFields(List<Row> rowsToLoad, List<Row> defaultRows, String[] fieldNames, |
| 117 | |
DocumentType documentType) { |
| 118 | 0 | for (String fieldName : fieldNames) { |
| 119 | 0 | if (fieldName.equals(DOCUMENT_ATTRIBUTE_FIELD_MARKER) && documentType != null) { |
| 120 | 0 | rowsToLoad.addAll(getDocumentAttributeRows(documentType)); |
| 121 | |
} |
| 122 | |
else { |
| 123 | 0 | for (Row defaultRow : defaultRows) { |
| 124 | 0 | for (Field defaultField : defaultRow.getFields()) { |
| 125 | |
|
| 126 | |
|
| 127 | 0 | if (defaultField.getPropertyName().endsWith(fieldName)) { |
| 128 | |
|
| 129 | 0 | if (fieldName.equals(APPLICATION_DOCUMENT_STATUS_CODE) || |
| 130 | |
fieldName.equals(ROUTE_NODE_NAME) || |
| 131 | |
fieldName.equals(ROUTE_NODE_LOGIC)) { |
| 132 | 0 | if (documentType == null) { |
| 133 | 0 | continue; |
| 134 | |
} |
| 135 | |
} |
| 136 | 0 | rowsToLoad.add(defaultRow); |
| 137 | |
} |
| 138 | |
} |
| 139 | |
} |
| 140 | |
} |
| 141 | |
} |
| 142 | 0 | } |
| 143 | |
|
| 144 | |
protected List<Row> getDocumentAttributeRows(DocumentType documentType) { |
| 145 | 0 | List<Row> documentAttributeRows = new ArrayList<Row>(); |
| 146 | 0 | DocumentSearchCriteriaConfiguration configuration = |
| 147 | |
KEWServiceLocator.getDocumentSearchCustomizationMediator(). |
| 148 | |
getDocumentSearchCriteriaConfiguration(documentType); |
| 149 | 0 | if (configuration != null) { |
| 150 | 0 | List<RemotableAttributeField> remotableAttributeFields = configuration.getFlattenedSearchAttributeFields(); |
| 151 | 0 | if (remotableAttributeFields != null && !remotableAttributeFields.isEmpty()) { |
| 152 | 0 | documentAttributeRows.addAll(FieldUtils.convertRemotableAttributeFields(remotableAttributeFields)); |
| 153 | |
} |
| 154 | |
} |
| 155 | 0 | List<Row> fixedDocumentAttributeRows = new ArrayList<Row>(); |
| 156 | 0 | for (Row row : documentAttributeRows) { |
| 157 | 0 | List<Field> fields = row.getFields(); |
| 158 | 0 | for (Field field : fields) { |
| 159 | |
|
| 160 | 0 | if(field.getMaxLength() == 0) { |
| 161 | 0 | field.setMaxLength(100); |
| 162 | |
} |
| 163 | 0 | if(field.isDatePicker() && field.isRanged()) { |
| 164 | 0 | Field newDate = FieldUtils.createRangeDateField(field); |
| 165 | 0 | List<Field> newFields = new ArrayList<Field>(); |
| 166 | 0 | newFields.add(newDate); |
| 167 | 0 | fixedDocumentAttributeRows.addAll(FieldUtils.wrapFields(newFields)); |
| 168 | |
} |
| 169 | |
|
| 170 | 0 | field.setPropertyName(KewApiConstants.DOCUMENT_ATTRIBUTE_FIELD_PREFIX + field.getPropertyName()); |
| 171 | |
} |
| 172 | 0 | fixedDocumentAttributeRows.add(row); |
| 173 | 0 | } |
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | 0 | return fixedDocumentAttributeRows; |
| 183 | |
} |
| 184 | |
|
| 185 | |
protected void addHiddenFields(List<Row> rows, boolean advancedSearch, boolean superUserSearch) { |
| 186 | 0 | Row hiddenRow = new Row(); |
| 187 | 0 | hiddenRow.setHidden(true); |
| 188 | |
|
| 189 | 0 | Field detailedField = new Field(); |
| 190 | 0 | detailedField.setPropertyName(ADVANCED_SEARCH_FIELD); |
| 191 | 0 | detailedField.setPropertyValue(advancedSearch ? "YES" : "NO"); |
| 192 | 0 | detailedField.setFieldType(Field.HIDDEN); |
| 193 | |
|
| 194 | 0 | Field superUserSearchField = new Field(); |
| 195 | 0 | superUserSearchField.setPropertyName(SUPERUSER_SEARCH_FIELD); |
| 196 | 0 | superUserSearchField.setPropertyValue(superUserSearch ? "YES" : "NO"); |
| 197 | 0 | superUserSearchField.setFieldType(Field.HIDDEN); |
| 198 | |
|
| 199 | 0 | Field clearSavedSearchField = new Field(); |
| 200 | 0 | clearSavedSearchField .setPropertyName(CLEARSAVED_SEARCH_FIELD); |
| 201 | 0 | clearSavedSearchField .setPropertyValue(superUserSearch ? "YES" : "NO"); |
| 202 | 0 | clearSavedSearchField .setFieldType(Field.HIDDEN); |
| 203 | |
|
| 204 | 0 | List<Field> hiddenFields = new ArrayList<Field>(); |
| 205 | 0 | hiddenFields.add(detailedField); |
| 206 | 0 | hiddenFields.add(superUserSearchField); |
| 207 | 0 | hiddenFields.add(clearSavedSearchField); |
| 208 | 0 | hiddenRow.setFields(hiddenFields); |
| 209 | 0 | rows.add(hiddenRow); |
| 210 | |
|
| 211 | 0 | } |
| 212 | |
|
| 213 | |
} |