1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.workflow;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.kuali.rice.core.api.uif.RemotableAttributeError;
25 import org.kuali.rice.core.api.uif.RemotableAttributeField;
26 import org.kuali.rice.kew.api.document.DocumentWithContent;
27 import org.kuali.rice.kew.api.document.attribute.DocumentAttribute;
28 import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition;
29 import org.kuali.rice.kew.api.document.search.DocumentSearchCriteria;
30 import org.kuali.rice.kew.api.document.search.DocumentSearchResult;
31 import org.kuali.rice.kew.api.extension.ExtensionDefinition;
32 import org.kuali.rice.kew.framework.document.attribute.SearchableAttribute;
33 import org.kuali.rice.kew.framework.document.search.DocumentSearchCustomizer;
34 import org.kuali.rice.kew.framework.document.search.DocumentSearchResultSetConfiguration;
35 import org.kuali.rice.kew.framework.document.search.DocumentSearchResultValues;
36 import org.kuali.rice.kew.framework.document.search.StandardResultField;
37
38 public class OLEDocumentSearchCustomizer implements SearchableAttribute, DocumentSearchCustomizer {
39 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OLEDocumentSearchCustomizer.class);
40
41 protected SearchableAttribute searchableAttribute;
42
43 public OLEDocumentSearchCustomizer() {
44 this(new OLESearchableAttribute());
45 }
46
47 public OLEDocumentSearchCustomizer(SearchableAttribute searchableAttribute) {
48 this.searchableAttribute = searchableAttribute;
49 }
50
51 @Override
52 public DocumentSearchResultValues customizeResults(DocumentSearchCriteria documentSearchCriteria, List<DocumentSearchResult> defaultResults) {
53 if ( LOG.isDebugEnabled() ) {
54 LOG.debug( "customizeResults( " + documentSearchCriteria + ", " + defaultResults + " )" );
55 }
56 return null;
57 }
58
59 @Override
60 public final String generateSearchContent(ExtensionDefinition extensionDefinition,
61 String documentTypeName,
62 WorkflowAttributeDefinition attributeDefinition) {
63 if ( LOG.isDebugEnabled() ) {
64 LOG.debug( "generateSearchContent( " + extensionDefinition + ", " + documentTypeName + ", " + attributeDefinition + " )" );
65 }
66 return getSearchableAttribute().generateSearchContent(extensionDefinition, documentTypeName, attributeDefinition);
67 }
68
69 @Override
70 public final List<DocumentAttribute> extractDocumentAttributes(ExtensionDefinition extensionDefinition,
71 DocumentWithContent documentWithContent) {
72 if ( LOG.isDebugEnabled() ) {
73 LOG.debug( "extractDocumentAttributes( " + extensionDefinition + ", " + documentWithContent + " )" );
74 }
75 return getSearchableAttribute().extractDocumentAttributes(extensionDefinition, documentWithContent);
76 }
77
78 @Override
79 public final List<RemotableAttributeField> getSearchFields(ExtensionDefinition extensionDefinition,
80 String documentTypeName) {
81 if ( LOG.isDebugEnabled() ) {
82 LOG.debug( "getSearchFields( " + extensionDefinition + ", " + documentTypeName + " )" );
83 }
84 return getSearchableAttribute().getSearchFields(extensionDefinition, documentTypeName);
85 }
86
87 @Override
88 public final List<RemotableAttributeError> validateDocumentAttributeCriteria(ExtensionDefinition extensionDefinition,
89 DocumentSearchCriteria documentSearchCriteria) {
90 if ( LOG.isDebugEnabled() ) {
91 LOG.debug( "validateDocumentAttributeCriteria( " + extensionDefinition + ", " + documentSearchCriteria + " )" );
92 }
93 return getSearchableAttribute().validateDocumentAttributeCriteria(extensionDefinition, documentSearchCriteria);
94 }
95
96 protected SearchableAttribute getSearchableAttribute() {
97 return this.searchableAttribute;
98 }
99
100 public void setSearchableAttribute(SearchableAttribute searchableAttribute) {
101 this.searchableAttribute = searchableAttribute;
102 }
103
104 @Override
105 public DocumentSearchCriteria customizeCriteria(DocumentSearchCriteria documentSearchCriteria) {
106 if ( LOG.isDebugEnabled() ) {
107 LOG.debug( "customizeCriteria( " + documentSearchCriteria + " )" );
108 }
109
110
111 if ( documentSearchCriteria.getDocumentAttributeValues().containsKey( OLESearchableAttribute.DISPLAY_TYPE_SEARCH_ATTRIBUTE_NAME ) ) {
112 DocumentSearchCriteria.Builder newCriteria = DocumentSearchCriteria.Builder.create(documentSearchCriteria);
113 Map<String, List<String>> searchOptions = new HashMap<String, List<String>>();
114 searchOptions.put(OLESearchableAttribute.DISPLAY_TYPE_SEARCH_ATTRIBUTE_NAME,
115 newCriteria.getDocumentAttributeValues().get(OLESearchableAttribute.DISPLAY_TYPE_SEARCH_ATTRIBUTE_NAME));
116 newCriteria.setSearchOptions(searchOptions);
117 newCriteria.getDocumentAttributeValues().remove( OLESearchableAttribute.DISPLAY_TYPE_SEARCH_ATTRIBUTE_NAME );
118 return newCriteria.build();
119 }
120 return null;
121 }
122
123 @Override
124 public DocumentSearchCriteria customizeClearCriteria(DocumentSearchCriteria documentSearchCriteria) {
125 if ( LOG.isDebugEnabled() ) {
126 LOG.debug( "customizeClearCriteria( " + documentSearchCriteria + " )" );
127 }
128 DocumentSearchCriteria.Builder newCriteria = DocumentSearchCriteria.Builder.create();
129 newCriteria.setDocumentTypeName(documentSearchCriteria.getDocumentTypeName());
130 return newCriteria.build();
131 }
132
133 protected static final List<StandardResultField> standardResultsToRemove = new ArrayList<StandardResultField>();
134 static {
135 standardResultsToRemove.add(StandardResultField.DOCUMENT_TYPE);
136 standardResultsToRemove.add(StandardResultField.TITLE);
137
138 standardResultsToRemove.add(StandardResultField.INITIATOR);
139 standardResultsToRemove.add(StandardResultField.DATE_CREATED);
140 }
141
142 @Override
143 public DocumentSearchResultSetConfiguration customizeResultSetConfiguration(DocumentSearchCriteria documentSearchCriteria) {
144 if ( LOG.isDebugEnabled() ) {
145 LOG.debug( "customizeResultSetConfiguration( " + documentSearchCriteria + " )" );
146 }
147 DocumentSearchResultSetConfiguration.Builder config = DocumentSearchResultSetConfiguration.Builder.create();
148 config.setOverrideSearchableAttributes(false);
149 config.setStandardResultFieldsToRemove(standardResultsToRemove);
150
151 List<String> displayTypeList = documentSearchCriteria.getSearchOptions().get(OLESearchableAttribute.DISPLAY_TYPE_SEARCH_ATTRIBUTE_NAME);
152 if ( displayTypeList != null && !displayTypeList.isEmpty() ) {
153
154 String displayType = displayTypeList.get(0);
155 if ( StringUtils.equals(displayType, OLESearchableAttribute.WORKFLOW_DISPLAY_TYPE_VALUE)) {
156 config.setOverrideSearchableAttributes(true);
157 config.setStandardResultFieldsToRemove(null);
158 }
159 }
160 return config.build();
161 }
162
163 @Override
164 public boolean isCustomizeCriteriaEnabled(String documentTypeName) {
165 return true;
166 }
167
168 @Override
169 public boolean isCustomizeClearCriteriaEnabled(String documentTypeName) {
170 return true;
171 }
172
173 @Override
174 public boolean isCustomizeResultsEnabled(String documentTypeName) {
175 return false;
176 }
177
178 @Override
179 public boolean isCustomizeResultSetFieldsEnabled(String documentTypeName) {
180 return true;
181 }
182
183
184 }