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