org.camunda.bpm.engine.impl.history.HistoryLevel Java Examples

The following examples show how to use org.camunda.bpm.engine.impl.history.HistoryLevel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IncidentEntity.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void fireHistoricIncidentEvent(final HistoryEventType eventType) {
  ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();

  HistoryLevel historyLevel = processEngineConfiguration.getHistoryLevel();
  if(historyLevel.isHistoryEventProduced(eventType, this)) {

    HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {
      @Override
      public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {

        HistoryEvent event = null;
        if (HistoryEvent.INCIDENT_CREATE.equals(eventType.getEventName())) {
          event = producer.createHistoricIncidentCreateEvt(IncidentEntity.this);

        } else if (HistoryEvent.INCIDENT_RESOLVE.equals(eventType.getEventName())) {
          event = producer.createHistoricIncidentResolveEvt(IncidentEntity.this);

        } else if (HistoryEvent.INCIDENT_DELETE.equals(eventType.getEventName())) {
          event = producer.createHistoricIncidentDeleteEvt(IncidentEntity.this);
        }
        return event;
      }
    });
  }
}
 
Example #2
Source File: TaskAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testStandaloneTaskCompleteWithTaskWorkPermission() {
  // given
  String taskId = "myTask";
  createTask(taskId);

  createGrantAuthorization(TASK, taskId, userId, TASK_WORK);

  // when
  taskService.complete(taskId);

  // then
  Task task = selectSingleTask();
  assertNull(task);

  if (!processEngineConfiguration.getHistoryLevel().equals(HistoryLevel.HISTORY_LEVEL_NONE)) {
    historyService.deleteHistoricTaskInstance(taskId);
  }
}
 
Example #3
Source File: AsyncTaskTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * CAM-3708
 */
@Deployment
public void testDeleteInScopeShouldNotInvokeOutputMapping() {
  // given
  ProcessInstance instance = runtimeService.startProcessInstanceByKey("asyncOutputMappingSubProcess");
  assertEquals(1, managementService.createJobQuery().count());

  // when
  runtimeService.deleteProcessInstance(instance.getId(), "");

  // then
  if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_AUDIT.getId()) {
    // the output mapping of the task has not been executed because the
    // activity was not active yet
    assertEquals(0, historyService.createHistoricVariableInstanceQuery().variableName("taskOutputMappingExecuted").count());

    // but the containing sub process output mapping was executed
    assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableName("subProcessOutputMappingExecuted").count());
  }
}
 
Example #4
Source File: DetermineHistoryLevelCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public HistoryLevel execute(final CommandContext commandContext) {
  final Integer databaseHistoryLevel = HistoryLevelSetupCommand.databaseHistoryLevel(commandContext);

  HistoryLevel result = null;

  if (databaseHistoryLevel != null) {
    for (final HistoryLevel historyLevel : historyLevels) {
      if (historyLevel.getId() == databaseHistoryLevel) {
        result = historyLevel;
        break;
      }
    }

    if (result != null) {
      return result;
    }
    else {
      // if a custom non-null value is not registered, throw an exception.
      throw new ProcessEngineException(String.format("The configured history level with id='%s' is not registered in this config.", databaseHistoryLevel));
    }
  }
  else {
    return null;
  }
}
 
Example #5
Source File: AbstractSetProcessInstanceStateCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected void triggerHistoryEvent(CommandContext commandContext){
  HistoryLevel historyLevel = commandContext.getProcessEngineConfiguration().getHistoryLevel();
  List<ProcessInstance> updatedProcessInstances = obtainProcessInstances(commandContext);
  //suspension state is not updated synchronously
  if (getNewSuspensionState() != null && updatedProcessInstances != null) {
    for (final ProcessInstance processInstance: updatedProcessInstances) {

      if (historyLevel.isHistoryEventProduced(HistoryEventTypes.PROCESS_INSTANCE_UPDATE, processInstance)) {
        HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {
          @Override
          public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {
            HistoricProcessInstanceEventEntity processInstanceUpdateEvt = (HistoricProcessInstanceEventEntity)
                producer.createProcessInstanceUpdateEvt((DelegateExecution) processInstance);
            if (SuspensionState.SUSPENDED.getStateCode() == getNewSuspensionState().getStateCode()) {
              processInstanceUpdateEvt.setState(HistoricProcessInstance.STATE_SUSPENDED);
            } else {
              processInstanceUpdateEvt.setState(HistoricProcessInstance.STATE_ACTIVE);
            }
            return processInstanceUpdateEvt;
          }
        });
      }
    }
  }
}
 
