Search in sources :

Example 61 with HistoricProcessInstance

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

the class ProcessInstanceRestServiceImpl method setRetriesByProcessHistoricQueryBased.

@Override
public BatchDto setRetriesByProcessHistoricQueryBased(SetJobRetriesByProcessDto setJobRetriesDto) {
    List<String> processInstanceIds = new ArrayList<String>();
    HistoricProcessInstanceQueryDto queryDto = setJobRetriesDto.getHistoricProcessInstanceQuery();
    if (queryDto != null) {
        HistoricProcessInstanceQuery query = queryDto.toQuery(getProcessEngine());
        List<HistoricProcessInstance> historicProcessInstances = query.list();
        for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
            processInstanceIds.add(historicProcessInstance.getId());
        }
    }
    if (setJobRetriesDto.getProcessInstances() != null) {
        processInstanceIds.addAll(setJobRetriesDto.getProcessInstances());
    }
    try {
        ManagementService managementService = getProcessEngine().getManagementService();
        Batch batch = managementService.setJobRetriesAsync(processInstanceIds, (ProcessInstanceQuery) null, setJobRetriesDto.getRetries());
        return BatchDto.fromBatch(batch);
    } catch (BadUserRequestException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
    }
}
Also used : HistoricProcessInstanceQueryDto(org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto) ManagementService(org.camunda.bpm.engine.ManagementService) HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) Batch(org.camunda.bpm.engine.batch.Batch) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException)

Example 62 with HistoricProcessInstance

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

the class ProcessInstanceRestServiceImpl method deleteAsyncHistoricQueryBased.

@Override
public BatchDto deleteAsyncHistoricQueryBased(DeleteProcessInstancesDto deleteProcessInstancesDto) {
    List<String> processInstanceIds = new ArrayList<String>();
    HistoricProcessInstanceQueryDto queryDto = deleteProcessInstancesDto.getHistoricProcessInstanceQuery();
    if (queryDto != null) {
        HistoricProcessInstanceQuery query = queryDto.toQuery(getProcessEngine());
        List<HistoricProcessInstance> historicProcessInstances = query.list();
        for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
            processInstanceIds.add(historicProcessInstance.getId());
        }
    }
    if (deleteProcessInstancesDto.getProcessInstanceIds() != null) {
        processInstanceIds.addAll(deleteProcessInstancesDto.getProcessInstanceIds());
    }
    try {
        RuntimeService runtimeService = getProcessEngine().getRuntimeService();
        Batch batch = runtimeService.deleteProcessInstancesAsync(processInstanceIds, null, deleteProcessInstancesDto.getDeleteReason(), deleteProcessInstancesDto.isSkipCustomListeners(), deleteProcessInstancesDto.isSkipSubprocesses());
        return BatchDto.fromBatch(batch);
    } catch (BadUserRequestException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
    }
}
Also used : HistoricProcessInstanceQueryDto(org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto) HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) RuntimeService(org.camunda.bpm.engine.RuntimeService) Batch(org.camunda.bpm.engine.batch.Batch) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException)

Example 63 with HistoricProcessInstance

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

the class HistoricProcessInstanceResourceImpl method getHistoricProcessInstance.

