Search in sources :

Example 1 with BatchQuery

use of org.camunda.bpm.engine.batch.BatchQuery in project camunda-bpm-platform by camunda.

the class BatchRestServiceImpl method getBatches.

public List<BatchDto> getBatches(UriInfo uriInfo, Integer firstResult, Integer maxResults) {
    BatchQueryDto queryDto = new BatchQueryDto(getObjectMapper(), uriInfo.getQueryParameters());
    BatchQuery query = queryDto.toQuery(getProcessEngine());
    List<Batch> matchingBatches;
    if (firstResult != null || maxResults != null) {
        matchingBatches = executePaginatedQuery(query, firstResult, maxResults);
    } else {
        matchingBatches = query.list();
    }
    List<BatchDto> batchResults = new ArrayList<BatchDto>();
    for (Batch matchingBatch : matchingBatches) {
        batchResults.add(BatchDto.fromBatch(matchingBatch));
    }
    return batchResults;
}
Also used : Batch(org.camunda.bpm.engine.batch.Batch) ArrayList(java.util.ArrayList) BatchDto(org.camunda.bpm.engine.rest.dto.batch.BatchDto) BatchQuery(org.camunda.bpm.engine.batch.BatchQuery) BatchQueryDto(org.camunda.bpm.engine.rest.dto.batch.BatchQueryDto)

Example 2 with BatchQuery

use of org.camunda.bpm.engine.batch.BatchQuery in project camunda-bpm-platform by camunda.

the class BatchRestServiceImpl method getBatchesCount.

public CountResultDto getBatchesCount(UriInfo uriInfo) {
    ProcessEngine processEngine = getProcessEngine();
    BatchQueryDto queryDto = new BatchQueryDto(getObjectMapper(), uriInfo.getQueryParameters());
    BatchQuery query = queryDto.toQuery(processEngine);
    long count = query.count();
    return new CountResultDto(count);
}
Also used : CountResultDto(org.camunda.bpm.engine.rest.dto.CountResultDto) BatchQuery(org.camunda.bpm.engine.batch.BatchQuery) BatchQueryDto(org.camunda.bpm.engine.rest.dto.batch.BatchQueryDto) ProcessEngine(org.camunda.bpm.engine.ProcessEngine)

Example 3 with BatchQuery

use of org.camunda.bpm.engine.batch.BatchQuery in project camunda-bpm-platform by camunda.

the class BatchQueryTest method testBatchQueryBySuspendedBatches.

@Test
public void testBatchQueryBySuspendedBatches() {
    // given
    Batch batch1 = helper.migrateProcessInstancesAsync(1);
    Batch batch2 = helper.migrateProcessInstancesAsync(1);
    helper.migrateProcessInstancesAsync(1);
    // when
    managementService.suspendBatchById(batch1.getId());
    managementService.suspendBatchById(batch2.getId());
    managementService.activateBatchById(batch1.getId());
    // then
    BatchQuery query = managementService.createBatchQuery().suspended();
    Assert.assertEquals(1, query.count());
    Assert.assertEquals(1, query.list().size());
    Assert.assertEquals(batch2.getId(), query.singleResult().getId());
}
Also used : Batch(org.camunda.bpm.engine.batch.Batch) BatchQuery(org.camunda.bpm.engine.batch.BatchQuery) Test(org.junit.Test)

Example 4 with BatchQuery

use of org.camunda.bpm.engine.batch.BatchQuery in project camunda-bpm-platform by camunda.

the class BatchRestServiceInteractionTest method testGetNonExistingBatch.

@Test
public void testGetNonExistingBatch() {
    String nonExistingId = MockProvider.NON_EXISTING_ID;
    BatchQuery batchQuery = mock(BatchQuery.class);
    when(batchQuery.batchId(nonExistingId)).thenReturn(batchQuery);
    when(batchQuery.singleResult()).thenReturn(null);
    when(managementServiceMock.createBatchQuery()).thenReturn(batchQuery);
    given().pathParam("id", nonExistingId).then().expect().statusCode(Status.NOT_FOUND.getStatusCode()).body("type", equalTo(InvalidRequestException.class.getSimpleName())).body("message", equalTo("Batch with id '" + nonExistingId + "' does not exist")).when().get(SINGLE_BATCH_RESOURCE_URL);
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) BatchQuery(org.camunda.bpm.engine.batch.BatchQuery) Test(org.junit.Test)

Example 5 with BatchQuery

use of org.camunda.bpm.engine.batch.BatchQuery in project camunda-bpm-platform by camunda.

the class BatchQueryTest method testBatchQueryByActiveBatches.

@Test
public void testBatchQueryByActiveBatches() {
    // given
    Batch batch1 = helper.migrateProcessInstancesAsync(1);
    Batch batch2 = helper.migrateProcessInstancesAsync(1);
    Batch batch3 = helper.migrateProcessInstancesAsync(1);
    // when
    managementService.suspendBatchById(batch1.getId());
    managementService.suspendBatchById(batch2.getId());
    managementService.activateBatchById(batch1.getId());
    // then
    BatchQuery query = managementService.createBatchQuery().active();
    Assert.assertEquals(2, query.count());
    Assert.assertEquals(2, query.list().size());
    List<String> foundIds = new ArrayList<String>();
    for (Batch batch : query.list()) {
        foundIds.add(batch.getId());
    }
    Assert.assertThat(foundIds, hasItems(batch1.getId(), batch3.getId()));
}
Also used : Batch(org.camunda.bpm.engine.batch.Batch) ArrayList(java.util.ArrayList) BatchQuery(org.camunda.bpm.engine.batch.BatchQuery) Test(org.junit.Test)

Aggregations

BatchQuery (org.camunda.bpm.engine.batch.BatchQuery)5 Batch (org.camunda.bpm.engine.batch.Batch)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 BatchQueryDto (org.camunda.bpm.engine.rest.dto.batch.BatchQueryDto)2 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)1 CountResultDto (org.camunda.bpm.engine.rest.dto.CountResultDto)1 BatchDto (org.camunda.bpm.engine.rest.dto.batch.BatchDto)1 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)1