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 java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
24 import org.kuali.rice.kew.actionlist.CustomActionListAttribute;
25 import org.kuali.rice.kew.api.action.ActionItem;
26 import org.kuali.rice.kew.api.action.ActionItemCustomization;
27 import org.kuali.rice.kew.api.extension.ExtensionDefinition;
28 import org.kuali.rice.kew.api.extension.ExtensionRepositoryService;
29 import org.kuali.rice.kew.api.extension.ExtensionUtils;
30 import org.kuali.rice.kew.framework.actionlist.ActionListCustomizationHandlerService;
31
32
33
34
35
36
37 public class ActionListCustomizationHandlerServiceImpl implements ActionListCustomizationHandlerService {
38
39 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionListCustomizationHandlerServiceImpl.class);
40
41 private ExtensionRepositoryService extensionRepositoryService;
42
43 @Override
44 public List<ActionItemCustomization> customizeActionList(String principalId, List<ActionItem> actionItems)
45 throws RiceIllegalArgumentException {
46 if (StringUtils.isBlank(principalId)) {
47 throw new RiceIllegalArgumentException("principalId was null or blank");
48 }
49 if (actionItems == null) {
50 actionItems = Collections.emptyList();
51 }
52 List<ActionItemCustomization> actionItemCustomizations = new ArrayList<ActionItemCustomization>();
53
54 for (ActionItem actionItem : actionItems) {
55
56
57 CustomActionListAttribute customActionListAttribute = loadAttribute("attributeName?");
58
59 ActionItemCustomization actionItemCustomization;
60 try {
61 actionItemCustomization = ActionItemCustomization.Builder.create(customActionListAttribute.getLegalActions(principalId, actionItem), customActionListAttribute.getDocHandlerDisplayParameters(principalId, actionItem)).build();
62 actionItemCustomizations.add(actionItemCustomization);
63 } catch (Exception e) {
64
65 LOG.error("Problem loading custom action list attribute", e);
66 }
67 }
68 return actionItemCustomizations;
69 }
70
71
72
73
74
75
76
77 protected CustomActionListAttribute loadAttribute(String attributeName) {
78 ExtensionDefinition extensionDefinition = extensionRepositoryService.getExtensionByName(attributeName);
79 if (extensionDefinition == null) {
80 throw new RiceIllegalArgumentException("Failed to locate a CustomActionListAttribute with the given name: " + attributeName);
81 }
82
83 CustomActionListAttribute customActionListAttribute = ExtensionUtils.loadExtension(extensionDefinition);
84 if (customActionListAttribute == null) {
85 throw new RiceIllegalArgumentException("Failed to load CustomActionListAttribute for: " + extensionDefinition);
86 }
87 return (CustomActionListAttribute)customActionListAttribute;
88 }
89
90
91
92
93
94
95
96
97 public ExtensionRepositoryService getExtensionRepositoryService() {
98 return extensionRepositoryService;
99 }
100
101 public void setExtensionRepositoryService(ExtensionRepositoryService extensionRepositoryService) {
102 this.extensionRepositoryService = extensionRepositoryService;
103 }
104 }