1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.impl.document; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collection; |
20 | |
import java.util.Collections; |
21 | |
import java.util.LinkedHashSet; |
22 | |
import java.util.List; |
23 | |
import java.util.Set; |
24 | |
|
25 | |
import javax.jws.WebParam; |
26 | |
|
27 | |
import org.apache.commons.lang.StringUtils; |
28 | |
import org.apache.log4j.Logger; |
29 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
30 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
31 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
32 | |
import org.kuali.rice.kew.api.action.ActionRequest; |
33 | |
import org.kuali.rice.kew.api.action.ActionTaken; |
34 | |
import org.kuali.rice.kew.api.document.Document; |
35 | |
import org.kuali.rice.kew.api.document.DocumentContent; |
36 | |
import org.kuali.rice.kew.api.document.DocumentDetail; |
37 | |
import org.kuali.rice.kew.api.document.DocumentLink; |
38 | |
import org.kuali.rice.kew.api.document.RouteNodeInstance; |
39 | |
import org.kuali.rice.kew.api.document.WorkflowDocumentService; |
40 | |
import org.kuali.rice.kew.dto.DTOConverter; |
41 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
42 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValueContent; |
43 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | public class WorkflowDocumentServiceImpl implements WorkflowDocumentService { |
52 | |
|
53 | 0 | private static final Logger LOG = Logger.getLogger(WorkflowDocumentServiceImpl.class); |
54 | |
|
55 | |
@Override |
56 | |
public Document getDocument(String documentId) { |
57 | 0 | if (StringUtils.isBlank(documentId)) { |
58 | 0 | throw new RiceIllegalArgumentException("documentId was blank or null"); |
59 | |
} |
60 | 0 | DocumentRouteHeaderValue documentBo = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId); |
61 | 0 | return DocumentRouteHeaderValue.to(documentBo); |
62 | |
} |
63 | |
|
64 | |
@Override |
65 | |
public boolean doesDocumentExist(String documentId) { |
66 | 0 | if (StringUtils.isBlank(documentId)) { |
67 | 0 | throw new RiceIllegalArgumentException("documentId was blank or null"); |
68 | |
} |
69 | 0 | DocumentRouteHeaderValue documentBo = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId); |
70 | 0 | return documentBo != null; |
71 | |
} |
72 | |
|
73 | |
@Override |
74 | |
public DocumentContent getDocumentContent(String documentId) { |
75 | 0 | if (StringUtils.isBlank(documentId)) { |
76 | 0 | throw new RiceIllegalArgumentException("documentId was blank or null"); |
77 | |
} |
78 | 0 | DocumentRouteHeaderValueContent content = KEWServiceLocator.getRouteHeaderService().getContent(documentId); |
79 | 0 | return DocumentRouteHeaderValueContent.to(content); |
80 | |
} |
81 | |
|
82 | |
@Override |
83 | |
public List<ActionRequest> getRootActionRequests(String documentId) { |
84 | 0 | List<ActionRequest> actionRequests = new ArrayList<ActionRequest>(); |
85 | 0 | List<ActionRequestValue> actionRequestBos = KEWServiceLocator.getActionRequestService().findAllRootActionRequestsByDocumentId(documentId); |
86 | 0 | for (ActionRequestValue actionRequestBo : actionRequestBos) { |
87 | 0 | actionRequests.add(ActionRequestValue.to(actionRequestBo)); |
88 | |
} |
89 | 0 | return Collections.unmodifiableList(actionRequests); |
90 | |
} |
91 | |
|
92 | |
@Override |
93 | |
public List<ActionRequest> getActionRequests(String documentId, String nodeName, String principalId) { |
94 | 0 | if (StringUtils.isBlank(documentId)) { |
95 | 0 | throw new RiceIllegalArgumentException("documentId was null or blank"); |
96 | |
} |
97 | 0 | if ( LOG.isDebugEnabled() ) { |
98 | 0 | LOG.debug("Fetching ActionRequests [docId="+documentId+", nodeName="+nodeName+", principalId="+principalId+"]"); |
99 | |
} |
100 | 0 | List<ActionRequestValue> actionRequestBos = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(documentId); |
101 | 0 | List<ActionRequestValue> matchingActionRequests = new ArrayList<ActionRequestValue>(); |
102 | 0 | for (ActionRequestValue actionRequestValue : actionRequestBos) { |
103 | 0 | if (actionRequestMatches(actionRequestValue, nodeName, principalId)) { |
104 | 0 | matchingActionRequests.add(actionRequestValue); |
105 | |
} |
106 | |
} |
107 | 0 | List<ActionRequest> actionRequests = new ArrayList<ActionRequest>(matchingActionRequests.size()); |
108 | 0 | for (ActionRequestValue matchingActionRequest : matchingActionRequests) { |
109 | 0 | actionRequests.add(ActionRequestValue.to(matchingActionRequest)); |
110 | |
} |
111 | 0 | return actionRequests; |
112 | |
} |
113 | |
|
114 | |
|
115 | |
protected boolean actionRequestMatches(ActionRequestValue actionRequest, String nodeName, String principalId) { |
116 | 0 | boolean matchesUserId = true; |
117 | 0 | boolean matchesNodeName = true; |
118 | 0 | if (StringUtils.isNotBlank(nodeName)) { |
119 | 0 | matchesNodeName = nodeName.equals(actionRequest.getPotentialNodeName()); |
120 | |
} |
121 | 0 | if (principalId != null) { |
122 | 0 | matchesUserId = actionRequest.isRecipientRoutedRequest(principalId); |
123 | |
} |
124 | 0 | return matchesNodeName && matchesUserId; |
125 | |
} |
126 | |
|
127 | |
|
128 | |
@Override |
129 | |
public List<ActionTaken> getActionsTaken(String documentId) { |
130 | 0 | List<ActionTaken> actionTakens = new ArrayList<ActionTaken>(); |
131 | 0 | Collection<ActionTakenValue> actionTakenBos = KEWServiceLocator.getActionTakenService().findByDocumentId(documentId); |
132 | 0 | for (ActionTakenValue actionTakenBo : actionTakenBos) { |
133 | 0 | actionTakens.add(ActionTakenValue.to(actionTakenBo)); |
134 | |
} |
135 | 0 | return actionTakens; |
136 | |
} |
137 | |
|
138 | |
@Override |
139 | |
public DocumentDetail getDocumentDetail(@WebParam(name = "documentId") String documentId) { |
140 | 0 | if (StringUtils.isBlank(documentId)) { |
141 | 0 | throw new IllegalArgumentException("documentId was null or blank"); |
142 | |
} |
143 | 0 | if ( LOG.isDebugEnabled() ) { |
144 | 0 | LOG.debug("Fetching DocumentDetail [id="+documentId+"]"); |
145 | |
} |
146 | 0 | DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId); |
147 | 0 | if (document == null) { |
148 | 0 | return null; |
149 | |
} |
150 | 0 | DocumentDetail documentDetailVO = DTOConverter.convertDocumentDetailNew(document); |
151 | 0 | if ( LOG.isDebugEnabled() ) { |
152 | 0 | LOG.debug("Returning DocumentDetailVO [id=" + documentId + "]"); |
153 | |
} |
154 | 0 | return documentDetailVO; |
155 | |
} |
156 | |
|
157 | |
@Override |
158 | |
public List<RouteNodeInstance> getRouteNodeInstances(String documentId) { |
159 | 0 | if ( LOG.isDebugEnabled() ) { |
160 | 0 | LOG.debug("Fetching RouteNodeInstances [documentId=" + documentId + "]"); |
161 | |
} |
162 | 0 | DocumentRouteHeaderValue documentBo = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId); |
163 | 0 | if (documentBo == null) { |
164 | 0 | return Collections.emptyList(); |
165 | |
} |
166 | 0 | return convertRouteNodeInstances(KEWServiceLocator.getRouteNodeService().getFlattenedNodeInstances(documentBo, true)); |
167 | |
} |
168 | |
|
169 | |
@Override |
170 | |
public List<RouteNodeInstance> getActiveRouteNodeInstances(String documentId) { |
171 | 0 | if ( LOG.isDebugEnabled() ) { |
172 | 0 | LOG.debug("Fetching active RouteNodeInstances [documentId=" + documentId + "]"); |
173 | |
} |
174 | 0 | return convertRouteNodeInstances(KEWServiceLocator.getRouteNodeService().getActiveNodeInstances(documentId)); |
175 | |
} |
176 | |
|
177 | |
private List<RouteNodeInstance> convertRouteNodeInstances(List<org.kuali.rice.kew.engine.node.RouteNodeInstance> routeNodeInstanceBos) { |
178 | 0 | List<RouteNodeInstance> routeNodeInstances = new ArrayList<RouteNodeInstance>(); |
179 | 0 | for (org.kuali.rice.kew.engine.node.RouteNodeInstance routeNodeInstanceBo : routeNodeInstanceBos) { |
180 | 0 | routeNodeInstances.add(org.kuali.rice.kew.engine.node.RouteNodeInstance.to(routeNodeInstanceBo)); |
181 | |
} |
182 | 0 | return Collections.unmodifiableList(routeNodeInstances); |
183 | |
} |
184 | |
|
185 | |
@Override |
186 | |
public List<String> getPreviousRouteNodeNames(String documentId) { |
187 | 0 | if ( LOG.isDebugEnabled() ) { |
188 | 0 | LOG.debug("Fetching previous node names [documentId=" + documentId + "]"); |
189 | |
} |
190 | 0 | DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId); |
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | 0 | if (document.isEnroute() || document.isInException()) { |
196 | |
|
197 | |
|
198 | |
|
199 | 0 | List<org.kuali.rice.kew.engine.node.RouteNodeInstance> routeNodeInstances = KEWServiceLocator.getRouteNodeService().getFlattenedNodeInstances(document, false); |
200 | 0 | Set<String> routeNodeNames = new LinkedHashSet<String>(); |
201 | 0 | if (routeNodeInstances != null) { |
202 | 0 | for (org.kuali.rice.kew.engine.node.RouteNodeInstance routeNodeInstance : routeNodeInstances) { |
203 | 0 | if (routeNodeInstance.isComplete()) { |
204 | 0 | routeNodeNames.add(routeNodeInstance.getName()); |
205 | |
} |
206 | |
} |
207 | |
} |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | 0 | return Collections.unmodifiableList(new ArrayList<String>(routeNodeNames)); |
229 | |
} else { |
230 | 0 | return Collections.emptyList(); |
231 | |
} |
232 | |
} |
233 | |
|
234 | |
@Override |
235 | |
public DocumentLink addDocumentLink(DocumentLink documentLink) throws RiceIllegalArgumentException { |
236 | 0 | if (documentLink == null) { |
237 | 0 | throw new RiceIllegalArgumentException("documentLink was null"); |
238 | |
} |
239 | 0 | if (documentLink.getId() != null) { |
240 | 0 | throw new RiceIllegalArgumentException("the given documentLink already has an id, cannot add a document link with an existing id"); |
241 | |
} |
242 | 0 | org.kuali.rice.kew.documentlink.DocumentLink documentLinkBo = org.kuali.rice.kew.documentlink.DocumentLink.from(documentLink); |
243 | 0 | KEWServiceLocator.getDocumentLinkService().saveDocumentLink(documentLinkBo); |
244 | 0 | return org.kuali.rice.kew.documentlink.DocumentLink.to(documentLinkBo); |
245 | |
} |
246 | |
|
247 | |
@Override |
248 | |
public DocumentLink deleteDocumentLink(String documentLinkId) throws RiceIllegalArgumentException { |
249 | 0 | if (StringUtils.isBlank(documentLinkId)) { |
250 | 0 | throw new RiceIllegalArgumentException("documentLinkId was null or blank"); |
251 | |
} |
252 | 0 | org.kuali.rice.kew.documentlink.DocumentLink documentLinkBo = KEWServiceLocator.getDocumentLinkService().getDocumentLink(Long.valueOf(documentLinkId)); |
253 | 0 | if (documentLinkBo == null) { |
254 | 0 | throw new RiceIllegalArgumentException("Failed to locate document link with the given documentLinkId: " + documentLinkId); |
255 | |
} |
256 | 0 | KEWServiceLocator.getDocumentLinkService().deleteDocumentLink(documentLinkBo); |
257 | 0 | return org.kuali.rice.kew.documentlink.DocumentLink.to(documentLinkBo); |
258 | |
} |
259 | |
|
260 | |
@Override |
261 | |
public List<DocumentLink> deleteDocumentLinksByDocumentId(String originatingDocumentId) throws RiceIllegalArgumentException { |
262 | 0 | if (StringUtils.isBlank(originatingDocumentId)) { |
263 | 0 | throw new RiceIllegalArgumentException("originatingDocumentId was null or blank"); |
264 | |
} |
265 | 0 | List<org.kuali.rice.kew.documentlink.DocumentLink> documentLinkBos = KEWServiceLocator.getDocumentLinkService().getLinkedDocumentsByDocId(originatingDocumentId); |
266 | 0 | if (documentLinkBos == null || documentLinkBos.isEmpty()) { |
267 | 0 | return Collections.emptyList(); |
268 | |
} |
269 | 0 | List<DocumentLink> deletedDocumentLinks = new ArrayList<DocumentLink>(); |
270 | 0 | for (org.kuali.rice.kew.documentlink.DocumentLink documentLinkBo : documentLinkBos) { |
271 | 0 | deletedDocumentLinks.add(org.kuali.rice.kew.documentlink.DocumentLink.to(documentLinkBo)); |
272 | 0 | KEWServiceLocator.getDocumentLinkService().deleteDocumentLink(documentLinkBo); |
273 | |
} |
274 | 0 | return Collections.unmodifiableList(deletedDocumentLinks); |
275 | |
} |
276 | |
|
277 | |
@Override |
278 | |
public List<DocumentLink> getOutgoingDocumentLinks(String originatingDocumentId) throws RiceIllegalArgumentException { |
279 | 0 | if (StringUtils.isBlank(originatingDocumentId)) { |
280 | 0 | throw new RiceIllegalArgumentException("originatingDocumentId was null or blank"); |
281 | |
} |
282 | 0 | List<org.kuali.rice.kew.documentlink.DocumentLink> outgoingDocumentLinkBos = KEWServiceLocator.getDocumentLinkService().getLinkedDocumentsByDocId(originatingDocumentId); |
283 | 0 | List<DocumentLink> outgoingDocumentLinks = new ArrayList<DocumentLink>(); |
284 | 0 | for (org.kuali.rice.kew.documentlink.DocumentLink outgoingDocumentLinkBo : outgoingDocumentLinkBos) { |
285 | 0 | outgoingDocumentLinks.add(org.kuali.rice.kew.documentlink.DocumentLink.to(outgoingDocumentLinkBo)); |
286 | |
} |
287 | 0 | return Collections.unmodifiableList(outgoingDocumentLinks); |
288 | |
} |
289 | |
|
290 | |
@Override |
291 | |
public List<DocumentLink> getIncomingDocumentLinks(String destinationDocumentId) throws RiceIllegalArgumentException { |
292 | 0 | if (StringUtils.isBlank(destinationDocumentId)) { |
293 | 0 | throw new RiceIllegalArgumentException("destinationDocumentId was null or blank"); |
294 | |
} |
295 | 0 | List<org.kuali.rice.kew.documentlink.DocumentLink> incomingDocumentLinkBos = KEWServiceLocator.getDocumentLinkService().getOutgoingLinkedDocumentsByDocId(destinationDocumentId); |
296 | 0 | List<DocumentLink> incomingDocumentLinks = new ArrayList<DocumentLink>(); |
297 | 0 | for (org.kuali.rice.kew.documentlink.DocumentLink incomingDocumentLinkBo : incomingDocumentLinkBos) { |
298 | 0 | incomingDocumentLinks.add(org.kuali.rice.kew.documentlink.DocumentLink.to(incomingDocumentLinkBo)); |
299 | |
} |
300 | 0 | return Collections.unmodifiableList(incomingDocumentLinks); |
301 | |
} |
302 | |
|
303 | |
@Override |
304 | |
public DocumentLink getDocumentLink(String documentLinkId) throws RiceIllegalArgumentException { |
305 | 0 | if (StringUtils.isBlank(documentLinkId)) { |
306 | 0 | throw new RiceIllegalArgumentException("documentLinkId was null or blank"); |
307 | |
} |
308 | 0 | org.kuali.rice.kew.documentlink.DocumentLink documentLinkBo = KEWServiceLocator.getDocumentLinkService().getDocumentLink(Long.valueOf(documentLinkId)); |
309 | 0 | return org.kuali.rice.kew.documentlink.DocumentLink.to(documentLinkBo); |
310 | |
} |
311 | |
|
312 | |
} |