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 org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
20 import org.kuali.rice.kew.actionlist.CustomActionListAttribute;
21 import org.kuali.rice.kew.actionlist.DefaultCustomActionListAttribute;
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.actionlist.ActionListCustomizationHandlerService;
27
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33
34
35
36
37
38
39 public class ActionListCustomizationHandlerServiceImpl implements ActionListCustomizationHandlerService {
40
41 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ActionListCustomizationHandlerServiceImpl.class);
42
43 private DocumentTypeService documentTypeService;
44
45 @Override
46 public List<ActionItemCustomization> customizeActionList(String principalId, List<ActionItem> actionItems)
47 throws RiceIllegalArgumentException {
48 if (StringUtils.isBlank(principalId)) {
49 throw new RiceIllegalArgumentException("principalId was null or blank");
50 }
51 if (actionItems == null) { actionItems = Collections.emptyList(); }
52
53 List<ActionItemCustomization> actionItemCustomizations =
54 new ArrayList<ActionItemCustomization>(actionItems.size());
55
56 for (ActionItem actionItem : actionItems) {
57 DocumentType documentType = getDocumentTypeService().findByName(actionItem.getDocName());
58
59 try {
60 CustomActionListAttribute customActionListAttribute = null;
61 if (documentType != null) {
62 customActionListAttribute = documentType.getCustomActionListAttribute();
63 }
64
65 if (customActionListAttribute == null) {
66 customActionListAttribute = getDefaultCustomActionListAttribute();
67 }
68
69 ActionItemCustomization actionItemCustomization = ActionItemCustomization.Builder.create(
70 actionItem.getId(),
71 customActionListAttribute.getLegalActions(principalId, actionItem),
72 customActionListAttribute.getDocHandlerDisplayParameters(principalId, actionItem)).build();
73
74 actionItemCustomizations.add(actionItemCustomization);
75
76 } catch (Exception e) {
77 LOG.error("Problem loading custom action list attribute for action item " + actionItem.getId(), e);
78 }
79 }
80
81 return actionItemCustomizations;
82 }
83
84 public DocumentTypeService getDocumentTypeService() {
85 return documentTypeService;
86 }
87
88 public void setDocumentTypeService(DocumentTypeService documentTypeService) {
89 this.documentTypeService = documentTypeService;
90 }
91
92
93 private static class DefaultCustomActionListAttributeHolder {
94
95 static final CustomActionListAttribute defaultCustomActionListAttribute =
96 new DefaultCustomActionListAttribute();
97 }
98
99 private CustomActionListAttribute getDefaultCustomActionListAttribute() {
100 return DefaultCustomActionListAttributeHolder.defaultCustomActionListAttribute;
101 }
102 }