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