@Test public void shouldAcceptAndUpdateProcessId() { final DeployedWorkflow workflow = deployNewWorkflow(); final TypedRecord<WorkflowInstanceCreationRecord> command = newCommand(WorkflowInstanceCreationRecord.class); command.getValue().setWorkflowKey(workflow.getKey()); processor.onCommand(command, controller, streamWriter); final WorkflowInstanceCreationRecord acceptedRecord = getAcceptedRecord(WorkflowInstanceCreationIntent.CREATED); assertThat(acceptedRecord.getBpmnProcessIdBuffer()).isEqualTo(workflow.getBpmnProcessId()); }
@Override public boolean onCommand( final TypedRecord<WorkflowInstanceCreationRecord> command, final CommandControl<WorkflowInstanceCreationRecord> controller, final TypedStreamWriter streamWriter) { final WorkflowInstanceCreationRecord record = command.getValue(); final DeployedWorkflow workflow = getWorkflow(record, controller); if (workflow == null || !isValidWorkflow(controller, workflow)) { return true; } final long workflowInstanceKey = keyGenerator.nextKey(); if (!setVariablesFromDocument(controller, record, workflow.getKey(), workflowInstanceKey)) { return true; } final ElementInstance workflowInstance = createElementInstance(workflow, workflowInstanceKey); streamWriter.appendFollowUpEvent( workflowInstanceKey, WorkflowInstanceIntent.ELEMENT_ACTIVATING, workflowInstance.getValue()); record .setWorkflowInstanceKey(workflowInstanceKey) .setBpmnProcessId(workflow.getBpmnProcessId()) .setVersion(workflow.getVersion()) .setWorkflowKey(workflow.getKey()); controller.accept(WorkflowInstanceCreationIntent.CREATED, record); return true; }
CreateWorkflowInstanceProcessor implements CommandProcessor<WorkflowInstanceCreationRecord> { @Override public boolean onCommand( final TypedRecord<WorkflowInstanceCreationRecord> command, final CommandControl<WorkflowInstanceCreationRecord> controller, final TypedStreamWriter streamWriter) { final WorkflowInstanceCreationRecord record = command.getValue(); final DeployedWorkflow workflow = getWorkflow(record, controller); if (workflow == null || !isValidWorkflow(controller, workflow)) { return true; } final long workflowInstanceKey = keyGenerator.nextKey(); if (!setVariablesFromDocument(controller, record, workflow.getKey(), workflowInstanceKey)) { return true; } final ElementInstance workflowInstance = createElementInstance(workflow, workflowInstanceKey); streamWriter.appendFollowUpEvent( workflowInstanceKey, WorkflowInstanceIntent.ELEMENT_ACTIVATING, workflowInstance.getValue()); record .setWorkflowInstanceKey(workflowInstanceKey) .setBpmnProcessId(workflow.getBpmnProcessId()) .setVersion(workflow.getVersion()) .setWorkflowKey(workflow.getKey()); controller.accept(WorkflowInstanceCreationIntent.CREATED, record); return true; } }
CreateWorkflowInstanceProcessor implements CommandProcessor<WorkflowInstanceCreationRecord> { @Override public boolean onCommand( final TypedRecord<WorkflowInstanceCreationRecord> command, final CommandControl<WorkflowInstanceCreationRecord> controller, final TypedStreamWriter streamWriter) { final WorkflowInstanceCreationRecord record = command.getValue(); final DeployedWorkflow workflow = getWorkflow(record, controller); if (workflow == null || !isValidWorkflow(controller, workflow)) { return true; } final long workflowInstanceKey = keyGenerator.nextKey(); if (!setVariablesFromDocument(controller, record, workflow.getKey(), workflowInstanceKey)) { return true; } final ElementInstance workflowInstance = createElementInstance(workflow, workflowInstanceKey); streamWriter.appendFollowUpEvent( workflowInstanceKey, WorkflowInstanceIntent.ELEMENT_ACTIVATING, workflowInstance.getValue()); record .setWorkflowInstanceKey(workflowInstanceKey) .setBpmnProcessId(workflow.getBpmnProcessId()) .setVersion(workflow.getVersion()) .setWorkflowKey(workflow.getKey()); controller.accept(WorkflowInstanceCreationIntent.CREATED, record); return true; } CreateWorkflowInstanceProcessor(
      final WorkflowState workflowState,
      final ElementInstanceState elementInstanceState,
      final VariablesState variablesState,
      final KeyGenerator keyGenerator); }
