Search in sources :

Example 41 with HistoricProcessInstanceQuery

use of org.camunda.bpm.engine.history.HistoricProcessInstanceQuery 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 42 with HistoricProcessInstanceQuery

use of org.camunda.bpm.engine.history.HistoricProcessInstanceQuery 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 43 with HistoricProcessInstanceQuery

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

the class HistoricProcessInstanceRestServiceImpl method deleteAsync.

@Override
public BatchDto deleteAsync(DeleteHistoricProcessInstancesDto dto) {
    HistoryService historyService = processEngine.getHistoryService();
    HistoricProcessInstanceQuery historicProcessInstanceQuery = null;
    if (dto.getHistoricProcessInstanceQuery() != null) {
        historicProcessInstanceQuery = dto.getHistoricProcessInstanceQuery().toQuery(processEngine);
    }
    try {
        Batch batch = historyService.deleteHistoricProcessInstancesAsync(dto.getHistoricProcessInstanceIds(), historicProcessInstanceQuery, dto.getDeleteReason());
        return BatchDto.fromBatch(batch);
    } catch (BadUserRequestException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
    }
}
Also used : HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) Batch(org.camunda.bpm.engine.batch.Batch) HistoryService(org.camunda.bpm.engine.HistoryService) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException)

Example 44 with HistoricProcessInstanceQuery

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

the class HistoricProcessInstanceRestServiceImpl method queryHistoricProcessInstancesCount.

@Override
public CountResultDto queryHistoricProcessInstancesCount(HistoricProcessInstanceQueryDto queryDto) {
    queryDto.setObjectMapper(objectMapper);
    HistoricProcessInstanceQuery query = queryDto.toQuery(processEngine);
    long count = query.count();
    CountResultDto result = new CountResultDto();
    result.setCount(count);
    return result;
}
Also used : HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) CountResultDto(org.camunda.bpm.engine.rest.dto.CountResultDto)

Example 45 with HistoricProcessInstanceQuery

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

the class MultiTenancyProcessInstantiationTest method testRestartProcessInstanceSyncWithTenantIdByHistoricProcessInstanceQuery.

@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL)
public void testRestartProcessInstanceSyncWithTenantIdByHistoricProcessInstanceQuery() {
    // given
    ProcessInstance processInstance = startAndDeleteProcessInstance(TENANT_ONE, PROCESS);
    HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().processDefinitionId(processInstance.getProcessDefinitionId());
    identityService.setAuthentication("user", null, Collections.singletonList(TENANT_ONE));
    // when
    runtimeService.restartProcessInstances(processInstance.getProcessDefinitionId()).startBeforeActivity("userTask").historicProcessInstanceQuery(query).execute();
    // then
    ProcessInstance restartedInstance = runtimeService.createProcessInstanceQuery().active().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult();
    assertNotNull(restartedInstance);
    assertEquals(restartedInstance.getTenantId(), TENANT_ONE);
}
Also used : HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Aggregations

HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)71 Test (org.junit.Test)29 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)25 Batch (org.camunda.bpm.engine.batch.Batch)16 HistoricProcessInstanceQueryDto (org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto)14 HashMap (java.util.HashMap)12 ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)11 Deployment (org.camunda.bpm.engine.test.Deployment)11 RequiredHistoryLevel (org.camunda.bpm.engine.test.RequiredHistoryLevel)10 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 Matchers.anyString (org.mockito.Matchers.anyString)8 ArrayList (java.util.ArrayList)7 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)7 Response (com.jayway.restassured.response.Response)6 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)6 HistoricBatch (org.camunda.bpm.engine.batch.history.HistoricBatch)6 ExternalTask (org.camunda.bpm.engine.externaltask.ExternalTask)4 HistoricProcessInstanceQueryImpl (org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl)4 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)4