Example #6
Source File: AbstractDeleteProcessInstanceCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void triggerHistoryEvent(List<ProcessInstance> subProcesslist) {
  ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration();
  HistoryLevel historyLevel = configuration.getHistoryLevel();

  for (final ProcessInstance processInstance : subProcesslist) {
    // TODO: This smells bad, as the rest of the history is done via the
    // ParseListener
    if (historyLevel.isHistoryEventProduced(HistoryEventTypes.PROCESS_INSTANCE_UPDATE, processInstance)) {

      HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {
        @Override
        public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {
          return producer.createProcessInstanceUpdateEvt((DelegateExecution) processInstance);
        }
      });
    }
  }
}
 
Example #7
Source File: HistoricVariableJsonSerializationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSelectHistoricSerializedValues() throws JSONException {
  if (processEngineConfiguration.getHistoryLevel().getId() >=
      HistoryLevel.HISTORY_LEVEL_AUDIT.getId()) {


    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    JsonSerializable bean = new JsonSerializable("a String", 42, false);
    runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME));

    HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult();
    assertNotNull(historicVariable.getValue());
    assertNull(historicVariable.getErrorMessage());

    ObjectValue typedValue = (ObjectValue) historicVariable.getTypedValue();
    assertEquals(JSON_FORMAT_NAME, typedValue.getSerializationDataFormat());
    JSONAssert.assertEquals(bean.toExpectedJsonString(),new String(typedValue.getValueSerialized()), true);
    assertEquals(JsonSerializable.class.getName(), typedValue.getObjectTypeName());
  }
}
 
Example #8
Source File: HistoricVariableJsonSerializationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSelectHistoricVariableInstances() throws JSONException {
  if (processEngineConfiguration.getHistoryLevel().getId() >=
      HistoryLevel.HISTORY_LEVEL_AUDIT.getId()) {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    JsonSerializable bean = new JsonSerializable("a String", 42, false);
    runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(bean).serializationDataFormat(JSON_FORMAT_NAME).create());

    HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult();
    assertNotNull(historicVariable.getValue());
    assertNull(historicVariable.getErrorMessage());

    assertEquals(ValueType.OBJECT.getName(), historicVariable.getTypeName());
    assertEquals(ValueType.OBJECT.getName(), historicVariable.getVariableTypeName());

    JsonSerializable historyValue = (JsonSerializable) historicVariable.getValue();
    assertEquals(bean.getStringProperty(), historyValue.getStringProperty());
    assertEquals(bean.getIntProperty(), historyValue.getIntProperty());
    assertEquals(bean.getBooleanProperty(), historyValue.getBooleanProperty());
  }
}
 
Example #9
Source File: DatabaseHistoryPropertyAutoTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void usesDefaultValueAuditWhenNoValueIsConfigured() {
  final ProcessEngineConfigurationImpl config = config("true", ProcessEngineConfiguration.HISTORY_AUTO);
  ProcessEngineImpl processEngine = buildEngine(config);

  final Integer level = config.getCommandExecutorSchemaOperations().execute(new Command<Integer>() {
    @Override
    public Integer execute(CommandContext commandContext) {
      return HistoryLevelSetupCommand.databaseHistoryLevel(commandContext);
    }
  });

  assertThat(level, equalTo(HistoryLevel.HISTORY_LEVEL_AUDIT.getId()));

  assertThat(processEngine.getProcessEngineConfiguration().getHistoryLevel(), equalTo(HistoryLevel.HISTORY_LEVEL_AUDIT));
}
 
Example #10
Source File: FormServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubmitTaskFormForStandaloneTask() {
  // given
  String id = "standaloneTask";
  Task task = taskService.newTask(id);
  taskService.saveTask(task);

  // when
  formService.submitTaskForm(task.getId(), Variables.createVariables().putValue("foo", "bar"));


  if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_AUDIT.getId()) {
    HistoricVariableInstance variableInstance = historyService
      .createHistoricVariableInstanceQuery()
      .taskIdIn(id)
      .singleResult();

    assertNotNull(variableInstance);
    assertEquals("foo", variableInstance.getName());
    assertEquals("bar", variableInstance.getValue());
  }

  taskService.deleteTask(id, true);
}
 
