Search in sources :

Example 6 with HistoricProcessInstanceQueryImpl

use of org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl in project camunda-bpm-platform by camunda.

the class AbstractSetExternalTaskRetriesCmd method collectProcessInstanceIds.

protected List<String> collectProcessInstanceIds() {
    Set<String> collectedProcessInstanceIds = new HashSet<String>();
    List<String> processInstanceIds = builder.getProcessInstanceIds();
    if (processInstanceIds != null && !processInstanceIds.isEmpty()) {
        collectedProcessInstanceIds.addAll(processInstanceIds);
    }
    ProcessInstanceQueryImpl processInstanceQuery = (ProcessInstanceQueryImpl) builder.getProcessInstanceQuery();
    if (processInstanceQuery != null) {
        collectedProcessInstanceIds.addAll(processInstanceQuery.listIds());
    }
    HistoricProcessInstanceQueryImpl historicProcessInstanceQuery = (HistoricProcessInstanceQueryImpl) builder.getHistoricProcessInstanceQuery();
    if (historicProcessInstanceQuery != null) {
        collectedProcessInstanceIds.addAll(historicProcessInstanceQuery.listIds());
    }
    return new ArrayList<String>(collectedProcessInstanceIds);
}
Also used : ArrayList(java.util.ArrayList) HistoricProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl) ProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.ProcessInstanceQueryImpl) HashSet(java.util.HashSet) HistoricProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl)

Example 7 with HistoricProcessInstanceQueryImpl

use of org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl in project camunda-bpm-platform by camunda.

the class DeleteHistoricProcessInstancesBatchCmd method collectHistoricProcessInstanceIds.

protected List<String> collectHistoricProcessInstanceIds() {
    Set<String> collectedProcessInstanceIds = new HashSet<String>();
    List<String> processInstanceIds = this.getHistoricProcessInstanceIds();
    if (processInstanceIds != null) {
        collectedProcessInstanceIds.addAll(processInstanceIds);
    }
    final HistoricProcessInstanceQueryImpl processInstanceQuery = (HistoricProcessInstanceQueryImpl) this.historicProcessInstanceQuery;
    if (processInstanceQuery != null) {
        for (HistoricProcessInstance hpi : processInstanceQuery.list()) {
            collectedProcessInstanceIds.add(hpi.getId());
        }
    }
    return new ArrayList<String>(collectedProcessInstanceIds);
}
Also used : HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HistoricProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl)

Example 8 with HistoricProcessInstanceQueryImpl

use of org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl 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 HistoricProcessInstanceQueryImpl

use of org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl in project camunda-bpm-platform by camunda.

the class AbstractRestartProcessInstanceCmd method collectProcessInstanceIds.

protected Collection<String> collectProcessInstanceIds() {
    Set<String> collectedProcessInstanceIds = new HashSet<String>();
    List<String> processInstanceIds = builder.getProcessInstanceIds();
    if (processInstanceIds != null) {
        collectedProcessInstanceIds.addAll(processInstanceIds);
    }
    final HistoricProcessInstanceQueryImpl historicProcessInstanceQuery = (HistoricProcessInstanceQueryImpl) builder.getHistoricProcessInstanceQuery();
    if (historicProcessInstanceQuery != null) {
        collectedProcessInstanceIds.addAll(historicProcessInstanceQuery.listIds());
    }
    EnsureUtil.ensureNotEmpty(BadUserRequestException.class, "processInstanceIds", collectedProcessInstanceIds);
    return collectedProcessInstanceIds;
}
Also used : HashSet(java.util.HashSet) HistoricProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl)

Example 10 with HistoricProcessInstanceQueryImpl

use of org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl in project camunda-bpm-platform by camunda.

the class DeleteHistoricProcessInstancesCmd method execute.

@Override
public Void execute(CommandContext commandContext) {
    ensureNotEmpty(BadUserRequestException.class, "processInstanceIds", processInstanceIds);
    ensureNotContainsNull(BadUserRequestException.class, "processInstanceId is null", "processInstanceIds", processInstanceIds);
    // Check if process instance is still running
    List<HistoricProcessInstance> instances = commandContext.runWithoutAuthorization(new Callable<List<HistoricProcessInstance>>() {

        @Override
        public List<HistoricProcessInstance> call() throws Exception {
            return new HistoricProcessInstanceQueryImpl().processInstanceIds(new HashSet<String>(processInstanceIds)).list();
        }
    });
    if (processInstanceIds.size() == 1) {
        ensureNotEmpty(BadUserRequestException.class, "No historic process instance found with id: " + processInstanceIds.get(0), "historicProcessInstanceIds", instances);
    } else {
        ensureNotEmpty(BadUserRequestException.class, "No historic process instances found", "historicProcessInstanceIds", instances);
    }
    // check if all historicProcessInstances were found
    List<String> existingIds = new ArrayList<String>();
    for (HistoricProcessInstance historicProcessInstance : instances) {
        existingIds.add(historicProcessInstance.getId());
        for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
            checker.checkDeleteHistoricProcessInstance(historicProcessInstance);
        }
        ensureNotNull(BadUserRequestException.class, "Process instance is still running, cannot delete historic process instance: " + historicProcessInstance, "instance.getEndTime()", historicProcessInstance.getEndTime());
    }
    ArrayList<String> nonExistingIds = new ArrayList<String>(processInstanceIds);
    nonExistingIds.removeAll(existingIds);
    ensureNumberOfElements(BadUserRequestException.class, "No historic process instances found with ids " + nonExistingIds, "nonExistingIds", nonExistingIds, 0);
    commandContext.getHistoricProcessInstanceManager().deleteHistoricProcessInstanceByIds(processInstanceIds);
    return null;
}
Also used : HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) HistoricProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

HistoricProcessInstanceQueryImpl (org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl)11 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 HistoricProcessInstanceQueryDto (org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto)6 Test (org.junit.Test)6 Matchers.anyString (org.mockito.Matchers.anyString)6 HashSet (java.util.HashSet)4 Map (java.util.Map)4 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)2 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)2 ProcessInstanceQueryImpl (org.camunda.bpm.engine.impl.ProcessInstanceQueryImpl)2 List (java.util.List)1 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)1 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)1