@Test public void updateWorkflowInstanceCreatesActionWhenStateVariablesAreModified() { WorkflowInstance instance = updateInstanceBuilder().putStateVariable("foo", "bar").build(); WorkflowInstanceAction action = constructActionBuilder(instance.id).build(); dao.updateWorkflowInstanceAfterExecution(instance, action, noChildWorkflows, emptyWorkflows, false); assertThat(updatedInstance().actions.size(), is(1)); }
@SuppressWarnings("null") public void updateWorkflowInstanceAfterExecution(WorkflowInstance instance, WorkflowInstanceAction action, List<WorkflowInstance> childWorkflows, List<WorkflowInstance> workflows, boolean createAction) { Assert.isTrue(action != null, "action can not be null"); Assert.isTrue(childWorkflows != null, "childWorkflows can not be null"); Assert.isTrue(workflows != null, "workflows can not be null"); Map<String, String> changedStateVariables = instance.getChangedStateVariables(); if (!createAction && (!childWorkflows.isEmpty() || !workflows.isEmpty() || !changedStateVariables.isEmpty())) { logger.info("Forcing action creation because new workflow instances are created or state variables are changed."); createAction = true; } if (createAction) { if (sqlVariants.hasUpdateableCTE() && childWorkflows.isEmpty() && workflows.isEmpty()) { updateWorkflowInstanceWithCTE(instance, action, changedStateVariables); } else { updateWorkflowInstanceWithTransaction(instance, action, childWorkflows, workflows, changedStateVariables); } } else { updateWorkflowInstance(instance); } }
WorkflowInstanceDao { @SuppressWarnings("null") public void updateWorkflowInstanceAfterExecution(WorkflowInstance instance, WorkflowInstanceAction action, List<WorkflowInstance> childWorkflows, List<WorkflowInstance> workflows, boolean createAction) { Assert.isTrue(action != null, "action can not be null"); Assert.isTrue(childWorkflows != null, "childWorkflows can not be null"); Assert.isTrue(workflows != null, "workflows can not be null"); Map<String, String> changedStateVariables = instance.getChangedStateVariables(); if (!createAction && (!childWorkflows.isEmpty() || !workflows.isEmpty() || !changedStateVariables.isEmpty())) { logger.info("Forcing action creation because new workflow instances are created or state variables are changed."); createAction = true; } if (createAction) { if (sqlVariants.hasUpdateableCTE() && childWorkflows.isEmpty() && workflows.isEmpty()) { updateWorkflowInstanceWithCTE(instance, action, changedStateVariables); } else { updateWorkflowInstanceWithTransaction(instance, action, childWorkflows, workflows, changedStateVariables); } } else { updateWorkflowInstance(instance); } } }
WorkflowInstanceDao { @SuppressWarnings("null") public void updateWorkflowInstanceAfterExecution(WorkflowInstance instance, WorkflowInstanceAction action, List<WorkflowInstance> childWorkflows, List<WorkflowInstance> workflows, boolean createAction) { Assert.isTrue(action != null, "action can not be null"); Assert.isTrue(childWorkflows != null, "childWorkflows can not be null"); Assert.isTrue(workflows != null, "workflows can not be null"); Map<String, String> changedStateVariables = instance.getChangedStateVariables(); if (!createAction && (!childWorkflows.isEmpty() || !workflows.isEmpty() || !changedStateVariables.isEmpty())) { logger.info("Forcing action creation because new workflow instances are created or state variables are changed."); createAction = true; } if (createAction) { if (sqlVariants.hasUpdateableCTE() && childWorkflows.isEmpty() && workflows.isEmpty()) { updateWorkflowInstanceWithCTE(instance, action, changedStateVariables); } else { updateWorkflowInstanceWithTransaction(instance, action, childWorkflows, workflows, changedStateVariables); } } else { updateWorkflowInstance(instance); } } @Inject  WorkflowInstanceDao(SQLVariants sqlVariants, @NFlow JdbcTemplate nflowJdbcTemplate,
      @NFlow TransactionTemplate transactionTemplate, @NFlow NamedParameterJdbcTemplate nflowNamedParameterJdbcTemplate,
      ExecutorDao executorDao, WorkflowInstanceExecutor workflowInstanceExecutor, WorkflowInstanceFactory workflowInstanceFactory,
      Environment env); }