Example #11
Source File: MultiTenancyProcessDefinitionCmdsTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteCascadeProcessDefinitionDisabledTenantCheck() {
  //given deployment with a process definition and process instances
  BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess("process").startEvent().userTask().endEvent().done();
  testRule.deployForTenant(TENANT_ONE, bpmnModel);
  //tenant check disabled
  processEngineConfiguration.setTenantCheckEnabled(false);
  ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
  ProcessDefinition processDefinition = processDefinitionQuery.processDefinitionKey("process").singleResult();
  engineRule.getRuntimeService().createProcessInstanceByKey("process").executeWithVariablesInReturn();
  //user with no authentication
  identityService.setAuthentication("user", null, null);

  //when the corresponding process definition is cascading deleted from the deployment
  repositoryService.deleteProcessDefinition(processDefinition.getId(), true);

  //then exist no process instance and one definition, because test case deployes per default one definition
  identityService.clearAuthentication();
  assertEquals(0, engineRule.getRuntimeService().createProcessInstanceQuery().count());
  if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_ACTIVITY.getId()) {
    assertEquals(0, engineRule.getHistoryService().createHistoricActivityInstanceQuery().count());
  }
  assertThat(repositoryService.createProcessDefinitionQuery().count(), is(1L));
  assertThat(repositoryService.createProcessDefinitionQuery().tenantIdIn(TENANT_ONE).count(), is(1L));
}
 
Example #12
Source File: AsyncTaskTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * CAM-3708
 */
@Deployment
public void testDeleteShouldNotInvokeOutputMapping() {
  // given
  ProcessInstance instance = runtimeService.startProcessInstanceByKey("asyncOutputMapping");
  assertEquals(1, managementService.createJobQuery().count());

  // when
  runtimeService.deleteProcessInstance(instance.getId(), "");

  // then the output mapping has not been executed because the
  // activity was not active yet
  if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_AUDIT.getId()) {
    assertEquals(0, historyService.createHistoricVariableInstanceQuery().count());
  }

}
 
Example #13
Source File: DeleteProcessDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteProcessDefinitionCascade() {
  // given process definition and a process instance
  BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess("process").startEvent().userTask().endEvent().done();
  deployment = repositoryService.createDeployment()
                                .addModelInstance("process.bpmn", bpmnModel)
                                .deploy();
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process").singleResult();
  runtimeService.createProcessInstanceByKey("process").executeWithVariablesInReturn();

  //when the corresponding process definition is cascading deleted from the deployment
  repositoryService.deleteProcessDefinition(processDefinition.getId(), true);

  //then exist no process instance and no definition
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
  assertEquals(0, repositoryService.createProcessDefinitionQuery().count());
  if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_ACTIVITY.getId()) {
    assertEquals(0, engineRule.getHistoryService().createHistoricActivityInstanceQuery().count());
  }
}
 
Example #14
Source File: TaskAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testStandaloneTaskCompleteTask() {
  // given
  String taskId = "myTask";
  createTask(taskId);

  createGrantAuthorization(TASK, taskId, userId, UPDATE);

  // when
  taskService.complete(taskId);

  // then
  Task task = selectSingleTask();
  assertNull(task);

  if (!processEngineConfiguration.getHistoryLevel().equals(HistoryLevel.HISTORY_LEVEL_NONE)) {
    historyService.deleteHistoricTaskInstance(taskId);
  }
}
 
Example #15
Source File: PvmExecutionImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void setProcessBusinessKey(String businessKey) {
  final PvmExecutionImpl processInstance = getProcessInstance();
  processInstance.setBusinessKey(businessKey);

  HistoryLevel historyLevel = Context
  .getCommandContext().getProcessEngineConfiguration().getHistoryLevel();
  if (historyLevel.isHistoryEventProduced(HistoryEventTypes.PROCESS_INSTANCE_UPDATE, processInstance)) {

    HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {
      @Override
      public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {
        return producer.createProcessInstanceUpdateEvt(processInstance);
      }
    });
  }
}
 
