Search in sources :

Example 6 with HistoricProcessInstanceQueryDto

use of org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto in project camunda-bpm-platform by camunda.

the class ExternalTaskRestServiceInteractionTest method testSetRetriesForExternalTasksAsyncWithHistoricProcessInstanceQuery.

@Test
public void testSetRetriesForExternalTasksAsyncWithHistoricProcessInstanceQuery() {
    when(historyServiceMock.createHistoricProcessInstanceQuery()).thenReturn(new HistoricProcessInstanceQueryImpl());
    HistoricProcessInstanceQueryDto query = new HistoricProcessInstanceQueryDto();
    query.setProcessDefinitionId(EXAMPLE_PROCESS_DEFINITION_ID);
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("retries", "5");
    parameters.put("historicProcessInstanceQuery", query);
    given().contentType(POST_JSON_CONTENT_TYPE).body(parameters).then().expect().statusCode(Status.OK.getStatusCode()).when().post(RETRIES_EXTERNAL_TASKS_ASYNC_URL);
    ArgumentCaptor<HistoricProcessInstanceQuery> queryCapture = ArgumentCaptor.forClass(HistoricProcessInstanceQuery.class);
    verify(externalTaskService).updateRetries();
    verifyNoMoreInteractions(externalTaskService);
    verify(updateRetriesBuilder).externalTaskIds((List<String>) null);
    verify(updateRetriesBuilder).processInstanceIds((List<String>) null);
    verify(updateRetriesBuilder).externalTaskQuery(null);
    verify(updateRetriesBuilder).processInstanceQuery(null);
    verify(updateRetriesBuilder).historicProcessInstanceQuery(queryCapture.capture());
    verify(updateRetriesBuilder).setAsync(5);
    verifyNoMoreInteractions(updateRetriesBuilder);
    HistoricProcessInstanceQueryImpl actualQuery = (HistoricProcessInstanceQueryImpl) queryCapture.getValue();
    assertThat(actualQuery).isNotNull();
    assertThat(actualQuery.getProcessDefinitionId()).isEqualTo(EXAMPLE_PROCESS_DEFINITION_ID);
}
Also used : HistoricProcessInstanceQueryDto(org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto) HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) HistoricProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl) Test(org.junit.Test)

Example 7 with HistoricProcessInstanceQueryDto

use of org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto in project camunda-bpm-platform by camunda.

the class HistoricProcessInstanceRestServiceInteractionTest method testDeleteAsyncWithQuery.

@Test
public void testDeleteAsyncWithQuery() {
    Batch batchEntity = MockProvider.createMockBatch();
    when(historyServiceMock.deleteHistoricProcessInstancesAsync(anyListOf(String.class), any(HistoricProcessInstanceQuery.class), anyString())).thenReturn(batchEntity);
    Map<String, Object> messageBodyJson = new HashMap<String, Object>();
    messageBodyJson.put(DELETE_REASON, TEST_DELETE_REASON);
    HistoricProcessInstanceQueryDto query = new HistoricProcessInstanceQueryDto();
    messageBodyJson.put("historicProcessInstanceQuery", query);
    Response response = given().contentType(ContentType.JSON).body(messageBodyJson).then().expect().statusCode(Status.OK.getStatusCode()).when().post(DELETE_HISTORIC_PROCESS_INSTANCES_ASYNC_URL);
    verifyBatchJson(response.asString());
    verify(historyServiceMock, times(1)).deleteHistoricProcessInstancesAsync(eq((List<String>) null), any(HistoricProcessInstanceQuery.class), Mockito.eq(TEST_DELETE_REASON));
}
Also used : Response(com.jayway.restassured.response.Response) HistoricProcessInstanceQueryDto(org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto) HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) Batch(org.camunda.bpm.engine.batch.Batch) HashMap(java.util.HashMap) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 8 with HistoricProcessInstanceQueryDto

use of org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto in project camunda-bpm-platform by camunda.

the class ExternalTaskRestServiceInteractionTest method testSetRetriesWithHistoricProcessInstanceQuery.

@Test
public void testSetRetriesWithHistoricProcessInstanceQuery() {
    when(historyServiceMock.createHistoricProcessInstanceQuery()).thenReturn(new HistoricProcessInstanceQueryImpl());
    HistoricProcessInstanceQueryDto query = new HistoricProcessInstanceQueryDto();
    query.setProcessDefinitionId(EXAMPLE_PROCESS_DEFINITION_ID);
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("retries", "5");
    parameters.put("historicProcessInstanceQuery", query);
    given().contentType(POST_JSON_CONTENT_TYPE).body(parameters).then().expect().statusCode(Status.NO_CONTENT.getStatusCode()).when().put(RETRIES_EXTERNAL_TASK_SYNC_URL);
    ArgumentCaptor<HistoricProcessInstanceQuery> queryCapture = ArgumentCaptor.forClass(HistoricProcessInstanceQuery.class);
    verify(externalTaskService).updateRetries();
    verifyNoMoreInteractions(externalTaskService);
    verify(updateRetriesBuilder).externalTaskIds((List<String>) null);
    verify(updateRetriesBuilder).processInstanceIds((List<String>) null);
    verify(updateRetriesBuilder).externalTaskQuery(null);
    verify(updateRetriesBuilder).processInstanceQuery(null);
    verify(updateRetriesBuilder).historicProcessInstanceQuery(queryCapture.capture());
    verify(updateRetriesBuilder).set(5);
    verifyNoMoreInteractions(updateRetriesBuilder);
    HistoricProcessInstanceQueryImpl actualQuery = (HistoricProcessInstanceQueryImpl) queryCapture.getValue();
    assertThat(actualQuery).isNotNull();
    assertThat(actualQuery.getProcessDefinitionId()).isEqualTo(EXAMPLE_PROCESS_DEFINITION_ID);
}
Also used : HistoricProcessInstanceQueryDto(org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto) HistoricProcessInstanceQuery(org.camunda.bpm.engine.history.HistoricProcessInstanceQuery) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) HistoricProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl) Test(org.junit.Test)

Example 9 with HistoricProcessInstanceQueryDto

use of org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto 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 10 with HistoricProcessInstanceQueryDto

use of org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto 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)

Aggregations

HistoricProcessInstanceQueryDto (org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto)20 Test (org.junit.Test)17 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)14 HashMap (java.util.HashMap)12 Matchers.anyString (org.mockito.Matchers.anyString)9 ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)8 ArrayList (java.util.ArrayList)7 Batch (org.camunda.bpm.engine.batch.Batch)7 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)7 HistoricProcessInstanceQueryImpl (org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl)6 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)5 Response (com.jayway.restassured.response.Response)4 Map (java.util.Map)4 List (java.util.List)3 SetJobRetriesByProcessDto (org.camunda.bpm.engine.rest.dto.runtime.SetJobRetriesByProcessDto)3 ExampleVariableObject (org.camunda.bpm.engine.rest.helper.ExampleVariableObject)3 BatchEntity (org.camunda.bpm.engine.impl.batch.BatchEntity)2 DeleteProcessInstancesDto (org.camunda.bpm.engine.rest.dto.runtime.batch.DeleteProcessInstancesDto)2 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)2 JobQuery (org.camunda.bpm.engine.runtime.JobQuery)2