Search in sources :

Example 26 with UserOperationLogEntry

use of org.camunda.bpm.engine.history.UserOperationLogEntry in project camunda-bpm-platform by camunda.

the class SetProcessDefinitionVersionCmdTest method testOpLogSetProcessDefinitionVersionCmd.

public void testOpLogSetProcessDefinitionVersionCmd() {
    // given
    try {
        identityService.setAuthenticatedUserId("demo");
        String resource = "org/camunda/bpm/engine/test/api/runtime/migration/SetProcessDefinitionVersionCmdTest.bpmn";
        // Deployments
        org.camunda.bpm.engine.repository.Deployment firstDeployment = repositoryService.createDeployment().addClasspathResource(resource).deploy();
        org.camunda.bpm.engine.repository.Deployment secondDeployment = repositoryService.createDeployment().addClasspathResource(resource).deploy();
        // Process definitions
        ProcessDefinition processDefinitionV1 = repositoryService.createProcessDefinitionQuery().deploymentId(firstDeployment.getId()).singleResult();
        ProcessDefinition processDefinitionV2 = repositoryService.createProcessDefinitionQuery().deploymentId(secondDeployment.getId()).singleResult();
        // start process instance
        ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionV1.getId());
        // when
        setProcessDefinitionVersion(processInstance.getId(), 2);
        // then
        ProcessInstance processInstanceAfterMigration = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
        assertEquals(processDefinitionV2.getId(), processInstanceAfterMigration.getProcessDefinitionId());
        if (processEngineConfiguration.getHistoryLevel().equals(HistoryLevel.HISTORY_LEVEL_FULL)) {
            List<UserOperationLogEntry> userOperations = historyService.createUserOperationLogQuery().processInstanceId(processInstance.getId()).list();
            assertEquals(1, userOperations.size());
            UserOperationLogEntry userOperationLogEntry = userOperations.get(0);
            assertEquals(UserOperationLogEntry.OPERATION_TYPE_MODIFY_PROCESS_INSTANCE, userOperationLogEntry.getOperationType());
            assertEquals("processDefinitionVersion", userOperationLogEntry.getProperty());
            assertEquals("1", userOperationLogEntry.getOrgValue());
            assertEquals("2", userOperationLogEntry.getNewValue());
        }
        // Clean up the test
        repositoryService.deleteDeployment(firstDeployment.getId(), true);
        repositoryService.deleteDeployment(secondDeployment.getId(), true);
    } finally {
        identityService.clearAuthentication();
    }
}
Also used : UserOperationLogEntry(org.camunda.bpm.engine.history.UserOperationLogEntry) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance)

Example 27 with UserOperationLogEntry

use of org.camunda.bpm.engine.history.UserOperationLogEntry in project camunda-bpm-platform by camunda.

the class BatchMigrationUserOperationLogTest method testLogCreation.

@Test
public void testLogCreation() {
    // given
    ProcessDefinition sourceProcessDefinition = migrationRule.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);
    ProcessDefinition targetProcessDefinition = migrationRule.deployAndGetDefinition(modify(ProcessModels.ONE_TASK_PROCESS).changeElementId(ProcessModels.PROCESS_KEY, "new" + ProcessModels.PROCESS_KEY));
    MigrationPlan migrationPlan = engineRule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapEqualActivities().build();
    ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
    // when
    engineRule.getIdentityService().setAuthenticatedUserId(USER_ID);
    engineRule.getRuntimeService().newMigration(migrationPlan).processInstanceIds(Arrays.asList(processInstance.getId())).executeAsync();
    engineRule.getIdentityService().clearAuthentication();
    // then
    List<UserOperationLogEntry> opLogEntries = engineRule.getHistoryService().createUserOperationLogQuery().list();
    Assert.assertEquals(3, opLogEntries.size());
    Map<String, UserOperationLogEntry> entries = asMap(opLogEntries);
    UserOperationLogEntry procDefEntry = entries.get("processDefinitionId");
    Assert.assertNotNull(procDefEntry);
    Assert.assertEquals("ProcessInstance", procDefEntry.getEntityType());
    Assert.assertEquals("Migrate", procDefEntry.getOperationType());
    Assert.assertEquals(sourceProcessDefinition.getId(), procDefEntry.getProcessDefinitionId());
    Assert.assertEquals(sourceProcessDefinition.getKey(), procDefEntry.getProcessDefinitionKey());
    Assert.assertNull(procDefEntry.getProcessInstanceId());
    Assert.assertEquals(sourceProcessDefinition.getId(), procDefEntry.getOrgValue());
    Assert.assertEquals(targetProcessDefinition.getId(), procDefEntry.getNewValue());
    UserOperationLogEntry asyncEntry = entries.get("async");
    Assert.assertNotNull(asyncEntry);
    Assert.assertEquals("ProcessInstance", asyncEntry.getEntityType());
    Assert.assertEquals("Migrate", asyncEntry.getOperationType());
    Assert.assertEquals(sourceProcessDefinition.getId(), asyncEntry.getProcessDefinitionId());
    Assert.assertEquals(sourceProcessDefinition.getKey(), asyncEntry.getProcessDefinitionKey());
    Assert.assertNull(asyncEntry.getProcessInstanceId());
    Assert.assertNull(asyncEntry.getOrgValue());
    Assert.assertEquals("true", asyncEntry.getNewValue());
    UserOperationLogEntry numInstancesEntry = entries.get("nrOfInstances");
    Assert.assertNotNull(numInstancesEntry);
    Assert.assertEquals("ProcessInstance", numInstancesEntry.getEntityType());
    Assert.assertEquals("Migrate", numInstancesEntry.getOperationType());
    Assert.assertEquals(sourceProcessDefinition.getId(), numInstancesEntry.getProcessDefinitionId());
    Assert.assertEquals(sourceProcessDefinition.getKey(), numInstancesEntry.getProcessDefinitionKey());
    Assert.assertNull(numInstancesEntry.getProcessInstanceId());
    Assert.assertNull(numInstancesEntry.getOrgValue());
    Assert.assertEquals("1", numInstancesEntry.getNewValue());
    Assert.assertEquals(procDefEntry.getOperationId(), asyncEntry.getOperationId());
    Assert.assertEquals(asyncEntry.getOperationId(), numInstancesEntry.getOperationId());
}
Also used : UserOperationLogEntry(org.camunda.bpm.engine.history.UserOperationLogEntry) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 28 with UserOperationLogEntry