Example #16
Source File: HistoricTaskInstanceManager.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void markTaskInstanceEnded(String taskId, final String deleteReason) {
  ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration();

  final TaskEntity taskEntity = Context.getCommandContext()
      .getDbEntityManager()
      .selectById(TaskEntity.class, taskId);

  HistoryLevel historyLevel = configuration.getHistoryLevel();
  if(historyLevel.isHistoryEventProduced(HistoryEventTypes.TASK_INSTANCE_COMPLETE, taskEntity)) {

    HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {
      @Override
      public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {
        return producer.createTaskInstanceCompleteEvt(taskEntity, deleteReason);
      }
    });
  }
}
 
Example #17
Source File: IncidentAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void clearDatabase() {
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
  commandExecutor.execute(new Command<Object>() {
    public Object execute(CommandContext commandContext) {
      HistoryLevel historyLevel = Context.getProcessEngineConfiguration().getHistoryLevel();
      if (historyLevel.equals(HistoryLevel.HISTORY_LEVEL_FULL)) {
        commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerSuspendProcessDefinitionHandler.TYPE);
        List<HistoricIncident> incidents = Context.getProcessEngineConfiguration().getHistoryService().createHistoricIncidentQuery().list();
        for (HistoricIncident incident : incidents) {
          commandContext.getHistoricIncidentManager().delete((HistoricIncidentEntity) incident);
        }
      }

      return null;
    }
  });
}
 
Example #18
Source File: RuntimeServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void checkHistoricVariableUpdateEntity(String variableName, String processInstanceId) {
  if (processEngineConfiguration.getHistoryLevel().equals(HistoryLevel.HISTORY_LEVEL_FULL)) {
    boolean deletedVariableUpdateFound = false;

    List<HistoricDetail> resultSet = historyService.createHistoricDetailQuery().processInstanceId(processInstanceId).list();
    for (HistoricDetail currentHistoricDetail : resultSet) {
      assertTrue(currentHistoricDetail instanceof HistoricDetailVariableInstanceUpdateEntity);
      HistoricDetailVariableInstanceUpdateEntity historicVariableUpdate = (HistoricDetailVariableInstanceUpdateEntity) currentHistoricDetail;

      if (historicVariableUpdate.getName().equals(variableName)) {
        if (historicVariableUpdate.getValue() == null) {
          if (deletedVariableUpdateFound) {
            fail("Mismatch: A HistoricVariableUpdateEntity with a null value already found");
          } else {
            deletedVariableUpdateFound = true;
          }
        }
      }
    }

    assertTrue(deletedVariableUpdateFound);
  }
}
 
Example #19
Source File: DeleteProcessDefinitionAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteProcessDefinitionCascade() {
  // given process definition and a process instance
  BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess(PROCESS_DEFINITION_KEY).startEvent().userTask().endEvent().done();
  testHelper.deploy(bpmnModel);

  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_DEFINITION_KEY).singleResult();
  runtimeService.createProcessInstanceByKey(PROCESS_DEFINITION_KEY).executeWithVariablesInReturn();

  authRule.init(scenario)
    .withUser("userId")
    .start();

  //when the corresponding process definition is cascading deleted from the deployment
  repositoryService.deleteProcessDefinition(processDefinition.getId(), true);

  //then exist no process instance and no definition
  if (authRule.assertScenario(scenario)) {
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().count());
    if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_ACTIVITY.getId()) {
      assertEquals(0, engineRule.getHistoryService().createHistoricActivityInstanceQuery().count());
    }
  }
}
 
Example #20
Source File: ExternalTaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testSetRetriesToZero() {
  // given
  runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
  List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(5, WORKER_ID)
      .topic(TOPIC_NAME, LOCK_TIME)
      .execute();

  LockedExternalTask lockedTask = externalTasks.get(0);

  // when
  externalTaskService.setRetries(lockedTask.getId(), 0);

  // then
  Incident incident = runtimeService.createIncidentQuery().singleResult();
  assertNotNull(incident);
  assertEquals(lockedTask.getId(), incident.getConfiguration());

  if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_FULL.getId()) {

    HistoricIncident historicIncident = historyService.createHistoricIncidentQuery().singleResult();
    assertNotNull(historicIncident);
    assertEquals(incident.getId(), historicIncident.getId());
    assertTrue(historicIncident.isOpen());
    assertNull(historicIncident.getHistoryConfiguration());
  }

  // and resetting the retries removes the incident again
  externalTaskService.setRetries(lockedTask.getId(), 5);

  assertEquals(0, runtimeService.createIncidentQuery().count());

}
 
