/** * Start a new workflow instance for the given workflow name. * * @param requestMessage the workflow init message * @return the transition context * @throws TransitioningException when the workflow cannot be started */ protected TransitionContext startWorkflow(InitWorkflowRq requestMessage) throws TransitioningException { if (requestMessage == null) { throw new IllegalArgumentException("Cannot start workflow for request [null]."); } Name name = requestMessage.getWorkflowName(); Description summary = requestMessage.getSummary(); if (name == null || name.getValue() == null || name.getValue().isEmpty()) { throw new IllegalArgumentException("Cannot start workflow with name [null]."); } if (summary == null || summary.getValue() == null || summary.getValue().isEmpty()) { requestMessage.setSummary(new Description("Workflow '" + name + "'")); } try { WorkflowServiceLocator locator = new WorkflowServiceLocator(); WorkflowService service = locator.getService(null); ServiceRequest<InitWorkflowRq> rq = new ServiceRequest<InitWorkflowRq>(super.getContext()); rq.setRequestMessage(requestMessage); ServiceResponse<WorkflowResultRs> rs = service.initWorkflow(rq); if (rs == null || rs.getResponseMessage() == null) { throw new TransitioningException("Starting workflow did not finish successful."); } WorkflowResultRs responseMessage = rs.getResponseMessage(); TransitionContext transitionContext = new TransitionContext(); transitionContext.setInstance(responseMessage.getInstance()); transitionContext.setInstanceId(responseMessage.getInstanceId()); transitionContext.setName(responseMessage.getWorkflowName()); transitionContext.setWorkflowContext(responseMessage.getContext()); transitionContext.getNextTransitions().addAll(responseMessage.getNextTransitions()); return transitionContext; } catch (WorkflowException we) { throw new TransitioningException("Error starting workflow with name " + name + ".", we); } catch (Exception e) { throw new TransitioningException( "Unexpected error starting workflow with name " + name + ".", e); } }