use of org.camunda.bpm.engine.history.UserOperationLogEntry in project camunda-bpm-platform by camunda.

the class BatchHistoricDecisionInstanceDeletionUserOperationTest method testCreationByIds.

@Test
public void testCreationByIds() {
    // when
    identityService.setAuthenticatedUserId(USER_ID);
    historyService.deleteHistoricDecisionInstancesAsync(decisionInstanceIds, "a-delete-reason");
    identityService.clearAuthentication();
    // then
    List<UserOperationLogEntry> opLogEntries = engineRule.getHistoryService().createUserOperationLogQuery().list();
    Assert.assertEquals(4, opLogEntries.size());
    Map<String, UserOperationLogEntry> entries = asMap(opLogEntries);
    UserOperationLogEntry typeEntry = entries.get("type");
    assertNotNull(typeEntry);
    assertEquals(EntityTypes.DECISION_INSTANCE, typeEntry.getEntityType());
    assertEquals(UserOperationLogEntry.OPERATION_TYPE_DELETE, typeEntry.getOperationType());
    assertNull(typeEntry.getProcessDefinitionId());
    assertNull(typeEntry.getProcessDefinitionKey());
    assertNull(typeEntry.getProcessInstanceId());
    assertNull(typeEntry.getOrgValue());
    assertEquals("history", typeEntry.getNewValue());
    UserOperationLogEntry asyncEntry = entries.get("async");
    assertNotNull(asyncEntry);
    assertEquals(EntityTypes.DECISION_INSTANCE, typeEntry.getEntityType());
    assertEquals(UserOperationLogEntry.OPERATION_TYPE_DELETE, typeEntry.getOperationType());
    assertNull(typeEntry.getProcessDefinitionId());
    assertNull(typeEntry.getProcessDefinitionKey());
    assertNull(typeEntry.getProcessInstanceId());
    assertNull(typeEntry.getOrgValue());
    assertEquals("true", asyncEntry.getNewValue());
    UserOperationLogEntry numInstancesEntry = entries.get("nrOfInstances");
    assertNotNull(numInstancesEntry);
    assertEquals(EntityTypes.DECISION_INSTANCE, typeEntry.getEntityType());
    assertEquals(UserOperationLogEntry.OPERATION_TYPE_DELETE, typeEntry.getOperationType());
    assertNull(typeEntry.getProcessDefinitionId());
    assertNull(typeEntry.getProcessDefinitionKey());
    assertNull(typeEntry.getProcessInstanceId());
    assertNull(typeEntry.getOrgValue());
    assertEquals("10", numInstancesEntry.getNewValue());
    UserOperationLogEntry deleteReasonEntry = entries.get("deleteReason");
    assertNotNull(deleteReasonEntry);
    assertEquals(EntityTypes.DECISION_INSTANCE, typeEntry.getEntityType());
    assertEquals(UserOperationLogEntry.OPERATION_TYPE_DELETE, typeEntry.getOperationType());
    assertNull(typeEntry.getProcessDefinitionId());
    assertNull(typeEntry.getProcessDefinitionKey());
    assertNull(typeEntry.getProcessInstanceId());
    assertNull(typeEntry.getOrgValue());
    assertEquals("a-delete-reason", deleteReasonEntry.getNewValue());
    assertEquals(typeEntry.getOperationId(), asyncEntry.getOperationId());
    assertEquals(asyncEntry.getOperationId(), deleteReasonEntry.getOperationId());
    assertEquals(numInstancesEntry.getOperationId(), deleteReasonEntry.getOperationId());
}
Also used : UserOperationLogEntry(org.camunda.bpm.engine.history.UserOperationLogEntry) Test(org.junit.Test)