WorkflowInstanceDao { @SuppressWarnings("null") public void updateWorkflowInstanceAfterExecution(WorkflowInstance instance, WorkflowInstanceAction action, List<WorkflowInstance> childWorkflows, List<WorkflowInstance> workflows, boolean createAction) { Assert.isTrue(action != null, "action can not be null"); Assert.isTrue(childWorkflows != null, "childWorkflows can not be null"); Assert.isTrue(workflows != null, "workflows can not be null"); Map<String, String> changedStateVariables = instance.getChangedStateVariables(); if (!createAction && (!childWorkflows.isEmpty() || !workflows.isEmpty() || !changedStateVariables.isEmpty())) { logger.info("Forcing action creation because new workflow instances are created or state variables are changed."); createAction = true; } if (createAction) { if (sqlVariants.hasUpdateableCTE() && childWorkflows.isEmpty() && workflows.isEmpty()) { updateWorkflowInstanceWithCTE(instance, action, changedStateVariables); } else { updateWorkflowInstanceWithTransaction(instance, action, childWorkflows, workflows, changedStateVariables); } } else { updateWorkflowInstance(instance); } } @Inject  WorkflowInstanceDao(SQLVariants sqlVariants, @NFlow JdbcTemplate nflowJdbcTemplate,
      @NFlow TransactionTemplate transactionTemplate, @NFlow NamedParameterJdbcTemplate nflowNamedParameterJdbcTemplate,
      ExecutorDao executorDao, WorkflowInstanceExecutor workflowInstanceExecutor, WorkflowInstanceFactory workflowInstanceFactory,
      Environment env); long insertWorkflowInstance(WorkflowInstance instance); @SuppressWarnings("null") void updateWorkflowInstanceAfterExecution(WorkflowInstance instance, WorkflowInstanceAction action,
      List<WorkflowInstance> childWorkflows, List<WorkflowInstance> workflows, boolean createAction); int updateWorkflowInstance(WorkflowInstance instance); void recoverWorkflowInstancesFromDeadNodes(); void checkStateVariableValueLength(String name, String value); boolean updateNotRunningWorkflowInstance(WorkflowInstance instance); boolean wakeUpWorkflowExternally(long workflowInstanceId, List<String> expectedStates); boolean wakeupWorkflowInstanceIfNotExecuting(long workflowInstanceId, List<String> expectedStates); WorkflowInstance getWorkflowInstance(long id, Set<WorkflowInstanceInclude> includes, Long maxActions); List<Long> pollNextWorkflowInstanceIds(final int batchSize); List<WorkflowInstance> queryWorkflowInstances(QueryWorkflowInstances query); Stream<WorkflowInstance> queryWorkflowInstancesAsStream(QueryWorkflowInstances query); @Transactional(propagation = MANDATORY) long insertWorkflowInstanceAction(final WorkflowInstance instance, final WorkflowInstanceAction action); long insertWorkflowInstanceAction(final WorkflowInstanceAction action); String getWorkflowInstanceState(long workflowInstanceId); Optional<Integer> getSignal(long workflowInstanceId); @Transactional boolean setSignal(long workflowInstanceId, Optional<Integer> signal, String reason, WorkflowActionType actionType); String getWorkflowInstanceType(long workflowInstanceId); }
WorkflowInstanceDao { @SuppressWarnings("null") public void updateWorkflowInstanceAfterExecution(WorkflowInstance instance, WorkflowInstanceAction action, List<WorkflowInstance> childWorkflows, List<WorkflowInstance> workflows, boolean createAction) { Assert.isTrue(action != null, "action can not be null"); Assert.isTrue(childWorkflows != null, "childWorkflows can not be null"); Assert.isTrue(workflows != null, "workflows can not be null"); Map<String, String> changedStateVariables = instance.getChangedStateVariables(); if (!createAction && (!childWorkflows.isEmpty() || !workflows.isEmpty() || !changedStateVariables.isEmpty())) { logger.info("Forcing action creation because new workflow instances are created or state variables are changed."); createAction = true; } if (createAction) { if (sqlVariants.hasUpdateableCTE() && childWorkflows.isEmpty() && workflows.isEmpty()) { updateWorkflowInstanceWithCTE(instance, action, changedStateVariables); } else { updateWorkflowInstanceWithTransaction(instance, action, childWorkflows, workflows, changedStateVariables); } } else { updateWorkflowInstance(instance); } } @Inject  WorkflowInstanceDao(SQLVariants sqlVariants, @NFlow JdbcTemplate nflowJdbcTemplate,
      @NFlow TransactionTemplate transactionTemplate, @NFlow NamedParameterJdbcTemplate nflowNamedParameterJdbcTemplate,
      ExecutorDao executorDao, WorkflowInstanceExecutor workflowInstanceExecutor, WorkflowInstanceFactory workflowInstanceFactory,
      Environment env); long insertWorkflowInstance(WorkflowInstance instance); @SuppressWarnings("null") void updateWorkflowInstanceAfterExecution(WorkflowInstance instance, WorkflowInstanceAction action,
      List<WorkflowInstance> childWorkflows, List<WorkflowInstance> workflows, boolean createAction); int updateWorkflowInstance(WorkflowInstance instance); void recoverWorkflowInstancesFromDeadNodes(); void checkStateVariableValueLength(String name, String value); boolean updateNotRunningWorkflowInstance(WorkflowInstance instance); boolean wakeUpWorkflowExternally(long workflowInstanceId, List<String> expectedStates); boolean wakeupWorkflowInstanceIfNotExecuting(long workflowInstanceId, List<String> expectedStates); WorkflowInstance getWorkflowInstance(long id, Set<WorkflowInstanceInclude> includes, Long maxActions); List<Long> pollNextWorkflowInstanceIds(final int batchSize); List<WorkflowInstance> queryWorkflowInstances(QueryWorkflowInstances query); Stream<WorkflowInstance> queryWorkflowInstancesAsStream(QueryWorkflowInstances query); @Transactional(propagation = MANDATORY) long insertWorkflowInstanceAction(final WorkflowInstance instance, final WorkflowInstanceAction action); long insertWorkflowInstanceAction(final WorkflowInstanceAction action); String getWorkflowInstanceState(long workflowInstanceId); Optional<Integer> getSignal(long workflowInstanceId); @Transactional boolean setSignal(long workflowInstanceId, Optional<Integer> signal, String reason, WorkflowActionType actionType); String getWorkflowInstanceType(long workflowInstanceId);  }