1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actions;
17
18 import org.kuali.rice.kew.actionitem.ActionItem;
19 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
20 import org.kuali.rice.kew.api.action.ActionRequestStatus;
21 import org.kuali.rice.kew.api.exception.InvalidActionTakenException;
22 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
23 import org.kuali.rice.kew.api.KewApiConstants;
24 import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
25 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
26
27 import java.util.List;
28
29
30
31
32
33
34
35
36
37 public class ReleaseWorkgroupAuthority extends ActionTakenEvent {
38
39 private String groupId;
40
41
42
43
44 public ReleaseWorkgroupAuthority(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) {
45 super(KewApiConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD, routeHeader, principal);
46 }
47
48
49
50
51
52
53
54 public ReleaseWorkgroupAuthority(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, String groupId) {
55 super(KewApiConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD, routeHeader, principal, annotation);
56 this.groupId = groupId;
57 }
58
59
60
61
62 @Override
63 public String validateActionRules() {
64 if (groupId == null) {
65 return "User cannot Release Workgroup Authority without a given workgroup";
66 } else {
67 return performReleaseWorkgroupAuthority(true);
68 }
69 }
70
71
72
73
74
75
76 @Override
77 public String validateActionRules(List<ActionRequestValue> actionRequests) {
78 return validateActionRules();
79 }
80
81 public void recordAction() throws InvalidActionTakenException {
82 String error = performReleaseWorkgroupAuthority(false);
83 if (!org.apache.commons.lang.StringUtils.isEmpty(error)) {
84 throw new InvalidActionTakenException(error);
85 }
86
87 queueDocumentProcessing();
88 }
89
90 private String performReleaseWorkgroupAuthority(boolean forValidationOnly) {
91 if (!KimApiServiceLocator.getGroupService().isMemberOfGroup(getPrincipal().getPrincipalId(), groupId)){
92 return (getPrincipal().getPrincipalName() + " not a member of workgroup " + groupId);
93 }
94
95 List<ActionRequestValue> actionRequests = getActionRequestService().findPendingByDoc(getDocumentId());
96
97 for (ActionRequestValue actionRequest : actionRequests)
98 {
99
100 if (actionRequest.isGroupRequest() && actionRequest.isActive() && actionRequest.getGroupId().equals(groupId)) {
101 List<ActionItem> actionItems = actionRequest.getActionItems();
102 if (actionItems.size() == 1) {
103 ActionItem actionItem = actionItems.get(0);
104 if (! actionItem.getPrincipalId().equals(getPrincipal().getPrincipalId())) {
105 return "User attempting to release workgroup authority did not take it.";
106 } else if (!forValidationOnly)
107 {
108 actionRequest.setStatus(ActionRequestStatus.INITIALIZED.getCode());
109 getActionRequestService().activateRequest(actionRequest);
110 }
111 }
112 }
113 }
114 return "";
115 }
116 }