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.ArrayList; |
20 | |
import java.util.Collection; |
21 | |
import java.util.List; |
22 | |
|
23 | |
import org.kuali.rice.kew.actionitem.ActionItem; |
24 | |
import org.kuali.rice.kew.actionlist.service.ActionListService; |
25 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
26 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
27 | |
import org.kuali.rice.kew.exception.InvalidActionTakenException; |
28 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
29 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
30 | |
import org.kuali.rice.kew.util.KEWConstants; |
31 | |
import org.kuali.rice.kim.api.entity.principal.PrincipalContract; |
32 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public class TakeWorkgroupAuthority extends ActionTakenEvent { |
44 | |
|
45 | |
private String groupId; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public TakeWorkgroupAuthority(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) { |
52 | 0 | super(KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, routeHeader, principal); |
53 | 0 | } |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public TakeWorkgroupAuthority(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, String groupId) { |
62 | 0 | super(KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, routeHeader, principal, annotation); |
63 | 0 | this.groupId = groupId; |
64 | 0 | } |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
@Override |
70 | |
public String validateActionRules() { |
71 | 0 | if ( (groupId != null) && (!KimApiServiceLocator.getIdentityManagementService().isMemberOfGroup(getPrincipal().getPrincipalId(), groupId))) { |
72 | 0 | return (getPrincipal().getPrincipalName() + " not a member of workgroup " + groupId); |
73 | |
} |
74 | 0 | return ""; |
75 | |
} |
76 | |
|
77 | |
@Override |
78 | |
public String validateActionRules(List<ActionRequestValue> actionRequests) { |
79 | 0 | return validateActionRules(); |
80 | |
} |
81 | |
|
82 | |
public void recordAction() throws InvalidActionTakenException { |
83 | |
|
84 | 0 | String errorMessage = validateActionRules(); |
85 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) { |
86 | 0 | throw new InvalidActionTakenException(errorMessage); |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | 0 | List<ActionRequestValue> documentRequests = getActionRequestService().findPendingByDoc(getDocumentId()); |
93 | 0 | List<ActionRequestValue> workgroupRequests = new ArrayList<ActionRequestValue>(); |
94 | 0 | for (ActionRequestValue actionRequest : documentRequests) |
95 | |
{ |
96 | 0 | if (actionRequest.isGroupRequest() && actionRequest.getGroup().getId().equals(groupId)) |
97 | |
{ |
98 | 0 | workgroupRequests.add(actionRequest); |
99 | |
} |
100 | |
} |
101 | |
|
102 | 0 | ActionTakenValue actionTaken = saveActionTaken(findDelegatorForActionRequests(workgroupRequests)); |
103 | 0 | notifyActionTaken(actionTaken); |
104 | |
|
105 | 0 | ActionListService actionListService = KEWServiceLocator.getActionListService(); |
106 | 0 | Collection<ActionItem> actionItems = actionListService.findByDocumentId(getDocumentId()); |
107 | 0 | for (ActionItem actionItem : actionItems) |
108 | |
{ |
109 | |
|
110 | 0 | if (actionItem.isWorkgroupItem() && actionItem.getGroupId().equals(groupId) && |
111 | |
!actionItem.getPrincipalId().equals(getPrincipal().getPrincipalId())) |
112 | |
{ |
113 | 0 | actionListService.deleteActionItem(actionItem); |
114 | |
} |
115 | |
} |
116 | 0 | } |
117 | |
} |