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