Example 29 with UserOperationLogEntry

use of org.camunda.bpm.engine.history.UserOperationLogEntry in project camunda-bpm-platform by camunda.

the class BatchHistoricDecisionInstanceDeletionUserOperationTest method testCreationByIdsAndQuery.

@Test
public void testCreationByIdsAndQuery() {
    // given
    HistoricDecisionInstanceQuery query = historyService.createHistoricDecisionInstanceQuery().decisionDefinitionKey(DECISION);
    // when
    identityService.setAuthenticatedUserId(USER_ID);
    historyService.deleteHistoricDecisionInstancesAsync(decisionInstanceIds, query, "a-delete-reason");
    identityService.clearAuthentication();
    // then
    List<UserOperationLogEntry> opLogEntries = engineRule.getHistoryService().createUserOperationLogQuery().list();
    Assert.assertEquals(4, opLogEntries.size());
    Map<String, UserOperationLogEntry> entries = asMap(opLogEntries);
    UserOperationLogEntry typeEntry = entries.get("type");
    assertNotNull(typeEntry);
    assertEquals(EntityTypes.DECISION_INSTANCE, typeEntry.getEntityType());
    assertEquals(UserOperationLogEntry.OPERATION_TYPE_DELETE, typeEntry.getOperationType());
    assertNull(typeEntry.getProcessDefinitionId());
    assertNull(typeEntry.getProcessDefinitionKey());
    assertNull(typeEntry.getProcessInstanceId());
    assertNull(typeEntry.getOrgValue());
    assertEquals("history", typeEntry.getNewValue());
    UserOperationLogEntry asyncEntry = entries.get("async");
    assertNotNull(asyncEntry);
    assertEquals(EntityTypes.DECISION_INSTANCE, typeEntry.getEntityType());
    assertEquals(UserOperationLogEntry.OPERATION_TYPE_DELETE, typeEntry.getOperationType());
    assertNull(typeEntry.getProcessDefinitionId());
    assertNull(typeEntry.getProcessDefinitionKey());
    assertNull(typeEntry.getProcessInstanceId());
    assertNull(typeEntry.getOrgValue());
    assertEquals("true", asyncEntry.getNewValue());
    UserOperationLogEntry numInstancesEntry = entries.get("nrOfInstances");
    assertNotNull(numInstancesEntry);
    assertEquals(EntityTypes.DECISION_INSTANCE, typeEntry.getEntityType());
    assertEquals(UserOperationLogEntry.OPERATION_TYPE_DELETE, typeEntry.getOperationType());
    assertNull(typeEntry.getProcessDefinitionId());
    assertNull(typeEntry.getProcessDefinitionKey());
    assertNull(typeEntry.getProcessInstanceId());
    assertNull(typeEntry.getOrgValue());
    assertEquals("10", numInstancesEntry.getNewValue());
    UserOperationLogEntry deleteReasonEntry = entries.get("deleteReason");
    assertNotNull(deleteReasonEntry);
    assertEquals(EntityTypes.DECISION_INSTANCE, typeEntry.getEntityType());
    assertEquals(UserOperationLogEntry.OPERATION_TYPE_DELETE, typeEntry.getOperationType());
    assertNull(typeEntry.getProcessDefinitionId());
    assertNull(typeEntry.getProcessDefinitionKey());
    assertNull(typeEntry.getProcessInstanceId());
    assertNull(typeEntry.getOrgValue());
    assertEquals("a-delete-reason", deleteReasonEntry.getNewValue());
    assertEquals(typeEntry.getOperationId(), asyncEntry.getOperationId());
    assertEquals(asyncEntry.getOperationId(), numInstancesEntry.getOperationId());
    assertEquals(numInstancesEntry.getOperationId(), deleteReasonEntry.getOperationId());
}
Also used : UserOperationLogEntry(org.camunda.bpm.engine.history.UserOperationLogEntry) HistoricDecisionInstanceQuery(org.camunda.bpm.engine.history.HistoricDecisionInstanceQuery) Test(org.junit.Test)

Example 30 with UserOperationLogEntry

use of org.camunda.bpm.engine.history.UserOperationLogEntry in project camunda-bpm-platform by camunda.

the class UserOperationLogQueryTest method testQueryJobOperations.

