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