1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.util; |
17 | |
|
18 | |
import java.util.Date; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.apache.log4j.Logger; |
22 | |
import org.kuali.rice.kew.engine.node.BranchState; |
23 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
24 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
25 | |
import org.kuali.rice.kim.api.group.Group; |
26 | |
import org.kuali.rice.kim.api.services.IdentityManagementService; |
27 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class FutureRequestDocumentStateManager { |
38 | |
|
39 | 0 | private static final Logger LOG = Logger.getLogger(FutureRequestDocumentStateManager.class); |
40 | |
|
41 | |
private boolean receiveFutureRequests; |
42 | |
private boolean doNotReceiveFutureRequests; |
43 | |
private boolean clearFutureRequestState; |
44 | |
|
45 | |
|
46 | |
public static final String FUTURE_REQUESTS_VAR_KEY = BranchState.VARIABLE_PREFIX + KEWConstants.RECEIVE_FUTURE_REQUESTS_BRANCH_STATE_KEY; |
47 | |
public static final String DEACTIVATED_REQUESTS_VARY_KEY = BranchState.VARIABLE_PREFIX + KEWConstants.DEACTIVATED_FUTURE_REQUESTS_BRANCH_STATE_KEY; |
48 | |
|
49 | |
public FutureRequestDocumentStateManager (DocumentRouteHeaderValue document, String principalId) |
50 | 0 | { |
51 | 0 | if (document.getRootBranch() != null) { |
52 | 0 | for (BranchState state : document.getRootBranchState()) { |
53 | 0 | if (isStateForUser(state, principalId)) { |
54 | 0 | if (isReceiveFutureRequests(state)) { |
55 | 0 | this.receiveFutureRequests = true; |
56 | 0 | } else if (isDoNotReceiveFutureRequests(state)) { |
57 | 0 | this.doNotReceiveFutureRequests = true; |
58 | 0 | } else if (isClearFutureRequests(state)) { |
59 | 0 | this.clearFutureRequestState = true; |
60 | 0 | this.receiveFutureRequests = false; |
61 | 0 | this.doNotReceiveFutureRequests = false; |
62 | 0 | break; |
63 | |
} |
64 | |
} |
65 | |
} |
66 | |
} |
67 | 0 | if (this.isClearFutureRequestState()) { |
68 | 0 | this.clearStateFromDocument(document); |
69 | |
} |
70 | 0 | } |
71 | |
|
72 | |
public FutureRequestDocumentStateManager (DocumentRouteHeaderValue document, Group kimGroup) |
73 | 0 | { |
74 | 0 | IdentityManagementService ims = KimApiServiceLocator.getIdentityManagementService(); |
75 | 0 | List<String> principalIds = |
76 | |
ims.getGroupMemberPrincipalIds(kimGroup.getId()); |
77 | |
|
78 | 0 | for (String id : principalIds) |
79 | |
{ |
80 | 0 | FutureRequestDocumentStateManager requestStateMngr = |
81 | |
new FutureRequestDocumentStateManager(document, id); |
82 | 0 | if (requestStateMngr.isReceiveFutureRequests()) { |
83 | 0 | this.receiveFutureRequests = true; |
84 | 0 | } else if (requestStateMngr.isDoNotReceiveFutureRequests()) { |
85 | 0 | this.doNotReceiveFutureRequests = true; |
86 | |
} |
87 | 0 | } |
88 | 0 | } |
89 | |
|
90 | |
protected void clearStateFromDocument(DocumentRouteHeaderValue document) { |
91 | 0 | if (document.getRootBranchState() != null) { |
92 | 0 | for (BranchState state : document.getRootBranchState()) { |
93 | 0 | if (state.getKey().contains(FUTURE_REQUESTS_VAR_KEY)) { |
94 | 0 | String values[] = state.getKey().split(","); |
95 | 0 | state.setKey(DEACTIVATED_REQUESTS_VARY_KEY + "," + values[1] + "," + new Date().toString()); |
96 | 0 | } |
97 | |
} |
98 | 0 | KEWServiceLocator.getRouteNodeService().save(document.getRootBranch()); |
99 | |
} |
100 | 0 | } |
101 | |
|
102 | |
protected boolean isStateForUser(BranchState state, String principalId) |
103 | |
{ |
104 | 0 | String[] values = state.getKey().split(","); |
105 | 0 | if (values.length != 4 || ! values[0].contains(FUTURE_REQUESTS_VAR_KEY)) { |
106 | 0 | return false; |
107 | |
} |
108 | 0 | String statePrincipalId = values[1]; |
109 | 0 | return principalId.equals(statePrincipalId); |
110 | |
} |
111 | |
|
112 | |
protected boolean isReceiveFutureRequests(BranchState state) { |
113 | 0 | return state.getValue().equals(KEWConstants.RECEIVE_FUTURE_REQUESTS_BRANCH_STATE_VALUE); |
114 | |
} |
115 | |
|
116 | |
|
117 | |
protected boolean isDoNotReceiveFutureRequests(BranchState state) { |
118 | 0 | return state.getValue().equals(KEWConstants.DONT_RECEIVE_FUTURE_REQUESTS_BRANCH_STATE_VALUE); |
119 | |
} |
120 | |
|
121 | |
protected boolean isClearFutureRequests(BranchState state) { |
122 | 0 | return state.getValue().equals(KEWConstants.CLEAR_FUTURE_REQUESTS_BRANCH_STATE_VALUE); |
123 | |
} |
124 | |
|
125 | |
public boolean isClearFutureRequestState() { |
126 | 0 | return this.clearFutureRequestState; |
127 | |
} |
128 | |
|
129 | |
public boolean isDoNotReceiveFutureRequests() { |
130 | 0 | return this.doNotReceiveFutureRequests; |
131 | |
} |
132 | |
|
133 | |
public boolean isReceiveFutureRequests() { |
134 | 0 | return this.receiveFutureRequests; |
135 | |
} |
136 | |
|
137 | |
} |