@Deployment(resources = { "org/camunda/bpm/engine/test/history/HistoricJobLogTest.testAsyncContinuation.bpmn20.xml" })
public void testQueryJobOperations() {
    // given
    process = runtimeService.startProcessInstanceByKey("process");
    // when
    managementService.suspendJobDefinitionByProcessDefinitionId(process.getProcessDefinitionId());
    managementService.activateJobDefinitionByProcessDefinitionId(process.getProcessDefinitionId());
    managementService.suspendJobByProcessInstanceId(process.getId());
    managementService.activateJobByProcessInstanceId(process.getId());
    // then
    assertEquals(2, query().entityType(JOB_DEFINITION).count());
    assertEquals(2, query().entityType(JOB).count());
    // active job definition
    UserOperationLogEntry activeJobDefinitionEntry = query().entityType(JOB_DEFINITION).processDefinitionId(process.getProcessDefinitionId()).operationType(OPERATION_TYPE_ACTIVATE_JOB_DEFINITION).singleResult();
    assertNotNull(activeJobDefinitionEntry);
    assertEquals(process.getProcessDefinitionId(), activeJobDefinitionEntry.getProcessDefinitionId());
    assertEquals(deploymentId, activeJobDefinitionEntry.getDeploymentId());
    assertEquals("suspensionState", activeJobDefinitionEntry.getProperty());
    assertEquals("active", activeJobDefinitionEntry.getNewValue());
    assertNull(activeJobDefinitionEntry.getOrgValue());
    // active job
    UserOperationLogEntry activateJobIdEntry = query().entityType(JOB).processInstanceId(process.getProcessInstanceId()).operationType(OPERATION_TYPE_ACTIVATE_JOB).singleResult();
    assertNotNull(activateJobIdEntry);
    assertEquals(process.getProcessInstanceId(), activateJobIdEntry.getProcessInstanceId());
    assertEquals(deploymentId, activateJobIdEntry.getDeploymentId());
    assertEquals("suspensionState", activateJobIdEntry.getProperty());
    assertEquals("active", activateJobIdEntry.getNewValue());
    assertNull(activateJobIdEntry.getOrgValue());
    // suspended job definition
    UserOperationLogEntry suspendJobDefinitionEntry = query().entityType(JOB_DEFINITION).processDefinitionId(process.getProcessDefinitionId()).operationType(OPERATION_TYPE_SUSPEND_JOB_DEFINITION).singleResult();
    assertNotNull(suspendJobDefinitionEntry);
    assertEquals(process.getProcessDefinitionId(), suspendJobDefinitionEntry.getProcessDefinitionId());
    assertEquals(deploymentId, suspendJobDefinitionEntry.getDeploymentId());
    assertEquals("suspensionState", suspendJobDefinitionEntry.getProperty());
    assertEquals("suspended", suspendJobDefinitionEntry.getNewValue());
    assertNull(suspendJobDefinitionEntry.getOrgValue());
    // suspended job
    UserOperationLogEntry suspendedJobEntry = query().entityType(JOB).processInstanceId(process.getProcessInstanceId()).operationType(OPERATION_TYPE_SUSPEND_JOB).singleResult();
    assertNotNull(suspendedJobEntry);
    assertEquals(process.getProcessInstanceId(), suspendedJobEntry.getProcessInstanceId());
    assertEquals(deploymentId, suspendedJobEntry.getDeploymentId());
    assertEquals("suspensionState", suspendedJobEntry.getProperty());
    assertEquals("suspended", suspendedJobEntry.getNewValue());
    assertNull(suspendedJobEntry.getOrgValue());
}
Also used : UserOperationLogEntry(org.camunda.bpm.engine.history.UserOperationLogEntry) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

UserOperationLogEntry (org.camunda.bpm.engine.history.UserOperationLogEntry)59 Deployment (org.camunda.bpm.engine.test.Deployment)25 UserOperationLogQuery (org.camunda.bpm.engine.history.UserOperationLogQuery)20 Test (org.junit.Test)15 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)11 Deployment (org.camunda.bpm.engine.repository.Deployment)8 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)7 Date (java.util.Date)4 JobDefinition (org.camunda.bpm.engine.management.JobDefinition)4 RequiredHistoryLevel (org.camunda.bpm.engine.test.RequiredHistoryLevel)4 Batch (org.camunda.bpm.engine.batch.Batch)3 Job (org.camunda.bpm.engine.runtime.Job)3 ExternalTask (org.camunda.bpm.engine.externaltask.ExternalTask)2 HistoricDecisionInstanceQuery (org.camunda.bpm.engine.history.HistoricDecisionInstanceQuery)2 HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)2 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)2 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)2 ArrayList (java.util.ArrayList)1 EmbeddedProcessApplication (org.camunda.bpm.application.impl.EmbeddedProcessApplication)1 HistoryService (org.camunda.bpm.engine.HistoryService)1