CreateWorkflowInstanceProcessor implements CommandProcessor<WorkflowInstanceCreationRecord> { @Override public boolean onCommand( final TypedRecord<WorkflowInstanceCreationRecord> command, final CommandControl<WorkflowInstanceCreationRecord> controller, final TypedStreamWriter streamWriter) { final WorkflowInstanceCreationRecord record = command.getValue(); final DeployedWorkflow workflow = getWorkflow(record, controller); if (workflow == null || !isValidWorkflow(controller, workflow)) { return true; } final long workflowInstanceKey = keyGenerator.nextKey(); if (!setVariablesFromDocument(controller, record, workflow.getKey(), workflowInstanceKey)) { return true; } final ElementInstance workflowInstance = createElementInstance(workflow, workflowInstanceKey); streamWriter.appendFollowUpEvent( workflowInstanceKey, WorkflowInstanceIntent.ELEMENT_ACTIVATING, workflowInstance.getValue()); record .setWorkflowInstanceKey(workflowInstanceKey) .setBpmnProcessId(workflow.getBpmnProcessId()) .setVersion(workflow.getVersion()) .setWorkflowKey(workflow.getKey()); controller.accept(WorkflowInstanceCreationIntent.CREATED, record); return true; } CreateWorkflowInstanceProcessor(
      final WorkflowState workflowState,
      final ElementInstanceState elementInstanceState,
      final VariablesState variablesState,
      final KeyGenerator keyGenerator); @Override boolean onCommand(
      final TypedRecord<WorkflowInstanceCreationRecord> command,
      final CommandControl<WorkflowInstanceCreationRecord> controller,
      final TypedStreamWriter streamWriter); }
CreateWorkflowInstanceProcessor implements CommandProcessor<WorkflowInstanceCreationRecord> { @Override public boolean onCommand( final TypedRecord<WorkflowInstanceCreationRecord> command, final CommandControl<WorkflowInstanceCreationRecord> controller, final TypedStreamWriter streamWriter) { final WorkflowInstanceCreationRecord record = command.getValue(); final DeployedWorkflow workflow = getWorkflow(record, controller); if (workflow == null || !isValidWorkflow(controller, workflow)) { return true; } final long workflowInstanceKey = keyGenerator.nextKey(); if (!setVariablesFromDocument(controller, record, workflow.getKey(), workflowInstanceKey)) { return true; } final ElementInstance workflowInstance = createElementInstance(workflow, workflowInstanceKey); streamWriter.appendFollowUpEvent( workflowInstanceKey, WorkflowInstanceIntent.ELEMENT_ACTIVATING, workflowInstance.getValue()); record .setWorkflowInstanceKey(workflowInstanceKey) .setBpmnProcessId(workflow.getBpmnProcessId()) .setVersion(workflow.getVersion()) .setWorkflowKey(workflow.getKey()); controller.accept(WorkflowInstanceCreationIntent.CREATED, record); return true; } CreateWorkflowInstanceProcessor(
      final WorkflowState workflowState,
      final ElementInstanceState elementInstanceState,
      final VariablesState variablesState,
      final KeyGenerator keyGenerator); @Override boolean onCommand(
      final TypedRecord<WorkflowInstanceCreationRecord> command,
      final CommandControl<WorkflowInstanceCreationRecord> controller,
      final TypedStreamWriter streamWriter);  }