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 java.util.List; |
20 | |
|
21 | |
import org.kuali.rice.kew.actionitem.ActionItem; |
22 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
23 | |
import org.kuali.rice.kew.exception.InvalidActionTakenException; |
24 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
25 | |
import org.kuali.rice.kew.util.KEWConstants; |
26 | |
import org.kuali.rice.kim.api.entity.principal.PrincipalContract; |
27 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
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 | 0 | super(KEWConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD, routeHeader, principal); |
46 | 0 | } |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public ReleaseWorkgroupAuthority(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, String groupId) { |
55 | 0 | super(KEWConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD, routeHeader, principal, annotation); |
56 | 0 | this.groupId = groupId; |
57 | 0 | } |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
@Override |
63 | |
public String validateActionRules() { |
64 | 0 | if (groupId == null) { |
65 | 0 | return "User cannot Release Workgroup Authority without a given workgroup"; |
66 | |
} else { |
67 | 0 | return performReleaseWorkgroupAuthority(true); |
68 | |
} |
69 | |
} |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
@Override |
77 | |
public String validateActionRules(List<ActionRequestValue> actionRequests) { |
78 | 0 | return validateActionRules(); |
79 | |
} |
80 | |
|
81 | |
public void recordAction() throws InvalidActionTakenException { |
82 | 0 | String error = performReleaseWorkgroupAuthority(false); |
83 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(error)) { |
84 | 0 | throw new InvalidActionTakenException(error); |
85 | |
} |
86 | |
|
87 | 0 | queueDocumentProcessing(); |
88 | 0 | } |
89 | |
|
90 | |
private String performReleaseWorkgroupAuthority(boolean forValidationOnly) { |
91 | 0 | if (!KimApiServiceLocator.getIdentityManagementService().isMemberOfGroup(getPrincipal().getPrincipalId(), groupId)){ |
92 | 0 | return (getPrincipal().getPrincipalName() + " not a member of workgroup " + groupId); |
93 | |
} |
94 | |
|
95 | 0 | List<ActionRequestValue> actionRequests = getActionRequestService().findPendingByDoc(getDocumentId()); |
96 | |
|
97 | 0 | for (ActionRequestValue actionRequest : actionRequests) |
98 | |
{ |
99 | |
|
100 | 0 | if (actionRequest.isGroupRequest() && actionRequest.isActive() && actionRequest.getGroupId().equals(groupId)) { |
101 | 0 | List<ActionItem> actionItems = actionRequest.getActionItems(); |
102 | 0 | if (actionItems.size() == 1) { |
103 | 0 | ActionItem actionItem = actionItems.get(0); |
104 | 0 | if (! actionItem.getPrincipalId().equals(getPrincipal().getPrincipalId())) { |
105 | 0 | return "User attempting to release workgroup authority did not take it."; |
106 | 0 | } else if (!forValidationOnly) |
107 | |
{ |
108 | 0 | actionRequest.setStatus(KEWConstants.ACTION_REQUEST_INITIALIZED); |
109 | 0 | getActionRequestService().activateRequest(actionRequest); |
110 | |
} |
111 | |
} |
112 | 0 | } |
113 | |
} |
114 | 0 | return ""; |
115 | |
} |
116 | |
} |