@Override
public HistoricProcessInstanceDto getHistoricProcessInstance() {
    HistoryService historyService = engine.getHistoryService();
    HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    if (instance == null) {
        throw new InvalidRequestException(Status.NOT_FOUND, "Historic process instance with id " + processInstanceId + " does not exist");
    }
    return HistoricProcessInstanceDto.fromHistoricProcessInstance(instance);
}
Also used : HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) HistoryService(org.camunda.bpm.engine.HistoryService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 64 with HistoricProcessInstance

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

the class RestartProcessInstancesCmd method execute.

@Override
public Void execute(final CommandContext commandContext) {
    final Collection<String> processInstanceIds = collectProcessInstanceIds();
    final List<AbstractProcessInstanceModificationCommand> instructions = builder.getInstructions();
    ensureNotEmpty(BadUserRequestException.class, "Restart instructions cannot be empty", "instructions", instructions);
    ensureNotEmpty(BadUserRequestException.class, "Process instance ids cannot be empty", "Process instance ids", processInstanceIds);
    ensureNotContainsNull(BadUserRequestException.class, "Process instance ids cannot be null", "Process instance ids", processInstanceIds);
    final ProcessDefinitionEntity processDefinition = getProcessDefinition(commandContext, builder.getProcessDefinitionId());
    ensureNotNull("Process definition cannot be found", "processDefinition", processDefinition);
    checkAuthorization(commandContext, processDefinition);
    if (writeUserOperationLog) {
        writeUserOperationLog(commandContext, processDefinition, processInstanceIds.size(), false);
    }
    final String processDefinitionId = builder.getProcessDefinitionId();
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            for (String processInstanceId : processInstanceIds) {
                HistoricProcessInstance historicProcessInstance = getHistoricProcessInstance(commandContext, processInstanceId);
                ensureNotNull(BadUserRequestException.class, "Historic process instance cannot be found", "historicProcessInstanceId", historicProcessInstance);
                ensureHistoricProcessInstanceNotActive(historicProcessInstance);
                ensureSameProcessDefinition(historicProcessInstance, processDefinitionId);
                ProcessInstantiationBuilderImpl instantiationBuilder = getProcessInstantiationBuilder(commandExecutor, processDefinitionId);
                applyProperties(instantiationBuilder, processDefinition, historicProcessInstance);
                ProcessInstanceModificationBuilderImpl modificationBuilder = instantiationBuilder.getModificationBuilder();
                modificationBuilder.setModificationOperations(instructions);
                VariableMap variables = collectVariables(commandContext, historicProcessInstance);
                instantiationBuilder.setVariables(variables);
                instantiationBuilder.execute(builder.isSkipCustomListeners(), builder.isSkipIoMappings());
            }
        }
    };
    ProcessApplicationContextUtil.doContextSwitch(runnable, processDefinition);
    return null;
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstantiationBuilderImpl(org.camunda.bpm.engine.impl.ProcessInstantiationBuilderImpl) ProcessInstanceModificationBuilderImpl(org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 65 with HistoricProcessInstance

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

the class MigrationIncidentTest method historicIncidentRemainsOpenAfterMigration.

@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL)
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/migration/calledProcess.bpmn", "org/camunda/bpm/engine/test/api/runtime/migration/calledProcess_v2.bpmn" })
public void historicIncidentRemainsOpenAfterMigration() {
    // Given we create a new process instance
    ProcessDefinition process1 = engineRule.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("calledProcess").singleResult();
    ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceById(process1.getId());
    LockedExternalTask task = engineRule.getExternalTaskService().fetchAndLock(1, "foo").topic("foo", 1000L).execute().get(0);
    engineRule.getExternalTaskService().handleFailure(task.getId(), "foo", "error", 0, 1000L);
    Incident incidentInProcess = engineRule.getRuntimeService().createIncidentQuery().processDefinitionId(process1.getId()).singleResult();
    // when
    ProcessDefinition process2 = engineRule.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("calledProcessV2").singleResult();
    MigrationPlan migrationPlan = engineRule.getRuntimeService().createMigrationPlan(process1.getId(), process2.getId()).mapEqualActivities().mapActivities("ServiceTask_1p58ywb", "ServiceTask_V2").build();
    engineRule.getRuntimeService().newMigration(migrationPlan).processInstanceIds(processInstance.getId()).execute();
    // then
    HistoricIncident historicIncidentAfterMigration = engineRule.getHistoryService().createHistoricIncidentQuery().singleResult();
    assertNotNull(historicIncidentAfterMigration);
    assertNull(historicIncidentAfterMigration.getEndTime());
    assertTrue(historicIncidentAfterMigration.isOpen());
    HistoricProcessInstance historicProcessInstanceAfterMigration = engineRule.getHistoryService().createHistoricProcessInstanceQuery().withIncidents().incidentStatus("open").singleResult();
    assertNotNull(historicProcessInstanceAfterMigration);
    Incident incidentAfterMigration = engineRule.getRuntimeService().createIncidentQuery().incidentId(incidentInProcess.getId()).singleResult();
    assertEquals(process2.getId(), incidentAfterMigration.getProcessDefinitionId());
    assertEquals("ServiceTask_V2", incidentAfterMigration.getActivityId());
}
Also used : HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) Incident(org.camunda.bpm.engine.runtime.Incident) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Aggregations

HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)113 Deployment (org.camunda.bpm.engine.test.Deployment)46 Test (org.junit.Test)37 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)36 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)25 Task (org.camunda.bpm.engine.task.Task)19 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)18 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)17 ArrayList (java.util.ArrayList)15 Calendar (java.util.Calendar)12 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)12 GregorianCalendar (java.util.GregorianCalendar)11 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)9 RequiredHistoryLevel (org.camunda.bpm.engine.test.RequiredHistoryLevel)9 HistoricProcessInstanceQueryDto (org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto)7 List (java.util.List)5 ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)5 Response (com.jayway.restassured.response.Response)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4