Example #21
Source File: ExternalTaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testSetRetriesResolvesFailureIncident() {
  // given
  runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
  List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(5, WORKER_ID)
      .topic(TOPIC_NAME, LOCK_TIME)
      .execute();

  LockedExternalTask lockedTask = externalTasks.get(0);
  externalTaskService.handleFailure(lockedTask.getId(), WORKER_ID, "error", 0, LOCK_TIME);

  Incident incident = runtimeService.createIncidentQuery().singleResult();

  // when
  externalTaskService.setRetries(lockedTask.getId(), 5);

  // then the incident is resolved
  assertEquals(0, runtimeService.createIncidentQuery().count());

  if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_FULL.getId()) {

    HistoricIncident historicIncident = historyService.createHistoricIncidentQuery().singleResult();
    assertNotNull(historicIncident);
    assertEquals(incident.getId(), historicIncident.getId());
    assertTrue(historicIncident.isResolved());
  }

  // and the task can be fetched again
  ClockUtil.setCurrentTime(nowPlus(LOCK_TIME + 3000L));

  externalTasks = externalTaskService.fetchAndLock(5, WORKER_ID)
      .topic(TOPIC_NAME, LOCK_TIME)
      .execute();

  assertEquals(1, externalTasks.size());
  assertEquals(lockedTask.getId(), externalTasks.get(0).getId());
}
 
Example #22
Source File: ExternalTaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testCompleteWithLocalVariables() {
  // given
  BpmnModelInstance instance = Bpmn.createExecutableProcess("Process").startEvent().serviceTask("externalTask")
      .camundaType("external").camundaTopic("foo").camundaTaskPriority("100")
      .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ReadLocalVariableListenerImpl.class)
      .userTask("user").endEvent().done();

  deployment(instance);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process");

  List<LockedExternalTask> lockedTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic("foo", 1L).execute();

  // when
  externalTaskService.complete(lockedTasks.get(0).getId(), WORKER_ID, null,
      Variables.createVariables().putValue("abc", "bar"));

  // then
  VariableInstance variableInstance = runtimeService.createVariableInstanceQuery()
      .processInstanceIdIn(processInstance.getId()).singleResult();
  assertNull(variableInstance);
  if (processEngineConfiguration.getHistoryLevel() == HistoryLevel.HISTORY_LEVEL_AUDIT
      || processEngineConfiguration.getHistoryLevel() == HistoryLevel.HISTORY_LEVEL_FULL) {
    HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery()
        .activityInstanceIdIn(lockedTasks.get(0).getActivityInstanceId()).singleResult();
    assertNotNull(historicVariableInstance);
    assertEquals("abc", historicVariableInstance.getName());
    assertEquals("bar", historicVariableInstance.getValue());
  }
}
 
Example #23
Source File: HistoryLevelTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldInitHistoryLevelByString() throws Exception {
  ProcessEngineConfigurationImpl config = createConfig();
  config.setHistory(HistoryLevel.HISTORY_LEVEL_FULL.getName());

  ProcessEngineConfigurationImpl processEngineConfiguration = buildProcessEngine(config);

  assertThat(processEngineConfiguration.getHistoryLevels().size(), is(4));
  assertThat(processEngineConfiguration.getHistoryLevel(), is(HistoryLevel.HISTORY_LEVEL_FULL));
  assertThat(processEngineConfiguration.getHistory(), is(HistoryLevel.HISTORY_LEVEL_FULL.getName()));
}
 
