1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.impl.actionlist;
17
18 import com.google.common.collect.ArrayListMultimap;
19 import com.google.common.collect.ListMultimap;
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
22 import org.kuali.rice.kew.api.action.ActionItem;
23 import org.kuali.rice.kew.api.action.ActionItemCustomization;
24 import org.kuali.rice.kew.doctype.bo.DocumentType;
25 import org.kuali.rice.kew.doctype.service.DocumentTypeService;
26 import org.kuali.rice.kew.framework.KewFrameworkServiceLocator;
27 import org.kuali.rice.kew.framework.actionlist.ActionListCustomizationHandlerService;
28 import org.kuali.rice.kew.framework.actionlist.ActionListCustomizationMediator;
29 import org.kuali.rice.kew.rule.bo.RuleAttribute;
30
31 import java.util.Collections;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35
36
37
38
39
40 public class ActionListCustomizationMediatorImpl implements ActionListCustomizationMediator {
41
42 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionListCustomizationMediatorImpl.class);
43
44 private DocumentTypeService documentTypeService;
45 private ActionListCustomizationHandlerServiceChooser actionListCustomizationHandlerServiceChooser =
46 new ActionListCustomizationHandlerServiceChooser();
47
48
49
50
51
52
53
54 @Override
55 public Map<String, ActionItemCustomization> getActionListCustomizations(String principalId,
56 List<ActionItem> actionItems) throws RiceIllegalArgumentException {
57 if (StringUtils.isBlank(principalId)) {
58 throw new RiceIllegalArgumentException("invalid principalId: " + principalId);
59 }
60 if (actionItems == null) {
61 actionItems = Collections.emptyList();
62 }
63
64
65 Map<String, ActionItemCustomization> results = new HashMap<String, ActionItemCustomization>();
66
67
68
69
70
71 ListMultimap<String, ActionItem> itemsByApplicationId = ArrayListMultimap.create();
72
73 for (ActionItem actionItem : actionItems) {
74
75 DocumentType docType = getDocumentTypeService().findByName(actionItem.getDocName());
76 if (docType == null) {
77 LOG.error(String.format("Action item %s has an invalid document type name of %s",
78 actionItem.getId(), actionItem.getDocName()));
79
80 itemsByApplicationId.put(null, actionItem);
81 } else {
82
83 itemsByApplicationId.put(getActionListCustomizationApplicationId(docType), actionItem);
84 }
85 }
86
87
88
89
90
91 for (String applicationId : itemsByApplicationId.keySet()) {
92 ActionListCustomizationHandlerService actionListCustomizationHandler =
93 getActionListCustomizationHandlerServiceChooser().getByApplicationId(applicationId);
94
95 if (actionListCustomizationHandler == null) {
96
97 actionListCustomizationHandler =
98 getActionListCustomizationHandlerServiceChooser().getByApplicationId(null);
99 }
100
101 List<ActionItemCustomization> customizations =
102 actionListCustomizationHandler.customizeActionList(principalId, itemsByApplicationId.get(
103 applicationId));
104
105
106
107
108 if (customizations != null) for (ActionItemCustomization customization : customizations) {
109 results.put(customization.getActionItemId(), customization);
110 }
111 }
112
113 return results;
114 }
115
116
117
118 private String getActionListCustomizationApplicationId(DocumentType docType) {
119 String applicationId = null;
120 RuleAttribute ruleAttribute = docType.getCustomActionListRuleAttribute();
121 if (ruleAttribute != null) {
122 applicationId = ruleAttribute.getApplicationId();
123 }
124
125 return applicationId;
126 }
127
128 public DocumentTypeService getDocumentTypeService() {
129 return documentTypeService;
130 }
131
132 public void setDocumentTypeService(DocumentTypeService documentTypeService) {
133 this.documentTypeService = documentTypeService;
134 }
135
136
137
138
139 public static class ActionListCustomizationHandlerServiceChooser {
140 public ActionListCustomizationHandlerService getByApplicationId(String applicationId) {
141 return KewFrameworkServiceLocator.getActionListCustomizationHandlerService(applicationId);
142 }
143 }
144
145 public ActionListCustomizationHandlerServiceChooser getActionListCustomizationHandlerServiceChooser() {
146 return actionListCustomizationHandlerServiceChooser;
147 }
148
149 public void setActionListCustomizationHandlerServiceChooser(
150 ActionListCustomizationHandlerServiceChooser actionListCustomizationHandlerServiceChooser) {
151 this.actionListCustomizationHandlerServiceChooser = actionListCustomizationHandlerServiceChooser;
152 }
153 }