1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.dto; |
18 | |
|
19 | |
import java.sql.Timestamp; |
20 | |
import java.util.ArrayList; |
21 | |
import java.util.Arrays; |
22 | |
import java.util.Collection; |
23 | |
import java.util.Date; |
24 | |
import java.util.HashMap; |
25 | |
import java.util.Iterator; |
26 | |
import java.util.List; |
27 | |
import java.util.Map; |
28 | |
|
29 | |
import javax.xml.parsers.DocumentBuilder; |
30 | |
import javax.xml.parsers.DocumentBuilderFactory; |
31 | |
|
32 | |
import org.apache.commons.lang.StringUtils; |
33 | |
import org.apache.log4j.Logger; |
34 | |
import org.kuali.rice.core.exception.RiceRuntimeException; |
35 | |
import org.kuali.rice.core.reflect.DataDefinition; |
36 | |
import org.kuali.rice.core.reflect.ObjectDefinition; |
37 | |
import org.kuali.rice.core.reflect.PropertyDefinition; |
38 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
39 | |
import org.kuali.rice.kew.actionitem.ActionItem; |
40 | |
import org.kuali.rice.kew.actionrequest.ActionRequestFactory; |
41 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
42 | |
import org.kuali.rice.kew.actionrequest.KimGroupRecipient; |
43 | |
import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient; |
44 | |
import org.kuali.rice.kew.actionrequest.Recipient; |
45 | |
import org.kuali.rice.kew.actions.AdHocRevoke; |
46 | |
import org.kuali.rice.kew.actions.MovePoint; |
47 | |
import org.kuali.rice.kew.actions.ValidActions; |
48 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
49 | |
import org.kuali.rice.kew.definition.AttributeDefinition; |
50 | |
import org.kuali.rice.kew.docsearch.DocSearchCriteriaDTO; |
51 | |
import org.kuali.rice.kew.docsearch.DocSearchUtils; |
52 | |
import org.kuali.rice.kew.docsearch.DocumentSearchResult; |
53 | |
import org.kuali.rice.kew.docsearch.DocumentSearchResultComponents; |
54 | |
import org.kuali.rice.kew.docsearch.SearchableAttribute; |
55 | |
import org.kuali.rice.kew.docsearch.web.SearchAttributeFormContainer; |
56 | |
import org.kuali.rice.kew.docsearch.xml.GenericXMLSearchableAttribute; |
57 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
58 | |
import org.kuali.rice.kew.documentlink.DocumentLink; |
59 | |
import org.kuali.rice.kew.engine.node.BranchState; |
60 | |
import org.kuali.rice.kew.engine.node.KeyValuePair; |
61 | |
import org.kuali.rice.kew.engine.node.Process; |
62 | |
import org.kuali.rice.kew.engine.node.RouteNode; |
63 | |
import org.kuali.rice.kew.engine.node.RouteNodeInstance; |
64 | |
import org.kuali.rice.kew.engine.node.State; |
65 | |
import org.kuali.rice.kew.engine.simulation.SimulationActionToTake; |
66 | |
import org.kuali.rice.kew.engine.simulation.SimulationCriteria; |
67 | |
import org.kuali.rice.kew.exception.DocumentTypeNotFoundException; |
68 | |
import org.kuali.rice.kew.exception.WorkflowException; |
69 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
70 | |
import org.kuali.rice.kew.notes.Note; |
71 | |
import org.kuali.rice.kew.notes.service.NoteService; |
72 | |
import org.kuali.rice.kew.postprocessor.ActionTakenEvent; |
73 | |
import org.kuali.rice.kew.postprocessor.AfterProcessEvent; |
74 | |
import org.kuali.rice.kew.postprocessor.BeforeProcessEvent; |
75 | |
import org.kuali.rice.kew.postprocessor.DeleteEvent; |
76 | |
import org.kuali.rice.kew.postprocessor.DocumentLockingEvent; |
77 | |
import org.kuali.rice.kew.postprocessor.DocumentRouteLevelChange; |
78 | |
import org.kuali.rice.kew.postprocessor.DocumentRouteStatusChange; |
79 | |
import org.kuali.rice.kew.routeheader.DocumentContent; |
80 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
81 | |
import org.kuali.rice.kew.routeheader.DocumentStatusTransition; |
82 | |
import org.kuali.rice.kew.routeheader.StandardDocumentContent; |
83 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
84 | |
import org.kuali.rice.kew.rule.RuleDelegation; |
85 | |
import org.kuali.rice.kew.rule.RuleExtension; |
86 | |
import org.kuali.rice.kew.rule.RuleExtensionValue; |
87 | |
import org.kuali.rice.kew.rule.RuleResponsibility; |
88 | |
import org.kuali.rice.kew.rule.WorkflowAttribute; |
89 | |
import org.kuali.rice.kew.rule.WorkflowAttributeValidationError; |
90 | |
import org.kuali.rice.kew.rule.WorkflowAttributeXmlValidator; |
91 | |
import org.kuali.rice.kew.rule.bo.RuleAttribute; |
92 | |
import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute; |
93 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
94 | |
import org.kuali.rice.kew.user.RoleRecipient; |
95 | |
import org.kuali.rice.kew.util.KEWConstants; |
96 | |
import org.kuali.rice.kew.util.ResponsibleParty; |
97 | |
import org.kuali.rice.kew.util.Utilities; |
98 | |
import org.kuali.rice.kew.util.XmlHelper; |
99 | |
import org.kuali.rice.kew.web.KeyValueSort; |
100 | |
import org.kuali.rice.kim.bo.Group; |
101 | |
import org.kuali.rice.kim.bo.Person; |
102 | |
import org.kuali.rice.kim.bo.entity.KimPrincipal; |
103 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
104 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
105 | |
import org.w3c.dom.Document; |
106 | |
import org.w3c.dom.Element; |
107 | |
import org.w3c.dom.NodeList; |
108 | |
|
109 | |
import org.kuali.rice.kew.engine.node.Branch; |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | 0 | public class DTOConverter { |
118 | 0 | private static final Logger LOG = Logger.getLogger(DTOConverter.class); |
119 | |
|
120 | |
public static RouteHeaderDTO convertRouteHeader(DocumentRouteHeaderValue routeHeader, String principalId) throws WorkflowException { |
121 | 0 | RouteHeaderDTO routeHeaderVO = new RouteHeaderDTO(); |
122 | 0 | if (routeHeader == null) { |
123 | 0 | return null; |
124 | |
} |
125 | 0 | populateRouteHeaderVO(routeHeaderVO, routeHeader); |
126 | |
|
127 | 0 | if (principalId != null) { |
128 | 0 | routeHeaderVO.setUserBlanketApprover(false); |
129 | 0 | if (routeHeader.getDocumentType() != null) { |
130 | 0 | boolean isBlanketApprover = KEWServiceLocator.getDocumentTypePermissionService().canBlanketApprove(principalId, routeHeader.getDocumentType(), routeHeader.getDocRouteStatus(), routeHeader.getInitiatorWorkflowId()); |
131 | 0 | routeHeaderVO.setUserBlanketApprover(isBlanketApprover); |
132 | |
} |
133 | 0 | AttributeSet actionsRequested = KEWServiceLocator.getActionRequestService().getActionsRequested(routeHeader, principalId, true); |
134 | 0 | for (String actionRequestCode : actionsRequested.keySet()) { |
135 | 0 | if (KEWConstants.ACTION_REQUEST_FYI_REQ.equals(actionRequestCode)) { |
136 | 0 | routeHeaderVO.setFyiRequested(Boolean.parseBoolean(actionsRequested.get(actionRequestCode))); |
137 | |
} |
138 | 0 | else if (KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ.equals(actionRequestCode)) { |
139 | 0 | routeHeaderVO.setAckRequested(Boolean.parseBoolean(actionsRequested.get(actionRequestCode))); |
140 | |
} |
141 | 0 | else if (KEWConstants.ACTION_REQUEST_APPROVE_REQ.equals(actionRequestCode)) { |
142 | 0 | routeHeaderVO.setApproveRequested(Boolean.parseBoolean(actionsRequested.get(actionRequestCode))); |
143 | |
} |
144 | |
else { |
145 | 0 | routeHeaderVO.setCompleteRequested(Boolean.parseBoolean(actionsRequested.get(actionRequestCode))); |
146 | |
} |
147 | |
} |
148 | |
|
149 | 0 | routeHeaderVO.setNotesToDelete(null); |
150 | 0 | routeHeaderVO.setNotes(convertNotesArrayListToNoteVOArray(routeHeader.getNotes())); |
151 | |
} |
152 | |
|
153 | |
|
154 | 0 | if (principalId != null) { |
155 | 0 | KimPrincipal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId); |
156 | 0 | routeHeaderVO.setValidActions(convertValidActions(KEWServiceLocator.getActionRegistry().getValidActions(principal, routeHeader))); |
157 | |
} |
158 | 0 | return routeHeaderVO; |
159 | |
} |
160 | |
|
161 | |
public static ValidActionsDTO convertValidActions(ValidActions validActions) { |
162 | 0 | ValidActionsDTO validActionsVO = new ValidActionsDTO(); |
163 | 0 | for (Iterator<String> iter = validActions.getActionTakenCodes().iterator(); iter.hasNext();) { |
164 | 0 | String actionTakenCode = iter.next(); |
165 | 0 | validActionsVO.addValidActionsAllowed(actionTakenCode); |
166 | 0 | } |
167 | 0 | return validActionsVO; |
168 | |
} |
169 | |
|
170 | |
private static void populateRouteHeaderVO(RouteHeaderDTO routeHeaderVO, DocumentRouteHeaderValue routeHeader) throws WorkflowException { |
171 | 0 | routeHeaderVO.setRouteHeaderId(routeHeader.getRouteHeaderId()); |
172 | 0 | routeHeaderVO.setAppDocId(routeHeader.getAppDocId()); |
173 | 0 | routeHeaderVO.setDateApproved(Utilities.convertTimestamp(routeHeader.getApprovedDate())); |
174 | 0 | routeHeaderVO.setDateCreated(Utilities.convertTimestamp(routeHeader.getCreateDate())); |
175 | 0 | routeHeaderVO.setDateFinalized(Utilities.convertTimestamp(routeHeader.getFinalizedDate())); |
176 | 0 | routeHeaderVO.setDateLastModified(Utilities.convertTimestamp(routeHeader.getStatusModDate())); |
177 | 0 | routeHeaderVO.setAppDocStatus(routeHeader.getAppDocStatus()); |
178 | 0 | routeHeaderVO.setAppDocStatusDate(Utilities.convertTimestamp(routeHeader.getAppDocStatusDate())); |
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | 0 | routeHeaderVO.setDocRouteLevel(routeHeader.getDocRouteLevel()); |
193 | 0 | routeHeaderVO.setCurrentRouteNodeNames(routeHeader.getCurrentRouteLevelName()); |
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | 0 | routeHeaderVO.setDocRouteStatus(routeHeader.getDocRouteStatus()); |
204 | 0 | routeHeaderVO.setDocTitle(routeHeader.getDocTitle()); |
205 | 0 | if (routeHeader.getDocumentType() != null) { |
206 | 0 | routeHeaderVO.setDocTypeName(routeHeader.getDocumentType().getName()); |
207 | 0 | routeHeaderVO.setDocumentUrl(routeHeader.getDocumentType().getDocHandlerUrl()); |
208 | 0 | routeHeaderVO.setDocTypeId(routeHeader.getDocumentTypeId()); |
209 | |
} |
210 | 0 | routeHeaderVO.setDocVersion(routeHeader.getDocVersion()); |
211 | 0 | routeHeaderVO.setInitiatorPrincipalId(routeHeader.getInitiatorWorkflowId()); |
212 | 0 | routeHeaderVO.setRoutedByPrincipalId(routeHeader.getRoutedByUserWorkflowId()); |
213 | |
|
214 | |
|
215 | |
|
216 | 0 | Branch routeNodeInstanceBranch = routeHeader.getRootBranch(); |
217 | |
|
218 | |
|
219 | 0 | if (routeNodeInstanceBranch != null) { |
220 | 0 | List listOfBranchStates = routeNodeInstanceBranch.getBranchState(); |
221 | 0 | Iterator it = listOfBranchStates.iterator(); |
222 | 0 | while (it.hasNext()) { |
223 | 0 | BranchState bs = (BranchState) it.next(); |
224 | 0 | if (bs.getKey() != null && bs.getKey().startsWith(BranchState.VARIABLE_PREFIX)) { |
225 | 0 | LOG.debug("Setting branch state variable on vo: " + bs.getKey() + "=" + bs.getValue()); |
226 | 0 | routeHeaderVO.setVariable(bs.getKey().substring(BranchState.VARIABLE_PREFIX.length()), bs.getValue()); |
227 | |
} |
228 | 0 | } |
229 | |
} |
230 | 0 | } |
231 | |
|
232 | |
public static DocumentRouteHeaderValue convertRouteHeaderVO(RouteHeaderDTO routeHeaderVO) throws WorkflowException { |
233 | 0 | DocumentRouteHeaderValue routeHeader = new DocumentRouteHeaderValue(); |
234 | 0 | routeHeader.setAppDocId(routeHeaderVO.getAppDocId()); |
235 | 0 | routeHeader.setApprovedDate(Utilities.convertCalendar(routeHeaderVO.getDateApproved())); |
236 | 0 | routeHeader.setCreateDate(Utilities.convertCalendar(routeHeaderVO.getDateCreated())); |
237 | 0 | if (StringUtils.isEmpty(routeHeader.getDocContent())) { |
238 | 0 | routeHeader.setDocContent(KEWConstants.DEFAULT_DOCUMENT_CONTENT); |
239 | |
} |
240 | 0 | routeHeader.setDocRouteLevel(routeHeaderVO.getDocRouteLevel()); |
241 | 0 | routeHeader.setDocRouteStatus(routeHeaderVO.getDocRouteStatus()); |
242 | 0 | routeHeader.setDocTitle(routeHeaderVO.getDocTitle()); |
243 | 0 | if (routeHeaderVO.getDocTypeName() != null) { |
244 | 0 | DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName(routeHeaderVO.getDocTypeName()); |
245 | 0 | if (documentType == null) { |
246 | 0 | throw new DocumentTypeNotFoundException("Could not locate the given document type name: " + routeHeaderVO.getDocTypeName()); |
247 | |
} |
248 | 0 | routeHeader.setDocumentTypeId(documentType.getDocumentTypeId()); |
249 | |
} |
250 | 0 | routeHeader.setDocVersion(routeHeaderVO.getDocVersion()); |
251 | 0 | routeHeader.setFinalizedDate(Utilities.convertCalendar(routeHeaderVO.getDateFinalized())); |
252 | 0 | routeHeader.setInitiatorWorkflowId(routeHeaderVO.getInitiatorPrincipalId()); |
253 | 0 | routeHeader.setRoutedByUserWorkflowId(routeHeaderVO.getRoutedByPrincipalId()); |
254 | 0 | routeHeader.setRouteHeaderId(routeHeaderVO.getRouteHeaderId()); |
255 | 0 | routeHeader.setStatusModDate(Utilities.convertCalendar(routeHeaderVO.getDateLastModified())); |
256 | 0 | routeHeader.setAppDocStatus(routeHeaderVO.getAppDocStatus()); |
257 | 0 | routeHeader.setAppDocStatusDate(Utilities.convertCalendar(routeHeaderVO.getAppDocStatusDate())); |
258 | |
|
259 | |
|
260 | |
|
261 | 0 | List<KeyValueDTO> variables = routeHeaderVO.getVariables(); |
262 | 0 | if( variables != null && !variables.isEmpty()){ |
263 | 0 | for(KeyValueDTO kvp : variables){ |
264 | 0 | routeHeader.setVariable(kvp.getKey(), kvp.getValue()); |
265 | |
} |
266 | |
} |
267 | |
|
268 | 0 | return routeHeader; |
269 | |
} |
270 | |
|
271 | |
public static ActionItemDTO convertActionItem(ActionItem actionItem) { |
272 | 0 | ActionItemDTO actionItemVO = new ActionItemDTO(); |
273 | 0 | actionItemVO.setActionItemId(actionItem.getActionItemId()); |
274 | 0 | actionItemVO.setActionItemIndex(actionItem.getActionItemIndex()); |
275 | 0 | actionItemVO.setActionRequestCd(actionItem.getActionRequestCd()); |
276 | 0 | actionItemVO.setActionRequestId(actionItem.getActionRequestId()); |
277 | 0 | actionItemVO.setActionToTake(actionItem.getActionToTake()); |
278 | 0 | actionItemVO.setDateAssigned(actionItem.getDateAssigned()); |
279 | 0 | actionItemVO.setDateAssignedString(actionItem.getDateAssignedString()); |
280 | 0 | actionItemVO.setDelegationType(actionItem.getDelegationType()); |
281 | 0 | actionItemVO.setDelegatorPrincipalId(actionItem.getDelegatorWorkflowId()); |
282 | 0 | actionItemVO.setDelegatorGroupId(actionItem.getDelegatorGroupId()); |
283 | 0 | actionItemVO.setDocHandlerURL(actionItem.getDocHandlerURL()); |
284 | 0 | actionItemVO.setDocLabel(actionItem.getDocLabel()); |
285 | 0 | actionItemVO.setDocName(actionItem.getDocName()); |
286 | 0 | actionItemVO.setDocTitle(actionItem.getDocTitle()); |
287 | 0 | actionItemVO.setResponsibilityId(actionItem.getResponsibilityId()); |
288 | 0 | actionItemVO.setRoleName(actionItem.getRoleName()); |
289 | 0 | actionItemVO.setRouteHeaderId(actionItem.getRouteHeaderId()); |
290 | 0 | actionItemVO.setPrincipalId(actionItem.getPrincipalId()); |
291 | 0 | actionItemVO.setGroupId(actionItem.getGroupId()); |
292 | 0 | return actionItemVO; |
293 | |
} |
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
public static String buildUpdatedDocumentContent(DocumentContentDTO documentContentVO) throws WorkflowException { |
301 | 0 | DocumentType documentType = null; |
302 | 0 | String documentContent = KEWConstants.DEFAULT_DOCUMENT_CONTENT; |
303 | |
try { |
304 | |
|
305 | 0 | String existingDocContent = KEWConstants.DEFAULT_DOCUMENT_CONTENT; |
306 | 0 | if (documentContentVO.getRouteHeaderId() != null) { |
307 | 0 | DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentContentVO.getRouteHeaderId()); |
308 | 0 | documentType = document.getDocumentType(); |
309 | 0 | existingDocContent = document.getDocContent(); |
310 | |
} |
311 | 0 | StandardDocumentContent standardDocContent = new StandardDocumentContent(existingDocContent); |
312 | 0 | DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
313 | 0 | Document document = builder.newDocument(); |
314 | 0 | Element root = document.createElement(KEWConstants.DOCUMENT_CONTENT_ELEMENT); |
315 | 0 | document.appendChild(root); |
316 | 0 | Element applicationContentElement = standardDocContent.getApplicationContent(); |
317 | 0 | if (documentContentVO.getApplicationContent() != null) { |
318 | |
|
319 | 0 | if (!Utilities.isEmpty(documentContentVO.getApplicationContent())) { |
320 | 0 | applicationContentElement = document.createElement(KEWConstants.APPLICATION_CONTENT_ELEMENT); |
321 | 0 | XmlHelper.appendXml(applicationContentElement, documentContentVO.getApplicationContent()); |
322 | |
} else { |
323 | |
|
324 | 0 | applicationContentElement = null; |
325 | |
} |
326 | |
} |
327 | 0 | Element attributeContentElement = createDocumentContentSection(document, standardDocContent.getAttributeContent(), documentContentVO.getAttributeDefinitions(), documentContentVO.getAttributeContent(), KEWConstants.ATTRIBUTE_CONTENT_ELEMENT, documentType); |
328 | 0 | Element searchableContentElement = createDocumentContentSection(document, standardDocContent.getSearchableContent(), documentContentVO.getSearchableDefinitions(), documentContentVO.getSearchableContent(), KEWConstants.SEARCHABLE_CONTENT_ELEMENT, documentType); |
329 | 0 | if (applicationContentElement != null) { |
330 | 0 | root.appendChild(applicationContentElement); |
331 | |
} |
332 | 0 | if (attributeContentElement != null) { |
333 | 0 | root.appendChild(attributeContentElement); |
334 | |
} |
335 | 0 | if (searchableContentElement != null) { |
336 | 0 | root.appendChild(searchableContentElement); |
337 | |
} |
338 | 0 | documentContent = XmlHelper.writeNode(document); |
339 | 0 | } catch (Exception e) { |
340 | 0 | handleException("Error parsing document content.", e); |
341 | 0 | } |
342 | 0 | return documentContent; |
343 | |
} |
344 | |
|
345 | |
private static Element createDocumentContentSection(Document document, Element existingAttributeElement, WorkflowAttributeDefinitionDTO[] definitions, String content, String elementName, DocumentType documentType) throws Exception { |
346 | 0 | Element contentSectionElement = existingAttributeElement; |
347 | |
|
348 | 0 | if (content != null) { |
349 | 0 | if (!Utilities.isEmpty(content)) { |
350 | 0 | contentSectionElement = document.createElement(elementName); |
351 | |
|
352 | |
|
353 | 0 | Element incomingAttributeElement = XmlHelper.readXml(content).getDocumentElement(); |
354 | 0 | NodeList children = incomingAttributeElement.getChildNodes(); |
355 | 0 | for (int index = 0; index < children.getLength(); index++) { |
356 | 0 | contentSectionElement.appendChild(document.importNode(children.item(index), true)); |
357 | |
} |
358 | 0 | } else { |
359 | 0 | contentSectionElement = null; |
360 | |
} |
361 | |
} |
362 | |
|
363 | 0 | if (!Utilities.isEmpty(definitions)) { |
364 | 0 | String errorMessage = ""; |
365 | 0 | boolean inError = false; |
366 | 0 | if (contentSectionElement == null) { |
367 | 0 | contentSectionElement = document.createElement(elementName); |
368 | |
} |
369 | 0 | for (int index = 0; index < definitions.length; index++) { |
370 | 0 | WorkflowAttributeDefinitionDTO definitionVO = definitions[index]; |
371 | 0 | AttributeDefinition definition = convertWorkflowAttributeDefinitionVO(definitionVO, documentType); |
372 | 0 | RuleAttribute ruleAttribute = definition.getRuleAttribute(); |
373 | 0 | Object attribute = GlobalResourceLoader.getResourceLoader().getObject(definition.getObjectDefinition()); |
374 | 0 | boolean propertiesAsMap = false; |
375 | 0 | if (KEWConstants.RULE_XML_ATTRIBUTE_TYPE.equals(ruleAttribute.getType())) { |
376 | 0 | ((GenericXMLRuleAttribute) attribute).setRuleAttribute(ruleAttribute); |
377 | 0 | propertiesAsMap = true; |
378 | 0 | } else if (KEWConstants.SEARCHABLE_XML_ATTRIBUTE_TYPE.equals(ruleAttribute.getType())) { |
379 | 0 | ((GenericXMLSearchableAttribute) attribute).setRuleAttribute(ruleAttribute); |
380 | 0 | propertiesAsMap = true; |
381 | |
} |
382 | 0 | if (propertiesAsMap) { |
383 | 0 | for (PropertyDefinitionDTO propertyDefinitionVO : definitionVO.getProperties()) { |
384 | 0 | if (attribute instanceof GenericXMLRuleAttribute) { |
385 | 0 | ((GenericXMLRuleAttribute) attribute).getParamMap().put(propertyDefinitionVO.getName(), propertyDefinitionVO.getValue()); |
386 | 0 | } else if (attribute instanceof GenericXMLSearchableAttribute) { |
387 | 0 | ((GenericXMLSearchableAttribute) attribute).getParamMap().put(propertyDefinitionVO.getName(), propertyDefinitionVO.getValue()); |
388 | |
} |
389 | |
} |
390 | |
} |
391 | |
|
392 | |
|
393 | 0 | if (attribute instanceof WorkflowAttributeXmlValidator) { |
394 | 0 | List<WorkflowAttributeValidationError> errors = ((WorkflowAttributeXmlValidator) attribute).validateClientRoutingData(); |
395 | 0 | if (!errors.isEmpty()) { |
396 | 0 | inError = true; |
397 | 0 | errorMessage += "Error validating attribute " + definitions[index].getAttributeName() + " "; |
398 | 0 | for (WorkflowAttributeValidationError error : errors) { |
399 | 0 | errorMessage += error.getMessage() + " "; |
400 | |
} |
401 | |
} |
402 | |
} |
403 | |
|
404 | 0 | if (!inError) { |
405 | 0 | if (attribute instanceof WorkflowAttribute) { |
406 | 0 | String attributeDocContent = ((WorkflowAttribute) attribute).getDocContent(); |
407 | 0 | if (!StringUtils.isEmpty(attributeDocContent)) { |
408 | 0 | XmlHelper.appendXml(contentSectionElement, attributeDocContent); |
409 | |
} |
410 | 0 | } else if (attribute instanceof SearchableAttribute) { |
411 | 0 | String searcheAttributeContent = |
412 | |
((SearchableAttribute) attribute).getSearchContent(DocSearchUtils.getDocumentSearchContext("", documentType.getName(), "")); |
413 | 0 | if (!StringUtils.isEmpty(searcheAttributeContent)) { |
414 | 0 | XmlHelper.appendXml(contentSectionElement, searcheAttributeContent); |
415 | |
} |
416 | |
} |
417 | |
} |
418 | |
} |
419 | 0 | if (inError) { |
420 | 0 | throw new WorkflowRuntimeException(errorMessage); |
421 | |
} |
422 | |
|
423 | |
} |
424 | 0 | if (contentSectionElement != null) { |
425 | |
|
426 | |
|
427 | |
|
428 | 0 | contentSectionElement = (Element) document.importNode(contentSectionElement, true); |
429 | |
} |
430 | 0 | return contentSectionElement; |
431 | |
} |
432 | |
|
433 | |
public static DocumentContentDTO convertDocumentContent(String documentContentValue, Long documentId) throws WorkflowException { |
434 | 0 | if (documentContentValue == null) { |
435 | 0 | return null; |
436 | |
} |
437 | 0 | DocumentContentDTO documentContentVO = new DocumentContentDTO(); |
438 | |
|
439 | 0 | documentContentVO.setApplicationContent(""); |
440 | 0 | documentContentVO.setAttributeContent(""); |
441 | 0 | documentContentVO.setSearchableContent(""); |
442 | 0 | documentContentVO.setRouteHeaderId(documentId); |
443 | |
try { |
444 | 0 | DocumentContent documentContent = new StandardDocumentContent(documentContentValue); |
445 | 0 | if (documentContent.getApplicationContent() != null) { |
446 | 0 | documentContentVO.setApplicationContent(XmlHelper.writeNode(documentContent.getApplicationContent())); |
447 | |
} |
448 | 0 | if (documentContent.getAttributeContent() != null) { |
449 | 0 | documentContentVO.setAttributeContent(XmlHelper.writeNode(documentContent.getAttributeContent())); |
450 | |
} |
451 | 0 | if (documentContent.getSearchableContent() != null) { |
452 | 0 | documentContentVO.setSearchableContent(XmlHelper.writeNode(documentContent.getSearchableContent())); |
453 | |
} |
454 | 0 | } catch (Exception e) { |
455 | 0 | handleException("Error parsing document content.", e); |
456 | 0 | } |
457 | 0 | return documentContentVO; |
458 | |
} |
459 | |
|
460 | |
public static DocumentTypeDTO convertDocumentType(DocumentType docType) { |
461 | 0 | if (docType == null) { |
462 | 0 | return null; |
463 | |
} |
464 | 0 | DocumentTypeDTO docTypeVO = new DocumentTypeDTO(); |
465 | 0 | docTypeVO.setDocTypeParentId(docType.getDocTypeParentId()); |
466 | 0 | if (docType.getParentDocType() != null) { |
467 | 0 | docTypeVO.setDocTypeParentName(docType.getParentDocType().getName()); |
468 | |
} |
469 | |
|
470 | 0 | docTypeVO.setDocTypeDescription(docType.getDescription()); |
471 | 0 | docTypeVO.setDocTypeHandlerUrl(docType.getDocHandlerUrl()); |
472 | 0 | docTypeVO.setHelpDefinitionUrl(docType.getHelpDefinitionUrl()); |
473 | 0 | docTypeVO.setDocSearchHelpUrl(docType.getDocSearchHelpUrl()); |
474 | 0 | docTypeVO.setDocTypeId(docType.getDocumentTypeId()); |
475 | 0 | docTypeVO.setDocTypeLabel(docType.getLabel()); |
476 | 0 | docTypeVO.setName(docType.getName()); |
477 | 0 | docTypeVO.setDocTypeVersion(docType.getVersion()); |
478 | 0 | Boolean currentInd = docType.getCurrentInd(); |
479 | 0 | if (currentInd == null) { |
480 | 0 | docTypeVO.setDocTypeCurrentInd(null); |
481 | 0 | } else if (currentInd.booleanValue()) { |
482 | 0 | docTypeVO.setDocTypeCurrentInd(KEWConstants.ACTIVE_CD); |
483 | |
} else { |
484 | 0 | docTypeVO.setDocTypeCurrentInd(KEWConstants.INACTIVE_CD); |
485 | |
} |
486 | 0 | docTypeVO.setPostProcessorName(docType.getPostProcessorName()); |
487 | 0 | docTypeVO.setDocTypeJndiFactoryClass(null); |
488 | 0 | docTypeVO.setDocTypeActiveInd(docType.getActive().booleanValue()); |
489 | 0 | if (docType.getParentDocType() != null) { |
490 | 0 | docTypeVO.setDocTypeActiveInherited(true); |
491 | |
} else { |
492 | 0 | docTypeVO.setDocTypeActiveInherited(false); |
493 | |
} |
494 | 0 | Group blanketGroup = docType.getBlanketApproveWorkgroup(); |
495 | 0 | if (blanketGroup != null) { |
496 | 0 | docTypeVO.setBlanketApproveGroupId(blanketGroup.getGroupId()); |
497 | |
} |
498 | 0 | docTypeVO.setBlanketApprovePolicy(docType.getBlanketApprovePolicy()); |
499 | 0 | docTypeVO.setRoutePath(convertRoutePath(docType)); |
500 | 0 | return docTypeVO; |
501 | |
} |
502 | |
|
503 | |
public static RoutePathDTO convertRoutePath(DocumentType documentType) { |
504 | 0 | RoutePathDTO routePath = new RoutePathDTO(); |
505 | 0 | ProcessDTO[] processes = new ProcessDTO[documentType.getProcesses().size()]; |
506 | 0 | int index = 0; |
507 | 0 | for (Iterator iterator = documentType.getProcesses().iterator(); iterator.hasNext();) { |
508 | 0 | Process process = (Process) iterator.next(); |
509 | 0 | processes[index++] = convertProcess(process); |
510 | 0 | } |
511 | 0 | routePath.setProcesses(processes); |
512 | 0 | return routePath; |
513 | |
} |
514 | |
|
515 | |
public static ActionRequestDTO convertActionRequest(ActionRequestValue actionRequest) { |
516 | 0 | return convertActionRequest(actionRequest, true); |
517 | |
} |
518 | |
|
519 | |
protected static ActionRequestDTO convertActionRequest(ActionRequestValue actionRequest, boolean includeActionTaken) { |
520 | 0 | ActionRequestDTO actionRequestVO = new ActionRequestDTO(); |
521 | 0 | actionRequestVO.setActionRequested(actionRequest.getActionRequested()); |
522 | 0 | actionRequestVO.setActionRequestId(actionRequest.getActionRequestId()); |
523 | |
|
524 | 0 | if (includeActionTaken && (actionRequest.getActionTaken() != null)) { |
525 | 0 | actionRequestVO.setActionTakenId(actionRequest.getActionTakenId()); |
526 | 0 | actionRequestVO.setActionTaken(convertActionTaken(actionRequest.getActionTaken())); |
527 | |
} |
528 | |
|
529 | 0 | actionRequestVO.setAnnotation(actionRequest.getAnnotation()); |
530 | 0 | actionRequestVO.setDateCreated(Utilities.convertTimestamp(actionRequest.getCreateDate())); |
531 | 0 | actionRequestVO.setDocVersion(actionRequest.getDocVersion()); |
532 | 0 | actionRequestVO.setPrincipalId(actionRequest.getPrincipalId()); |
533 | 0 | actionRequestVO.setForceAction(actionRequest.getForceAction()); |
534 | 0 | actionRequestVO.setPriority(actionRequest.getPriority()); |
535 | 0 | actionRequestVO.setRecipientTypeCd(actionRequest.getRecipientTypeCd()); |
536 | 0 | actionRequestVO.setResponsibilityDesc(actionRequest.getResponsibilityDesc()); |
537 | 0 | actionRequestVO.setResponsibilityId(actionRequest.getResponsibilityId()); |
538 | 0 | actionRequestVO.setRouteHeaderId(actionRequest.getRouteHeaderId()); |
539 | 0 | actionRequestVO.setRouteLevel(actionRequest.getRouteLevel()); |
540 | 0 | actionRequestVO.setNodeName(actionRequest.getPotentialNodeName()); |
541 | 0 | actionRequestVO.setNodeInstanceId((actionRequest.getNodeInstance() == null ? null : actionRequest.getNodeInstance().getRouteNodeInstanceId())); |
542 | |
|
543 | 0 | actionRequestVO.setRoleName(actionRequest.getQualifiedRoleName()); |
544 | 0 | actionRequestVO.setQualifiedRoleName(actionRequest.getQualifiedRoleName()); |
545 | 0 | actionRequestVO.setQualifiedRoleNameLabel(actionRequest.getQualifiedRoleNameLabel()); |
546 | 0 | actionRequestVO.setStatus(actionRequest.getStatus()); |
547 | 0 | actionRequestVO.setGroupId(actionRequest.getGroupId()); |
548 | 0 | actionRequestVO.setDelegationType(actionRequest.getDelegationType()); |
549 | 0 | actionRequestVO.setParentActionRequestId(actionRequest.getParentActionRequestId()); |
550 | 0 | actionRequestVO.setRequestLabel(actionRequest.getRequestLabel()); |
551 | 0 | ActionRequestDTO[] childRequestVOs = new ActionRequestDTO[actionRequest.getChildrenRequests().size()]; |
552 | 0 | int index = 0; |
553 | 0 | for (ActionRequestValue childRequest : actionRequest.getChildrenRequests()) { |
554 | 0 | ActionRequestDTO childRequestVO = convertActionRequest(childRequest); |
555 | 0 | childRequestVOs[index++] = childRequestVO; |
556 | 0 | } |
557 | 0 | actionRequestVO.setChildrenRequests(childRequestVOs); |
558 | 0 | return actionRequestVO; |
559 | |
} |
560 | |
|
561 | |
public static ActionTakenDTO convertActionTakenWithActionRequests(ActionTakenValue actionTaken) { |
562 | 0 | return convertActionTaken(actionTaken, true); |
563 | |
} |
564 | |
|
565 | |
public static ActionTakenDTO convertActionTaken(ActionTakenValue actionTaken) { |
566 | 0 | return convertActionTaken(actionTaken, false); |
567 | |
} |
568 | |
|
569 | |
protected static ActionTakenDTO convertActionTaken(ActionTakenValue actionTaken, boolean fetchActionRequests) { |
570 | 0 | if (actionTaken == null) { |
571 | 0 | return null; |
572 | |
} |
573 | 0 | ActionTakenDTO actionTakenVO = new ActionTakenDTO(); |
574 | 0 | actionTakenVO.setActionDate(Utilities.convertTimestamp(actionTaken.getActionDate())); |
575 | 0 | actionTakenVO.setActionTaken(actionTaken.getActionTaken()); |
576 | 0 | actionTakenVO.setActionTakenId(actionTaken.getActionTakenId()); |
577 | 0 | actionTakenVO.setAnnotation(actionTaken.getAnnotation()); |
578 | 0 | actionTakenVO.setDocVersion(actionTaken.getDocVersion()); |
579 | 0 | actionTakenVO.setRouteHeaderId(actionTaken.getRouteHeaderId()); |
580 | 0 | actionTakenVO.setPrincipalId(actionTaken.getPrincipalId()); |
581 | 0 | actionTakenVO.setDelegatorPrincpalId(actionTaken.getDelegatorPrincipalId()); |
582 | 0 | actionTakenVO.setDelegatorGroupId(actionTaken.getDelegatorGroupId()); |
583 | 0 | if (fetchActionRequests) { |
584 | 0 | ActionRequestDTO[] actionRequests = new ActionRequestDTO[actionTaken.getActionRequests().size()]; |
585 | 0 | int index = 0; |
586 | 0 | for (Iterator iterator = actionTaken.getActionRequests().iterator(); iterator.hasNext();) { |
587 | 0 | ActionRequestValue actionRequest = (ActionRequestValue) iterator.next(); |
588 | 0 | actionRequests[index++] = convertActionRequest(actionRequest, false); |
589 | 0 | } |
590 | 0 | actionTakenVO.setActionRequests(actionRequests); |
591 | |
} |
592 | 0 | return actionTakenVO; |
593 | |
} |
594 | |
|
595 | |
public static ResponsiblePartyDTO convertResponsibleParty(ResponsibleParty responsibleParty) { |
596 | 0 | if (responsibleParty == null) { |
597 | 0 | return null; |
598 | |
} |
599 | 0 | ResponsiblePartyDTO responsiblePartyVO = new ResponsiblePartyDTO(); |
600 | 0 | responsiblePartyVO.setGroupId(responsibleParty.getGroupId()); |
601 | 0 | responsiblePartyVO.setPrincipalId(responsibleParty.getPrincipalId()); |
602 | 0 | responsiblePartyVO.setRoleName(responsibleParty.getRoleName()); |
603 | 0 | return responsiblePartyVO; |
604 | |
} |
605 | |
|
606 | |
public static ResponsibleParty convertResponsiblePartyVO(ResponsiblePartyDTO responsiblePartyVO) { |
607 | 0 | if (responsiblePartyVO == null) { |
608 | 0 | return null; |
609 | |
} |
610 | 0 | ResponsibleParty responsibleParty = new ResponsibleParty(); |
611 | 0 | responsibleParty.setGroupId(responsiblePartyVO.getGroupId()); |
612 | 0 | responsibleParty.setPrincipalId(responsiblePartyVO.getPrincipalId()); |
613 | 0 | responsibleParty.setRoleName(responsiblePartyVO.getRoleName()); |
614 | 0 | return responsibleParty; |
615 | |
} |
616 | |
|
617 | |
|
618 | |
|
619 | |
|
620 | |
|
621 | |
|
622 | |
|
623 | |
public static Recipient convertResponsiblePartyVOtoRecipient(ResponsiblePartyDTO responsiblePartyVO) { |
624 | 0 | if (responsiblePartyVO == null) { |
625 | 0 | return null; |
626 | |
} |
627 | 0 | if (responsiblePartyVO.getRoleName() != null) { |
628 | 0 | return new RoleRecipient(responsiblePartyVO.getRoleName()); |
629 | |
} |
630 | 0 | String groupId = responsiblePartyVO.getGroupId(); |
631 | 0 | if (groupId != null) { |
632 | 0 | Group group = KIMServiceLocator.getIdentityManagementService().getGroup(groupId); |
633 | 0 | if (group == null) { |
634 | 0 | throw new RiceRuntimeException("Failed to locate group with ID: " + groupId); |
635 | |
} |
636 | 0 | return new KimGroupRecipient(group); |
637 | |
} |
638 | 0 | String principalId = responsiblePartyVO.getPrincipalId(); |
639 | 0 | if (principalId != null) { |
640 | 0 | return new KimPrincipalRecipient(principalId); |
641 | |
} |
642 | 0 | throw new WorkflowRuntimeException("ResponsibleParty of unknown type"); |
643 | |
} |
644 | |
|
645 | |
|
646 | |
|
647 | |
|
648 | 0 | public static interface RouteNodeInstanceLoader { |
649 | |
RouteNodeInstance load(Long routeNodeInstanceID); |
650 | |
} |
651 | |
|
652 | |
|
653 | |
|
654 | |
|
655 | |
|
656 | |
|
657 | |
|
658 | |
|
659 | |
|
660 | |
public static ActionRequestValue convertActionRequestDTO(ActionRequestDTO actionRequestDTO) { |
661 | 0 | return convertActionRequestDTO(actionRequestDTO, null); |
662 | |
} |
663 | |
|
664 | |
|
665 | |
|
666 | |
|
667 | |
|
668 | |
|
669 | |
|
670 | |
public static ActionRequestValue convertActionRequestDTO(ActionRequestDTO actionRequestDTO, |
671 | |
RouteNodeInstanceLoader routeNodeInstanceLoader) { |
672 | |
|
673 | 0 | if (actionRequestDTO == null) { |
674 | 0 | return null; |
675 | |
} |
676 | 0 | if (actionRequestDTO.getParentActionRequestId() != null) { |
677 | 0 | throw new IllegalArgumentException("Cannot convert a non-root ActionRequestVO"); |
678 | |
} |
679 | 0 | ActionRequestValue actionRequest = new ActionRequestFactory().createBlankActionRequest(); |
680 | 0 | populateActionRequest(actionRequest, actionRequestDTO, routeNodeInstanceLoader); |
681 | 0 | if (actionRequestDTO.getChildrenRequests() != null) { |
682 | 0 | for (int i = 0; i < actionRequestDTO.getChildrenRequests().length; i++) { |
683 | 0 | ActionRequestDTO childVO = actionRequestDTO.getChildrenRequests()[i]; |
684 | 0 | actionRequest.getChildrenRequests().add(convertActionRequestVO(childVO, actionRequest, routeNodeInstanceLoader)); |
685 | |
} |
686 | |
} |
687 | 0 | return actionRequest; |
688 | |
} |
689 | |
|
690 | |
|
691 | |
protected static ActionRequestValue convertActionRequestVO(ActionRequestDTO actionRequestDTO, ActionRequestValue parentActionRequest, |
692 | |
RouteNodeInstanceLoader routeNodeInstanceLoader) { |
693 | 0 | if (actionRequestDTO == null) { |
694 | 0 | return null; |
695 | |
} |
696 | 0 | ActionRequestValue actionRequest = new ActionRequestFactory().createBlankActionRequest(); |
697 | 0 | populateActionRequest(actionRequest, actionRequestDTO, routeNodeInstanceLoader); |
698 | 0 | actionRequest.setParentActionRequest(parentActionRequest); |
699 | 0 | actionRequest.setParentActionRequestId(parentActionRequest.getActionRequestId()); |
700 | 0 | if (actionRequestDTO.getChildrenRequests() != null) { |
701 | 0 | for (int i = 0; i < actionRequestDTO.getChildrenRequests().length; i++) { |
702 | 0 | ActionRequestDTO childVO = actionRequestDTO.getChildrenRequests()[i]; |
703 | 0 | actionRequest.getChildrenRequests().add(convertActionRequestVO(childVO, actionRequest, routeNodeInstanceLoader)); |
704 | |
} |
705 | |
} |
706 | 0 | return actionRequest; |
707 | |
} |
708 | |
|
709 | |
|
710 | |
|
711 | |
|
712 | |
private static void populateActionRequest(ActionRequestValue actionRequest, ActionRequestDTO actionRequestDTO, |
713 | |
RouteNodeInstanceLoader routeNodeInstanceLoader) { |
714 | |
|
715 | 0 | actionRequest.setActionRequested(actionRequestDTO.getActionRequested()); |
716 | 0 | actionRequest.setActionRequestId(actionRequestDTO.getActionRequestId()); |
717 | 0 | actionRequest.setActionTakenId(actionRequestDTO.getActionTakenId()); |
718 | 0 | actionRequest.setAnnotation(actionRequestDTO.getAnnotation()); |
719 | 0 | actionRequest.setApprovePolicy(actionRequestDTO.getApprovePolicy()); |
720 | 0 | actionRequest.setCreateDate(new Timestamp(new Date().getTime())); |
721 | 0 | actionRequest.setCurrentIndicator(actionRequestDTO.getCurrentIndicator()); |
722 | 0 | actionRequest.setDelegationType(actionRequestDTO.getDelegationType()); |
723 | 0 | actionRequest.setDocVersion(actionRequestDTO.getDocVersion()); |
724 | 0 | actionRequest.setForceAction(actionRequestDTO.getForceAction()); |
725 | 0 | actionRequest.setPriority(actionRequestDTO.getPriority()); |
726 | 0 | actionRequest.setQualifiedRoleName(actionRequestDTO.getQualifiedRoleName()); |
727 | 0 | actionRequest.setQualifiedRoleNameLabel(actionRequestDTO.getQualifiedRoleNameLabel()); |
728 | 0 | actionRequest.setRecipientTypeCd(actionRequestDTO.getRecipientTypeCd()); |
729 | 0 | actionRequest.setResponsibilityDesc(actionRequestDTO.getResponsibilityDesc()); |
730 | 0 | actionRequest.setResponsibilityId(actionRequestDTO.getResponsibilityId()); |
731 | 0 | actionRequest.setRoleName(actionRequestDTO.getRoleName()); |
732 | 0 | Long routeHeaderId = actionRequestDTO.getRouteHeaderId(); |
733 | 0 | if (routeHeaderId != null) { |
734 | 0 | actionRequest.setRouteHeaderId(routeHeaderId); |
735 | 0 | actionRequest.setRouteHeader(KEWServiceLocator.getRouteHeaderService().getRouteHeader(routeHeaderId)); |
736 | |
} |
737 | 0 | actionRequest.setRouteLevel(actionRequestDTO.getRouteLevel()); |
738 | |
|
739 | 0 | actionRequest.setStatus(actionRequestDTO.getStatus()); |
740 | 0 | actionRequest.setPrincipalId(actionRequestDTO.getPrincipalId()); |
741 | 0 | actionRequest.setGroupId(actionRequestDTO.getGroupId()); |
742 | |
|
743 | 0 | if (routeNodeInstanceLoader != null && actionRequestDTO.getNodeInstanceId() != null) { |
744 | 0 | actionRequest.setNodeInstance(routeNodeInstanceLoader.load(actionRequestDTO.getNodeInstanceId())); |
745 | |
} |
746 | 0 | } |
747 | |
|
748 | |
public static ActionTakenValue convertActionTakenVO(ActionTakenDTO actionTakenVO) { |
749 | 0 | if (actionTakenVO == null) { |
750 | 0 | return null; |
751 | |
} |
752 | 0 | ActionTakenValue actionTaken = new ActionTakenValue(); |
753 | 0 | actionTaken.setActionDate(new Timestamp(actionTakenVO.getActionDate().getTimeInMillis())); |
754 | 0 | actionTaken.setActionTaken(actionTakenVO.getActionTaken()); |
755 | 0 | actionTaken.setActionTakenId(actionTakenVO.getActionTakenId()); |
756 | 0 | actionTaken.setAnnotation(actionTakenVO.getAnnotation()); |
757 | 0 | actionTaken.setCurrentIndicator(Boolean.TRUE); |
758 | 0 | actionTaken.setPrincipalId(actionTakenVO.getPrincipalId()); |
759 | 0 | actionTaken.setDelegatorPrincipalId(actionTakenVO.getDelegatorPrincpalId()); |
760 | 0 | actionTaken.setDelegatorGroupId(actionTakenVO.getDelegatorGroupId()); |
761 | 0 | actionTaken.setDocVersion(actionTakenVO.getDocVersion()); |
762 | 0 | DocumentRouteHeaderValue routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(actionTakenVO.getRouteHeaderId()); |
763 | 0 | actionTaken.setRouteHeader(routeHeader); |
764 | 0 | actionTaken.setRouteHeaderId(actionTaken.getRouteHeaderId()); |
765 | 0 | return actionTaken; |
766 | |
} |
767 | |
|
768 | |
public static DocumentRouteStatusChangeDTO convertDocumentRouteStatusChange(DocumentRouteStatusChange statusChange) { |
769 | 0 | if (statusChange == null) { |
770 | 0 | return null; |
771 | |
} |
772 | 0 | DocumentRouteStatusChangeDTO statusChangeVO = new DocumentRouteStatusChangeDTO(); |
773 | 0 | statusChangeVO.setRouteHeaderId(statusChange.getRouteHeaderId()); |
774 | 0 | statusChangeVO.setAppDocId(statusChange.getAppDocId()); |
775 | 0 | statusChangeVO.setOldRouteStatus(statusChange.getOldRouteStatus()); |
776 | 0 | statusChangeVO.setNewRouteStatus(statusChange.getNewRouteStatus()); |
777 | 0 | return statusChangeVO; |
778 | |
} |
779 | |
|
780 | |
public static DocumentRouteLevelChangeDTO convertDocumentRouteLevelChange(DocumentRouteLevelChange routeLevelChange) { |
781 | 0 | if (routeLevelChange == null) { |
782 | 0 | return null; |
783 | |
} |
784 | 0 | DocumentRouteLevelChangeDTO routeLevelChangeVO = new DocumentRouteLevelChangeDTO(); |
785 | 0 | routeLevelChangeVO.setRouteHeaderId(routeLevelChange.getRouteHeaderId()); |
786 | 0 | routeLevelChangeVO.setAppDocId(routeLevelChange.getAppDocId()); |
787 | 0 | routeLevelChangeVO.setOldRouteLevel(routeLevelChange.getOldRouteLevel()); |
788 | 0 | routeLevelChangeVO.setNewRouteLevel(routeLevelChange.getNewRouteLevel()); |
789 | 0 | routeLevelChangeVO.setOldNodeName(routeLevelChange.getOldNodeName()); |
790 | 0 | routeLevelChangeVO.setNewNodeName(routeLevelChange.getNewNodeName()); |
791 | 0 | routeLevelChangeVO.setOldNodeInstanceId(routeLevelChange.getOldNodeInstanceId()); |
792 | 0 | routeLevelChangeVO.setNewNodeInstanceId(routeLevelChange.getNewNodeInstanceId()); |
793 | 0 | return routeLevelChangeVO; |
794 | |
} |
795 | |
|
796 | |
public static DeleteEventDTO convertDeleteEvent(DeleteEvent deleteEvent) { |
797 | 0 | if (deleteEvent == null) { |
798 | 0 | return null; |
799 | |
} |
800 | 0 | DeleteEventDTO deleteEventVO = new DeleteEventDTO(); |
801 | 0 | deleteEventVO.setRouteHeaderId(deleteEvent.getRouteHeaderId()); |
802 | 0 | deleteEventVO.setAppDocId(deleteEvent.getAppDocId()); |
803 | 0 | return deleteEventVO; |
804 | |
} |
805 | |
|
806 | |
public static ActionTakenEventDTO convertActionTakenEvent(ActionTakenEvent actionTakenEvent) { |
807 | 0 | if (actionTakenEvent == null) { |
808 | 0 | return null; |
809 | |
} |
810 | 0 | ActionTakenEventDTO actionTakenEventVO = new ActionTakenEventDTO(); |
811 | 0 | actionTakenEventVO.setRouteHeaderId(actionTakenEvent.getRouteHeaderId()); |
812 | 0 | actionTakenEventVO.setAppDocId(actionTakenEvent.getAppDocId()); |
813 | 0 | actionTakenEventVO.setActionTaken(convertActionTaken(actionTakenEvent.getActionTaken())); |
814 | 0 | return actionTakenEventVO; |
815 | |
} |
816 | |
|
817 | |
public static BeforeProcessEventDTO convertBeforeProcessEvent(BeforeProcessEvent event) { |
818 | 0 | if (event == null) { |
819 | 0 | return null; |
820 | |
} |
821 | 0 | BeforeProcessEventDTO beforeProcessEvent = new BeforeProcessEventDTO(); |
822 | 0 | beforeProcessEvent.setRouteHeaderId(event.getRouteHeaderId()); |
823 | 0 | beforeProcessEvent.setAppDocId(event.getAppDocId()); |
824 | 0 | beforeProcessEvent.setNodeInstanceId(event.getNodeInstanceId()); |
825 | 0 | return beforeProcessEvent; |
826 | |
} |
827 | |
|
828 | |
public static AfterProcessEventDTO convertAfterProcessEvent(AfterProcessEvent event) { |
829 | 0 | if (event == null) { |
830 | 0 | return null; |
831 | |
} |
832 | 0 | AfterProcessEventDTO afterProcessEvent = new AfterProcessEventDTO(); |
833 | 0 | afterProcessEvent.setRouteHeaderId(event.getRouteHeaderId()); |
834 | 0 | afterProcessEvent.setAppDocId(event.getAppDocId()); |
835 | 0 | afterProcessEvent.setNodeInstanceId(event.getNodeInstanceId()); |
836 | 0 | afterProcessEvent.setSuccessfullyProcessed(event.isSuccessfullyProcessed()); |
837 | 0 | return afterProcessEvent; |
838 | |
} |
839 | |
|
840 | |
public static DocumentLockingEventDTO convertDocumentLockingEvent(DocumentLockingEvent event) { |
841 | 0 | if (event == null) { |
842 | 0 | return null; |
843 | |
} |
844 | 0 | DocumentLockingEventDTO documentLockingEvent = new DocumentLockingEventDTO(); |
845 | 0 | documentLockingEvent.setRouteHeaderId(event.getRouteHeaderId()); |
846 | 0 | documentLockingEvent.setAppDocId(event.getAppDocId()); |
847 | 0 | return documentLockingEvent; |
848 | |
} |
849 | |
|
850 | |
|
851 | |
public static AttributeDefinition convertWorkflowAttributeDefinitionVO(WorkflowAttributeDefinitionDTO definitionVO, org.kuali.rice.kew.doctype.bo.DocumentType documentType) { |
852 | 0 | if (definitionVO == null) { |
853 | 0 | return null; |
854 | |
} |
855 | |
|
856 | 0 | RuleAttribute ruleAttribute = KEWServiceLocator.getRuleAttributeService().findByClassName(definitionVO.getAttributeName()); |
857 | 0 | if (ruleAttribute == null) { |
858 | 0 | ruleAttribute = KEWServiceLocator.getRuleAttributeService().findByName(definitionVO.getAttributeName()); |
859 | |
} |
860 | 0 | if (ruleAttribute == null) { |
861 | 0 | throw new WorkflowRuntimeException("Attribute " + definitionVO.getAttributeName() + " not found"); |
862 | |
} |
863 | |
|
864 | 0 | ObjectDefinition definition = new ObjectDefinition(ruleAttribute.getClassName()); |
865 | 0 | for (int index = 0; index < definitionVO.getConstructorParameters().length; index++) { |
866 | 0 | String parameter = definitionVO.getConstructorParameters()[index]; |
867 | 0 | definition.addConstructorParameter(new DataDefinition(parameter, String.class)); |
868 | |
} |
869 | 0 | boolean propertiesAsMap = KEWConstants.RULE_XML_ATTRIBUTE_TYPE.equals(ruleAttribute.getType()) || KEWConstants.SEARCHABLE_XML_ATTRIBUTE_TYPE.equals(ruleAttribute.getType()); |
870 | 0 | if (!propertiesAsMap) { |
871 | 0 | for (int index = 0; index < definitionVO.getProperties().length; index++) { |
872 | 0 | PropertyDefinitionDTO propertyDefVO = definitionVO.getProperties()[index]; |
873 | 0 | definition.addProperty(new PropertyDefinition(propertyDefVO.getName(), new DataDefinition(propertyDefVO.getValue(), String.class))); |
874 | |
} |
875 | |
} |
876 | |
|
877 | |
|
878 | 0 | if (ruleAttribute.getServiceNamespace() != null) { |
879 | 0 | definition.setServiceNamespace(ruleAttribute.getServiceNamespace()); |
880 | |
} else { |
881 | |
|
882 | 0 | if (documentType != null) { |
883 | 0 | definition.setServiceNamespace(documentType.getServiceNamespace()); |
884 | |
} |
885 | |
} |
886 | |
|
887 | 0 | return new AttributeDefinition(ruleAttribute, definition); |
888 | |
} |
889 | |
|
890 | |
public static DocumentDetailDTO convertDocumentDetail(DocumentRouteHeaderValue routeHeader) throws WorkflowException { |
891 | 0 | if (routeHeader == null) { |
892 | 0 | return null; |
893 | |
} |
894 | 0 | DocumentDetailDTO detail = new DocumentDetailDTO(); |
895 | 0 | populateRouteHeaderVO(detail, routeHeader); |
896 | 0 | Map nodeInstances = new HashMap(); |
897 | 0 | List actionRequestVOs = new ArrayList(); |
898 | 0 | List rootActionRequests = KEWServiceLocator.getActionRequestService().getRootRequests(routeHeader.getActionRequests()); |
899 | 0 | for (Iterator iterator = rootActionRequests.iterator(); iterator.hasNext();) { |
900 | 0 | ActionRequestValue actionRequest = (ActionRequestValue) iterator.next(); |
901 | 0 | actionRequestVOs.add(convertActionRequest(actionRequest)); |
902 | 0 | RouteNodeInstance nodeInstance = actionRequest.getNodeInstance(); |
903 | 0 | if (nodeInstance == null) { |
904 | 0 | continue; |
905 | |
} |
906 | 0 | if (nodeInstance.getRouteNodeInstanceId() == null) { |
907 | 0 | throw new WorkflowException("Error creating document detail structure because of NULL node instance id."); |
908 | |
} |
909 | 0 | nodeInstances.put(nodeInstance.getRouteNodeInstanceId(), nodeInstance); |
910 | 0 | } |
911 | 0 | detail.setActionRequests((ActionRequestDTO[]) actionRequestVOs.toArray(new ActionRequestDTO[0])); |
912 | 0 | List nodeInstanceVOs = new ArrayList(); |
913 | 0 | for (Iterator iterator = nodeInstances.values().iterator(); iterator.hasNext();) { |
914 | 0 | RouteNodeInstance nodeInstance = (RouteNodeInstance) iterator.next(); |
915 | 0 | nodeInstanceVOs.add(convertRouteNodeInstance(nodeInstance)); |
916 | 0 | } |
917 | 0 | detail.setNodeInstances((RouteNodeInstanceDTO[]) nodeInstanceVOs.toArray(new RouteNodeInstanceDTO[0])); |
918 | 0 | List actionTakenVOs = new ArrayList(); |
919 | 0 | for (Iterator iterator = routeHeader.getActionsTaken().iterator(); iterator.hasNext();) { |
920 | 0 | ActionTakenValue actionTaken = (ActionTakenValue) iterator.next(); |
921 | 0 | actionTakenVOs.add(convertActionTaken(actionTaken)); |
922 | 0 | } |
923 | 0 | detail.setActionsTaken((ActionTakenDTO[]) actionTakenVOs.toArray(new ActionTakenDTO[0])); |
924 | 0 | return detail; |
925 | |
} |
926 | |
|
927 | |
public static RouteNodeInstanceDTO convertRouteNodeInstance(RouteNodeInstance nodeInstance) throws WorkflowException { |
928 | 0 | if (nodeInstance == null) { |
929 | 0 | return null; |
930 | |
} |
931 | 0 | RouteNodeInstanceDTO nodeInstanceVO = new RouteNodeInstanceDTO(); |
932 | 0 | nodeInstanceVO.setActive(nodeInstance.isActive()); |
933 | 0 | nodeInstanceVO.setBranchId(nodeInstance.getBranch().getBranchId()); |
934 | 0 | nodeInstanceVO.setComplete(nodeInstance.isComplete()); |
935 | 0 | nodeInstanceVO.setDocumentId(nodeInstance.getDocumentId()); |
936 | 0 | nodeInstanceVO.setInitial(nodeInstance.isInitial()); |
937 | 0 | nodeInstanceVO.setName(nodeInstance.getName()); |
938 | 0 | nodeInstanceVO.setProcessId(nodeInstance.getProcess() != null ? nodeInstance.getProcess().getRouteNodeInstanceId() : null); |
939 | 0 | nodeInstanceVO.setRouteNodeId(nodeInstance.getRouteNode().getRouteNodeId()); |
940 | 0 | nodeInstanceVO.setRouteNodeInstanceId(nodeInstance.getRouteNodeInstanceId()); |
941 | 0 | nodeInstanceVO.setState(convertStates(nodeInstance.getState())); |
942 | |
|
943 | 0 | nodeInstanceVO.setNextNodes(new RouteNodeInstanceDTO[nodeInstance.getNextNodeInstances().size()]); |
944 | 0 | int i = 0; |
945 | 0 | for (Iterator iter = nodeInstance.getNextNodeInstances().iterator(); iter.hasNext(); i++) { |
946 | 0 | RouteNodeInstance nextNodeInstance = (RouteNodeInstance) iter.next(); |
947 | 0 | nodeInstanceVO.getNextNodes()[i] = convertRouteNodeInstance(nextNodeInstance); |
948 | |
} |
949 | |
|
950 | 0 | return nodeInstanceVO; |
951 | |
} |
952 | |
|
953 | |
public static StateDTO[] convertStates(Collection states) { |
954 | 0 | if (states == null) { |
955 | 0 | return null; |
956 | |
} |
957 | 0 | StateDTO[] stateVOs = new StateDTO[states.size()]; |
958 | 0 | int index = 0; |
959 | 0 | for (Iterator iterator = states.iterator(); iterator.hasNext();) { |
960 | 0 | State state = (State) iterator.next(); |
961 | 0 | stateVOs[index++] = convertState(state); |
962 | 0 | } |
963 | 0 | return stateVOs; |
964 | |
} |
965 | |
|
966 | |
public static StateDTO convertState(State nodeState) { |
967 | 0 | if (nodeState == null) { |
968 | 0 | return null; |
969 | |
} |
970 | 0 | StateDTO stateVO = new StateDTO(); |
971 | 0 | stateVO.setStateId(nodeState.getStateId()); |
972 | 0 | stateVO.setKey(nodeState.getKey()); |
973 | 0 | stateVO.setValue(nodeState.getValue()); |
974 | 0 | return stateVO; |
975 | |
} |
976 | |
|
977 | |
public static RouteNodeDTO convertRouteNode(RouteNode node) { |
978 | 0 | if (node == null) { |
979 | 0 | return null; |
980 | |
} |
981 | 0 | RouteNodeDTO nodeVO = new RouteNodeDTO(); |
982 | 0 | nodeVO.setActivationType(node.getActivationType()); |
983 | 0 | nodeVO.setBranchName(node.getBranch() != null ? node.getBranch().getName() : null); |
984 | 0 | nodeVO.setDocumentTypeId(node.getDocumentTypeId()); |
985 | 0 | nodeVO.setExceptionGroupId(node.getExceptionWorkgroupId()); |
986 | 0 | nodeVO.setFinalApprovalInd(node.getFinalApprovalInd().booleanValue()); |
987 | 0 | nodeVO.setMandatoryRouteInd(node.getMandatoryRouteInd().booleanValue()); |
988 | 0 | nodeVO.setNodeType(node.getNodeType()); |
989 | 0 | nodeVO.setRouteMethodCode(node.getRouteMethodCode()); |
990 | 0 | nodeVO.setRouteMethodName(node.getRouteMethodName()); |
991 | 0 | nodeVO.setRouteNodeId(node.getRouteNodeId()); |
992 | 0 | nodeVO.setRouteNodeName(node.getRouteNodeName()); |
993 | 0 | int index = 0; |
994 | 0 | Long[] previousNodeIds = new Long[node.getPreviousNodes().size()]; |
995 | 0 | for (Iterator iterator = node.getPreviousNodes().iterator(); iterator.hasNext();) { |
996 | 0 | RouteNode prevNode = (RouteNode) iterator.next(); |
997 | 0 | previousNodeIds[index++] = prevNode.getRouteNodeId(); |
998 | 0 | } |
999 | 0 | nodeVO.setPreviousNodeIds(previousNodeIds); |
1000 | 0 | index = 0; |
1001 | 0 | Long[] nextNodeIds = new Long[node.getNextNodes().size()]; |
1002 | 0 | for (Iterator iterator = node.getNextNodes().iterator(); iterator.hasNext();) { |
1003 | 0 | RouteNode nextNode = (RouteNode) iterator.next(); |
1004 | 0 | nextNodeIds[index++] = nextNode.getRouteNodeId(); |
1005 | 0 | } |
1006 | 0 | nodeVO.setNextNodeIds(nextNodeIds); |
1007 | 0 | return nodeVO; |
1008 | |
} |
1009 | |
|
1010 | |
public static ProcessDTO convertProcess(Process process) { |
1011 | 0 | ProcessDTO processVO = new ProcessDTO(); |
1012 | 0 | processVO.setInitial(process.isInitial()); |
1013 | 0 | processVO.setInitialRouteNode(convertRouteNode(process.getInitialRouteNode())); |
1014 | 0 | processVO.setName(process.getName()); |
1015 | 0 | processVO.setProcessId(process.getProcessId()); |
1016 | 0 | return processVO; |
1017 | |
} |
1018 | |
|
1019 | |
public static MovePoint convertMovePointVO(MovePointDTO movePointVO) { |
1020 | 0 | MovePoint movePoint = new MovePoint(); |
1021 | 0 | movePoint.setStartNodeName(movePointVO.getStartNodeName()); |
1022 | 0 | movePoint.setStepsToMove(movePointVO.getStepsToMove()); |
1023 | 0 | return movePoint; |
1024 | |
} |
1025 | |
|
1026 | |
public static AdHocRevoke convertAdHocRevokeVO(AdHocRevokeDTO revokeVO) throws WorkflowException { |
1027 | 0 | AdHocRevoke revoke = new AdHocRevoke(); |
1028 | 0 | revoke.setActionRequestId(revokeVO.getActionRequestId()); |
1029 | 0 | revoke.setNodeName(revokeVO.getNodeName()); |
1030 | 0 | revoke.setPrincipalId(revokeVO.getPrincipalId()); |
1031 | 0 | revoke.setGroupId(revokeVO.getGroupId()); |
1032 | 0 | return revoke; |
1033 | |
} |
1034 | |
|
1035 | |
public static WorkflowAttributeValidationErrorDTO convertWorkflowAttributeValidationError(WorkflowAttributeValidationError error) { |
1036 | 0 | return new WorkflowAttributeValidationErrorDTO(error.getKey(), error.getMessage()); |
1037 | |
} |
1038 | |
|
1039 | |
|
1040 | |
public static void updateNotes(RouteHeaderDTO routeHeaderVO, Long routeHeaderId) { |
1041 | 0 | NoteDTO[] notes = routeHeaderVO.getNotes(); |
1042 | 0 | NoteDTO[] notesToDelete = routeHeaderVO.getNotesToDelete(); |
1043 | 0 | Note noteToDelete = null; |
1044 | 0 | Note noteToSave = null; |
1045 | |
|
1046 | |
|
1047 | 0 | if (notes != null) { |
1048 | 0 | for (int i = 0; i < notes.length; i++) { |
1049 | 0 | if (notes[i] != null) { |
1050 | 0 | noteToSave = new Note(); |
1051 | 0 | noteToSave.setNoteId(notes[i].getNoteId()); |
1052 | 0 | noteToSave.setRouteHeaderId(routeHeaderId); |
1053 | 0 | noteToSave.setNoteAuthorWorkflowId(notes[i].getNoteAuthorWorkflowId()); |
1054 | 0 | noteToSave.setNoteCreateDate(Utilities.convertCalendar(notes[i].getNoteCreateDate())); |
1055 | 0 | noteToSave.setNoteText(notes[i].getNoteText()); |
1056 | 0 | noteToSave.setLockVerNbr(notes[i].getLockVerNbr()); |
1057 | |
|
1058 | 0 | getNoteService().saveNote(noteToSave); |
1059 | |
} |
1060 | |
} |
1061 | |
|
1062 | |
} |
1063 | |
|
1064 | |
|
1065 | 0 | if (notesToDelete != null) { |
1066 | 0 | for (int i = 0; i < notesToDelete.length; i++) { |
1067 | 0 | noteToDelete = getNoteService().getNoteByNoteId(notesToDelete[i].getNoteId()); |
1068 | 0 | if (noteToDelete != null) { |
1069 | 0 | getNoteService().deleteNote(noteToDelete); |
1070 | |
} |
1071 | |
} |
1072 | 0 | routeHeaderVO.setNotesToDelete(null); |
1073 | |
} |
1074 | 0 | } |
1075 | |
|
1076 | |
private static NoteService getNoteService() { |
1077 | 0 | return (NoteService) KEWServiceLocator.getService(KEWServiceLocator.NOTE_SERVICE); |
1078 | |
} |
1079 | |
|
1080 | |
private static NoteDTO[] convertNotesArrayListToNoteVOArray(List notesArrayList) { |
1081 | 0 | if (notesArrayList.size() > 0) { |
1082 | 0 | NoteDTO[] noteVOArray = new NoteDTO[notesArrayList.size()]; |
1083 | 0 | int i = 0; |
1084 | |
Note tempNote; |
1085 | |
NoteDTO tempNoteVO; |
1086 | 0 | for (Iterator it = notesArrayList.iterator(); it.hasNext();) { |
1087 | 0 | tempNote = (Note) it.next(); |
1088 | 0 | tempNoteVO = new NoteDTO(); |
1089 | 0 | tempNoteVO.setNoteId(tempNote.getNoteId()); |
1090 | 0 | tempNoteVO.setRouteHeaderId(tempNote.getRouteHeaderId()); |
1091 | 0 | tempNoteVO.setNoteAuthorWorkflowId(tempNote.getNoteAuthorWorkflowId()); |
1092 | 0 | tempNoteVO.setNoteCreateDate(Utilities.convertTimestamp(tempNote.getNoteCreateDate())); |
1093 | 0 | tempNoteVO.setNoteText(tempNote.getNoteText()); |
1094 | 0 | tempNoteVO.setLockVerNbr(tempNote.getLockVerNbr()); |
1095 | 0 | noteVOArray[i] = tempNoteVO; |
1096 | 0 | i++; |
1097 | |
} |
1098 | 0 | return noteVOArray; |
1099 | |
} else { |
1100 | 0 | return null; |
1101 | |
} |
1102 | |
} |
1103 | |
|
1104 | |
public static SimulationCriteria convertReportCriteriaDTO(ReportCriteriaDTO criteriaVO) { |
1105 | 0 | if (criteriaVO == null) { |
1106 | 0 | return null; |
1107 | |
} |
1108 | 0 | SimulationCriteria criteria = new SimulationCriteria(); |
1109 | 0 | criteria.setDestinationNodeName(criteriaVO.getTargetNodeName()); |
1110 | 0 | criteria.setDocumentId(criteriaVO.getRouteHeaderId()); |
1111 | 0 | criteria.setDocumentTypeName(criteriaVO.getDocumentTypeName()); |
1112 | 0 | criteria.setXmlContent(criteriaVO.getXmlContent()); |
1113 | 0 | criteria.setActivateRequests(criteriaVO.getActivateRequests()); |
1114 | 0 | criteria.setFlattenNodes(criteriaVO.isFlattenNodes()); |
1115 | 0 | if (criteriaVO.getRoutingPrincipalId() != null) { |
1116 | 0 | KimPrincipal kPrinc = KEWServiceLocator.getIdentityHelperService().getPrincipal(criteriaVO.getRoutingPrincipalId()); |
1117 | 0 | Person user = KIMServiceLocator.getPersonService().getPerson(kPrinc.getPrincipalId()); |
1118 | 0 | if (user == null) { |
1119 | 0 | throw new RiceRuntimeException("Could not locate user for the given id: " + criteriaVO.getRoutingPrincipalId()); |
1120 | |
} |
1121 | 0 | criteria.setRoutingUser(user); |
1122 | |
} |
1123 | 0 | if (criteriaVO.getRuleTemplateNames() != null) { |
1124 | 0 | for (int index = 0; index < criteriaVO.getRuleTemplateNames().length; index++) { |
1125 | 0 | String ruleTemplateName = criteriaVO.getRuleTemplateNames()[index]; |
1126 | 0 | criteria.getRuleTemplateNames().add(ruleTemplateName); |
1127 | |
} |
1128 | |
} |
1129 | 0 | if (criteriaVO.getNodeNames() != null) { |
1130 | 0 | for (int i = 0; i < criteriaVO.getNodeNames().length; i++) { |
1131 | 0 | String nodeName = criteriaVO.getNodeNames()[i]; |
1132 | 0 | criteria.getNodeNames().add(nodeName); |
1133 | |
} |
1134 | |
} |
1135 | 0 | if (criteriaVO.getTargetPrincipalIds() != null) { |
1136 | 0 | for (String targetPrincipalId : criteriaVO.getTargetPrincipalIds()) { |
1137 | 0 | KimPrincipal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(targetPrincipalId); |
1138 | 0 | criteria.getDestinationRecipients().add(new KimPrincipalRecipient(principal)); |
1139 | |
} |
1140 | |
} |
1141 | 0 | if (criteriaVO.getActionsToTake() != null) { |
1142 | 0 | for (int index = 0; index < criteriaVO.getActionsToTake().length; index++) { |
1143 | 0 | ReportActionToTakeDTO actionToTakeVO = criteriaVO.getActionsToTake()[index]; |
1144 | 0 | criteria.getActionsToTake().add(convertReportActionToTakeVO(actionToTakeVO)); |
1145 | |
} |
1146 | |
} |
1147 | 0 | return criteria; |
1148 | |
} |
1149 | |
|
1150 | |
public static SimulationActionToTake convertReportActionToTakeVO(ReportActionToTakeDTO actionToTakeVO) { |
1151 | 0 | if (actionToTakeVO == null) { |
1152 | 0 | return null; |
1153 | |
} |
1154 | 0 | SimulationActionToTake actionToTake = new SimulationActionToTake(); |
1155 | 0 | actionToTake.setNodeName(actionToTakeVO.getNodeName()); |
1156 | 0 | if (StringUtils.isBlank(actionToTakeVO.getActionToPerform())) { |
1157 | 0 | throw new IllegalArgumentException("ReportActionToTakeVO must contain an action taken code and does not"); |
1158 | |
} |
1159 | 0 | actionToTake.setActionToPerform(actionToTakeVO.getActionToPerform()); |
1160 | 0 | if (actionToTakeVO.getPrincipalId() == null) { |
1161 | 0 | throw new IllegalArgumentException("ReportActionToTakeVO must contain a principalId and does not"); |
1162 | |
} |
1163 | 0 | KimPrincipal kPrinc = KEWServiceLocator.getIdentityHelperService().getPrincipal(actionToTakeVO.getPrincipalId()); |
1164 | 0 | Person user = KIMServiceLocator.getPersonService().getPerson(kPrinc.getPrincipalId()); |
1165 | 0 | if (user == null) { |
1166 | 0 | throw new RiceRuntimeException("Could not locate Person for the given id: " + actionToTakeVO.getPrincipalId()); |
1167 | |
} |
1168 | 0 | actionToTake.setUser(user); |
1169 | 0 | return actionToTake; |
1170 | |
} |
1171 | |
|
1172 | |
public static RuleDelegationDTO convertRuleDelegation(RuleDelegation ruleDelegation) throws WorkflowException { |
1173 | 0 | if (ruleDelegation == null) { |
1174 | 0 | return null; |
1175 | |
} |
1176 | 0 | RuleDelegationDTO ruleDelegationVO = new RuleDelegationDTO(); |
1177 | 0 | ruleDelegationVO.setDelegationType(ruleDelegation.getDelegationType()); |
1178 | 0 | ruleDelegationVO.setDelegationRule(convertRule(ruleDelegation.getDelegationRuleBaseValues())); |
1179 | 0 | return ruleDelegationVO; |
1180 | |
} |
1181 | |
|
1182 | |
|
1183 | |
|
1184 | |
public static Collection<RuleExtensionDTO> convertRuleExtension(RuleExtension ruleExtension) throws WorkflowException { |
1185 | 0 | if (ruleExtension == null) { |
1186 | 0 | return null; |
1187 | |
} |
1188 | 0 | List<RuleExtensionDTO> extensionVOs = new ArrayList<RuleExtensionDTO>(); |
1189 | 0 | for (Iterator iter = ruleExtension.getExtensionValues().iterator(); iter.hasNext();) { |
1190 | 0 | RuleExtensionValue extensionValue = (RuleExtensionValue) iter.next(); |
1191 | 0 | extensionVOs.add(new RuleExtensionDTO(extensionValue.getKey(), extensionValue.getValue())); |
1192 | 0 | } |
1193 | 0 | return extensionVOs; |
1194 | |
} |
1195 | |
|
1196 | |
public static KeyValuePair convertRuleExtensionVO(RuleExtensionDTO ruleExtensionVO) throws WorkflowException { |
1197 | 0 | if (ruleExtensionVO == null) { |
1198 | 0 | return null; |
1199 | |
} |
1200 | 0 | return new KeyValuePair(ruleExtensionVO.getKey(), ruleExtensionVO.getValue()); |
1201 | |
} |
1202 | |
|
1203 | |
public static RuleResponsibilityDTO convertRuleResponsibility(RuleResponsibility ruleResponsibility) throws WorkflowException { |
1204 | 0 | if (ruleResponsibility == null) { |
1205 | 0 | return null; |
1206 | |
} |
1207 | 0 | RuleResponsibilityDTO ruleResponsibilityVO = new RuleResponsibilityDTO(); |
1208 | 0 | ruleResponsibilityVO.setActionRequestedCd(ruleResponsibility.getActionRequestedCd()); |
1209 | 0 | ruleResponsibilityVO.setApprovePolicy(ruleResponsibility.getApprovePolicy()); |
1210 | 0 | ruleResponsibilityVO.setPriority(ruleResponsibility.getPriority()); |
1211 | 0 | ruleResponsibilityVO.setResponsibilityId(ruleResponsibility.getResponsibilityId()); |
1212 | 0 | ruleResponsibilityVO.setRoleName(ruleResponsibility.getRole()); |
1213 | 0 | if (ruleResponsibility.getPrincipal() != null) { |
1214 | 0 | ruleResponsibilityVO.setPrincipalId(ruleResponsibility.getPrincipal().getPrincipalId()); |
1215 | 0 | } else if (ruleResponsibility.getGroup() != null) { |
1216 | 0 | ruleResponsibilityVO.setGroupId(ruleResponsibility.getGroup().getGroupId()); |
1217 | 0 | } else if (ruleResponsibility.getRole() != null) { |
1218 | 0 | ruleResponsibilityVO.setRoleName(ruleResponsibility.getRole()); |
1219 | |
} |
1220 | 0 | for (Iterator iter = ruleResponsibility.getDelegationRules().iterator(); iter.hasNext();) { |
1221 | 0 | RuleDelegation ruleDelegation = (RuleDelegation) iter.next(); |
1222 | 0 | ruleResponsibilityVO.addDelegationRule(convertRuleDelegation(ruleDelegation)); |
1223 | 0 | } |
1224 | 0 | return ruleResponsibilityVO; |
1225 | |
} |
1226 | |
|
1227 | |
|
1228 | |
|
1229 | |
|
1230 | |
public static RuleDTO convertRule(RuleBaseValues ruleValues) throws WorkflowException { |
1231 | 0 | if (ruleValues == null) { |
1232 | 0 | return null; |
1233 | |
} |
1234 | 0 | RuleDTO rule = new RuleDTO(); |
1235 | 0 | rule.setActiveInd(ruleValues.getActiveInd()); |
1236 | 0 | rule.setDescription(ruleValues.getDescription()); |
1237 | 0 | rule.setDocTypeName(ruleValues.getDocTypeName()); |
1238 | 0 | rule.setFromDate(ruleValues.getFromDateString()); |
1239 | 0 | rule.setToDate(ruleValues.getToDateString()); |
1240 | 0 | rule.setForceAction(ruleValues.getForceAction()); |
1241 | 0 | rule.setRuleTemplateId(ruleValues.getRuleTemplateId()); |
1242 | 0 | rule.setRuleTemplateName(ruleValues.getRuleTemplateName()); |
1243 | |
|
1244 | |
|
1245 | 0 | for (Iterator iter = ruleValues.getRuleExtensions().iterator(); iter.hasNext();) { |
1246 | 0 | RuleExtension ruleExtension = (RuleExtension) iter.next(); |
1247 | 0 | rule.addRuleExtensions(convertRuleExtension(ruleExtension)); |
1248 | 0 | } |
1249 | |
|
1250 | 0 | for (Iterator iter = ruleValues.getResponsibilities().iterator(); iter.hasNext();) { |
1251 | 0 | RuleResponsibility ruleResponsibility = (RuleResponsibility) iter.next(); |
1252 | 0 | rule.addRuleResponsibility(convertRuleResponsibility(ruleResponsibility)); |
1253 | 0 | } |
1254 | 0 | return rule; |
1255 | |
} |
1256 | |
|
1257 | |
public static DocSearchCriteriaDTO convertDocumentSearchCriteriaDTO(DocumentSearchCriteriaDTO criteriaVO) throws WorkflowException { |
1258 | 0 | DocSearchCriteriaDTO criteria = new DocSearchCriteriaDTO(); |
1259 | 0 | criteria.setAppDocId(criteriaVO.getAppDocId()); |
1260 | 0 | criteria.setApprover(criteriaVO.getApprover()); |
1261 | 0 | criteria.setDocRouteStatus(criteriaVO.getDocRouteStatus()); |
1262 | 0 | criteria.setDocTitle(criteriaVO.getDocTitle()); |
1263 | 0 | criteria.setDocTypeFullName(criteriaVO.getDocTypeFullName()); |
1264 | 0 | criteria.setDocVersion(criteriaVO.getDocVersion()); |
1265 | 0 | criteria.setFromDateApproved(criteriaVO.getFromDateApproved()); |
1266 | 0 | criteria.setFromDateCreated(criteriaVO.getFromDateCreated()); |
1267 | 0 | criteria.setFromDateFinalized(criteriaVO.getFromDateFinalized()); |
1268 | 0 | criteria.setFromDateLastModified(criteriaVO.getFromDateLastModified()); |
1269 | 0 | criteria.setInitiator(criteriaVO.getInitiator()); |
1270 | 0 | criteria.setIsAdvancedSearch((criteriaVO.isAdvancedSearch()) ? DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING : "NO"); |
1271 | 0 | criteria.setSuperUserSearch((criteriaVO.isSuperUserSearch()) ? DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING : "NO"); |
1272 | 0 | criteria.setRouteHeaderId(criteriaVO.getRouteHeaderId()); |
1273 | 0 | criteria.setViewer(criteriaVO.getViewer()); |
1274 | 0 | criteria.setWorkgroupViewerName(criteriaVO.getGroupViewerName()); |
1275 | 0 | criteria.setToDateApproved(criteriaVO.getToDateApproved()); |
1276 | 0 | criteria.setToDateCreated(criteriaVO.getToDateCreated()); |
1277 | 0 | criteria.setToDateFinalized(criteriaVO.getToDateFinalized()); |
1278 | 0 | criteria.setToDateLastModified(criteriaVO.getToDateLastModified()); |
1279 | 0 | criteria.setThreshold(criteriaVO.getThreshold()); |
1280 | 0 | criteria.setSaveSearchForUser(criteriaVO.isSaveSearchForUser()); |
1281 | |
|
1282 | |
|
1283 | 0 | if ( (StringUtils.isNotBlank(criteriaVO.getDocRouteNodeName())) && (StringUtils.isBlank(criteriaVO.getDocTypeFullName())) ) { |
1284 | 0 | throw new WorkflowException("No document type name specified when attempting to search by route node name '" + criteriaVO.getDocRouteNodeName() + "'"); |
1285 | 0 | } else if ( (StringUtils.isNotBlank(criteriaVO.getDocRouteNodeName())) && (StringUtils.isNotBlank(criteriaVO.getDocTypeFullName())) ) { |
1286 | 0 | criteria.setDocRouteNodeLogic(criteriaVO.getDocRouteNodeLogic()); |
1287 | 0 | List routeNodes = KEWServiceLocator.getRouteNodeService().getFlattenedNodes(getDocumentTypeByName(criteria.getDocTypeFullName()), true); |
1288 | 0 | boolean foundRouteNode = false; |
1289 | 0 | for (Iterator iterator = routeNodes.iterator(); iterator.hasNext();) { |
1290 | 0 | RouteNode routeNode = (RouteNode) iterator.next(); |
1291 | 0 | if (criteriaVO.getDocRouteNodeName().equals(routeNode.getRouteNodeName())) { |
1292 | 0 | foundRouteNode = true; |
1293 | 0 | break; |
1294 | |
} |
1295 | 0 | } |
1296 | 0 | if (!foundRouteNode) { |
1297 | 0 | throw new WorkflowException("Could not find route node name '" + criteriaVO.getDocRouteNodeName() + "' for document type name '" + criteriaVO.getDocTypeFullName() + "'"); |
1298 | |
} |
1299 | 0 | criteria.setDocRouteNodeId(criteriaVO.getDocRouteNodeName()); |
1300 | |
} |
1301 | |
|
1302 | |
|
1303 | 0 | HashMap<String, List<String>> searchAttributeValues = new HashMap<String,List<String>>(); |
1304 | 0 | for (KeyValueDTO keyValueVO : criteriaVO.getSearchAttributeValues()) { |
1305 | 0 | if (searchAttributeValues.containsKey(keyValueVO.getKey())) { |
1306 | 0 | searchAttributeValues.get(keyValueVO.getKey()).add(keyValueVO.getValue()); |
1307 | |
} else { |
1308 | 0 | searchAttributeValues.put(keyValueVO.getKey(), Arrays.asList(new String[]{keyValueVO.getValue()})); |
1309 | |
} |
1310 | |
} |
1311 | |
|
1312 | 0 | List propertyFields = new ArrayList(); |
1313 | 0 | for (String key : searchAttributeValues.keySet()) { |
1314 | 0 | List<String> values = searchAttributeValues.get(key); |
1315 | 0 | SearchAttributeFormContainer container = null; |
1316 | 0 | if (values.size() == 1) { |
1317 | 0 | container = new SearchAttributeFormContainer(key, values.get(0)); |
1318 | 0 | } else if (values.size() > 1) { |
1319 | 0 | container = new SearchAttributeFormContainer(key, (String[])values.toArray()); |
1320 | |
} |
1321 | 0 | if (container != null) { |
1322 | 0 | propertyFields.add(container); |
1323 | |
} |
1324 | 0 | } |
1325 | 0 | DocSearchUtils.addSearchableAttributesToCriteria(criteria, propertyFields, true); |
1326 | 0 | return criteria; |
1327 | |
} |
1328 | |
|
1329 | |
private static DocumentType getDocumentTypeByName(String documentTypeName) { |
1330 | 0 | return KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName); |
1331 | |
} |
1332 | |
|
1333 | |
public static DocumentSearchResultDTO convertDocumentSearchResultComponents(DocumentSearchResultComponents searchResult) throws WorkflowException { |
1334 | 0 | DocumentSearchResultDTO resultsVO = new DocumentSearchResultDTO(); |
1335 | 0 | resultsVO.setSearchResults(convertDocumentSearchResults(searchResult.getSearchResults())); |
1336 | 0 | return resultsVO; |
1337 | |
} |
1338 | |
|
1339 | |
private static List<DocumentSearchResultRowDTO> convertDocumentSearchResults(List<DocumentSearchResult> searchResults) throws WorkflowException { |
1340 | 0 | List<DocumentSearchResultRowDTO> rowVOs = new ArrayList<DocumentSearchResultRowDTO>(); |
1341 | 0 | for (DocumentSearchResult documentSearchResult : searchResults) { |
1342 | 0 | rowVOs.add(convertDocumentSearchResult(documentSearchResult)); |
1343 | |
} |
1344 | 0 | return rowVOs; |
1345 | |
} |
1346 | |
|
1347 | |
public static DocumentSearchResultRowDTO convertDocumentSearchResult(DocumentSearchResult resultRow) throws WorkflowException { |
1348 | 0 | DocumentSearchResultRowDTO rowVO = new DocumentSearchResultRowDTO(); |
1349 | 0 | List<KeyValueDTO> fieldValues = new ArrayList<KeyValueDTO>(); |
1350 | 0 | for (KeyValueSort keyValueSort : resultRow.getResultContainers()) { |
1351 | 0 | fieldValues.add(new KeyValueDTO(keyValueSort.getKey(),keyValueSort.getValue(),keyValueSort.getUserDisplayValue())); |
1352 | |
} |
1353 | 0 | rowVO.setFieldValues(fieldValues); |
1354 | 0 | return rowVO; |
1355 | |
} |
1356 | |
|
1357 | |
public static DocumentStatusTransitionDTO convertDocumentStatusTransition(DocumentStatusTransition transition) throws WorkflowException { |
1358 | 0 | DocumentStatusTransitionDTO tranVO = new DocumentStatusTransitionDTO(); |
1359 | 0 | tranVO.setStatusTransitionId(transition.getStatusTransitionId()); |
1360 | 0 | tranVO.setRouteHeaderId(transition.getRouteHeaderId()); |
1361 | 0 | tranVO.setOldAppDocStatus(transition.getOldAppDocStatus()); |
1362 | 0 | tranVO.setNewAppDocStatus(transition.getNewAppDocStatus()); |
1363 | 0 | tranVO.setStatusTransitionDate(transition.getStatusTransitionDate()); |
1364 | 0 | return tranVO; |
1365 | |
} |
1366 | |
|
1367 | |
|
1368 | |
|
1369 | |
private static void handleException(String message, Exception e) throws WorkflowException { |
1370 | 0 | if (e instanceof RuntimeException) { |
1371 | 0 | throw (RuntimeException) e; |
1372 | 0 | } else if (e instanceof WorkflowException) { |
1373 | 0 | throw (WorkflowException) e; |
1374 | |
} |
1375 | 0 | throw new WorkflowException(message, e); |
1376 | |
} |
1377 | |
|
1378 | |
|
1379 | |
public static DocumentLinkDTO[] convertDocumentLink(Collection<DocumentLink> links) { |
1380 | 0 | if (links == null) { |
1381 | 0 | return null; |
1382 | |
} |
1383 | 0 | DocumentLinkDTO[] docLinkVOs = new DocumentLinkDTO[links.size()]; |
1384 | |
|
1385 | 0 | int index = 0; |
1386 | |
|
1387 | 0 | for (DocumentLink link: links) { |
1388 | 0 | docLinkVOs[index++] = convertDocumentLink(link); |
1389 | |
} |
1390 | 0 | return docLinkVOs; |
1391 | |
} |
1392 | |
|
1393 | |
|
1394 | |
public static List<DocumentLinkDTO> convertDocumentLinkToArrayList(Collection<DocumentLink> links) { |
1395 | 0 | if (links == null) { |
1396 | 0 | return null; |
1397 | |
} |
1398 | 0 | List<DocumentLinkDTO> docLinkVOs = new ArrayList<DocumentLinkDTO>(links.size()); |
1399 | |
|
1400 | 0 | for (DocumentLink link: links) { |
1401 | 0 | docLinkVOs.add(convertDocumentLink(link)); |
1402 | |
} |
1403 | 0 | return docLinkVOs; |
1404 | |
} |
1405 | |
|
1406 | |
|
1407 | |
public static DocumentLinkDTO convertDocumentLink(DocumentLink link) { |
1408 | 0 | if (link == null) { |
1409 | 0 | return null; |
1410 | |
} |
1411 | 0 | DocumentLinkDTO linkVO = new DocumentLinkDTO(); |
1412 | 0 | linkVO.setLinbkId(link.getDocLinkId()); |
1413 | 0 | linkVO.setOrgnDocId(link.getOrgnDocId()); |
1414 | 0 | linkVO.setDestDocId(link.getDestDocId()); |
1415 | |
|
1416 | 0 | return linkVO; |
1417 | |
} |
1418 | |
|
1419 | |
} |