Example #24
Source File: MigrationUserTaskTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testMigrateWithSubTask() {
  // given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);

  MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
    .mapEqualActivities()
    .build();

  ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());

  Task task = rule.getTaskService().createTaskQuery().singleResult();
  Task subTask = rule.getTaskService().newTask();
  subTask.setParentTaskId(task.getId());
  rule.getTaskService().saveTask(subTask);

  // when
  testHelper.migrateProcessInstance(migrationPlan, processInstance);

  // then the sub task properties have not been updated (i.e. subtask should not reference the process instance/definition now)
  Task subTaskAfterMigration = rule.getTaskService().createTaskQuery().taskId(subTask.getId()).singleResult();
  Assert.assertNull(subTaskAfterMigration.getProcessDefinitionId());
  Assert.assertNull(subTaskAfterMigration.getProcessInstanceId());
  Assert.assertNull(subTaskAfterMigration.getTaskDefinitionKey());

  // the tasks can be completed and the process can be ended
  rule.getTaskService().complete(subTask.getId());
  rule.getTaskService().complete(task.getId());
  testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());

  if (!rule.getProcessEngineConfiguration().getHistoryLevel().equals(HistoryLevel.HISTORY_LEVEL_NONE)) {
    rule.getHistoryService().deleteHistoricTaskInstance(subTaskAfterMigration.getId());
  }
}
 
Example #25
Source File: TestHelper.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private static HistoryLevel getHistoryLevelForName(List<HistoryLevel> historyLevels, String name) {
  for (HistoryLevel historyLevel : historyLevels) {

    if (historyLevel.getName().equalsIgnoreCase(name)) {
      return historyLevel;
    }
  }
  throw new IllegalArgumentException("Unknown history level: " + name);
}
 
Example #26
Source File: TestHelper.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private static boolean historyLevelCheck(ProcessEngine processEngine, RequiredHistoryLevel annotation) {
  ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();

  HistoryLevel requiredHistoryLevel = getHistoryLevelForName(processEngineConfiguration.getHistoryLevels(), annotation.value());
  HistoryLevel currentHistoryLevel = processEngineConfiguration.getHistoryLevel();

  return currentHistoryLevel.getId() >= requiredHistoryLevel.getId();
}
 
Example #27
Source File: DetermineHistoryLevelCmdTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void failWhenExistingHistoryLevelIsNotRegistered() {
  // init the db with custom level
  HistoryLevel customLevel = new HistoryLevel() {
    @Override
    public int getId() {
      return 99;
    }

    @Override
    public String getName() {
      return "custom";
    }

    @Override
    public boolean isHistoryEventProduced(HistoryEventType eventType, Object entity) {
      return false;
    }
  };
  ProcessEngineConfigurationImpl config = config("true", "custom");
  config.setCustomHistoryLevels(Arrays.asList(customLevel));
  processEngineImpl = (ProcessEngineImpl) config.buildProcessEngine();

  thrown.expect(ProcessEngineException.class);
  thrown.expectMessage("The configured history level with id='99' is not registered in this config.");

  config.getCommandExecutorSchemaOperations().execute(
      new DetermineHistoryLevelCmd(Collections.<HistoryLevel>emptyList()));
}
 
Example #28
Source File: HistoricBatchManager.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void createHistoricBatch(final BatchEntity batch) {
  ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration();

  HistoryLevel historyLevel = configuration.getHistoryLevel();
  if(historyLevel.isHistoryEventProduced(HistoryEventTypes.BATCH_START, batch)) {

    HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {
      @Override
      public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {
        return producer.createBatchStartEvent(batch);
      }
    });
  }
}
 
Example #29
Source File: HistoricIncidentManager.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected boolean isHistoryEventProduced() {
  HistoryLevel historyLevel = Context.getProcessEngineConfiguration().getHistoryLevel();
  return historyLevel.isHistoryEventProduced(HistoryEventTypes.INCIDENT_CREATE, null) ||
         historyLevel.isHistoryEventProduced(HistoryEventTypes.INCIDENT_DELETE, null) ||
         historyLevel.isHistoryEventProduced(HistoryEventTypes.INCIDENT_MIGRATE, null) ||
         historyLevel.isHistoryEventProduced(HistoryEventTypes.INCIDENT_RESOLVE, null);
}
 
Example #30
Source File: ExecutionEntity.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void fireHistoricActivityInstanceUpdate() {
  ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration();
  HistoryLevel historyLevel = configuration.getHistoryLevel();
  if (historyLevel.isHistoryEventProduced(HistoryEventTypes.ACTIVITY_INSTANCE_UPDATE, this)) {
    // publish update event for current activity instance (containing the id
    // of the sub process/case)
    HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {
      @Override
      public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {
        return producer.createActivityInstanceUpdateEvt(ExecutionEntity.this);
      }
    });
  }
}