1 | |
package org.kuali.rice.kew.docsearch; |
2 | |
|
3 | |
import org.aspectj.lang.reflect.FieldSignature; |
4 | |
import org.kuali.rice.core.api.uif.RemotableAttributeField; |
5 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
6 | |
import org.kuali.rice.kew.api.document.attribute.AttributeFields; |
7 | |
import org.kuali.rice.kew.doctype.DocumentTypeAttribute; |
8 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
9 | |
import org.kuali.rice.kew.framework.KewFrameworkServiceLocator; |
10 | |
import org.kuali.rice.kew.framework.docsearch.DocumentSearchCustomizationService; |
11 | |
import org.kuali.rice.kew.rule.bo.RuleAttribute; |
12 | |
import org.kuali.rice.ksb.api.KsbApiServiceLocator; |
13 | |
|
14 | |
import java.util.ArrayList; |
15 | |
import java.util.HashMap; |
16 | |
import java.util.LinkedHashMap; |
17 | |
import java.util.List; |
18 | |
import java.util.Map; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | 0 | public class DocumentSearchCustomizationMediatorImpl implements DocumentSearchCustomizationMediator { |
26 | |
|
27 | |
@Override |
28 | |
public List<RemotableAttributeField> getSearchFields(DocumentType documentType) { |
29 | |
|
30 | 0 | List<DocumentTypeAttribute> searchableAttributes = documentType.getSearchableAttributes(); |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 0 | LinkedHashMap<String, List<String>> applicationIdToAttributeNameMap = new LinkedHashMap<String, List<String>>(); |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | LinkedHashMap<String, List<RemotableAttributeField>> orderedFieldMap = new LinkedHashMap<String, List<RemotableAttributeField>>(); |
43 | |
|
44 | 0 | for (DocumentTypeAttribute searchableAttribute : searchableAttributes) { |
45 | 0 | RuleAttribute ruleAttribute = searchableAttribute.getRuleAttribute(); |
46 | 0 | String attributeName = ruleAttribute.getName(); |
47 | 0 | String applicationId = ruleAttribute.getApplicationId(); |
48 | 0 | if (!applicationIdToAttributeNameMap.containsKey(applicationId)) { |
49 | 0 | applicationIdToAttributeNameMap.put(applicationId, new ArrayList<String>()); |
50 | |
} |
51 | 0 | applicationIdToAttributeNameMap.get(applicationId).add(attributeName); |
52 | |
|
53 | 0 | orderedFieldMap.put(attributeName, null); |
54 | 0 | } |
55 | |
|
56 | 0 | for (String applicationId : applicationIdToAttributeNameMap.keySet()) { |
57 | 0 | DocumentSearchCustomizationService documentSearchCustomizationService = loadCustomizationService(applicationId); |
58 | 0 | List<String> searchableAttributeNames = applicationIdToAttributeNameMap.get(applicationId); |
59 | 0 | List<AttributeFields> attributeFieldsList = documentSearchCustomizationService.getSearchAttributeFields(documentType.getName(), searchableAttributeNames); |
60 | 0 | mergeAttributeFields(attributeFieldsList, orderedFieldMap); |
61 | 0 | } |
62 | |
|
63 | 0 | return flattenOrderedFieldMap(orderedFieldMap); |
64 | |
|
65 | |
} |
66 | |
|
67 | |
protected DocumentSearchCustomizationService loadCustomizationService(String applicationId) { |
68 | 0 | DocumentSearchCustomizationService service = KewFrameworkServiceLocator.getDocumentSearchCustomizationService(applicationId); |
69 | 0 | if (service == null) { |
70 | 0 | throw new WorkflowRuntimeException("Failed to locate DocumentSearchCustomizationService for applicationId: " + applicationId); |
71 | |
} |
72 | 0 | return service; |
73 | |
} |
74 | |
|
75 | |
protected void mergeAttributeFields(List<AttributeFields> attributeFieldsList, LinkedHashMap<String, List<RemotableAttributeField>> orderedFieldMap) { |
76 | 0 | if (attributeFieldsList == null) { |
77 | 0 | return; |
78 | |
} |
79 | 0 | for (AttributeFields attributeFields : attributeFieldsList) { |
80 | 0 | orderedFieldMap.put(attributeFields.getAttributeName(), attributeFields.getRemotableAttributeFields()); |
81 | |
} |
82 | 0 | } |
83 | |
|
84 | |
protected List<RemotableAttributeField> flattenOrderedFieldMap(LinkedHashMap<String, List<RemotableAttributeField>> orderedFieldMap) { |
85 | 0 | List<RemotableAttributeField> flattenedFields = new ArrayList<RemotableAttributeField>(); |
86 | 0 | for (List<RemotableAttributeField> fields : orderedFieldMap.values()) { |
87 | 0 | if (fields != null) { |
88 | 0 | flattenedFields.addAll(fields); |
89 | |
} |
90 | |
} |
91 | 0 | return flattenedFields; |
92 | |
} |
93 | |
|
94 | |
} |