Search in sources :

Example 6 with ProcessInstanceQueryImpl

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

the class AbstractModificationCmd method collectProcessInstanceIds.

protected Collection<String> collectProcessInstanceIds(CommandContext commandContext) {
    Set<String> collectedProcessInstanceIds = new HashSet<String>();
    List<String> processInstanceIds = builder.getProcessInstanceIds();
    if (processInstanceIds != null) {
        collectedProcessInstanceIds.addAll(processInstanceIds);
    }
    final ProcessInstanceQueryImpl processInstanceQuery = (ProcessInstanceQueryImpl) builder.getProcessInstanceQuery();
    if (processInstanceQuery != null) {
        collectedProcessInstanceIds.addAll(processInstanceQuery.listIds());
    }
    return collectedProcessInstanceIds;
}
Also used : ProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.ProcessInstanceQueryImpl) HashSet(java.util.HashSet)

Example 7 with ProcessInstanceQueryImpl

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

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

the class AbstractMigrationCmd method collectProcessInstanceIds.

protected Collection<String> collectProcessInstanceIds(CommandContext commandContext) {
    Set<String> collectedProcessInstanceIds = new HashSet<String>();
    List<String> processInstanceIds = executionBuilder.getProcessInstanceIds();
    if (processInstanceIds != null) {
        collectedProcessInstanceIds.addAll(processInstanceIds);
    }
    final ProcessInstanceQueryImpl processInstanceQuery = (ProcessInstanceQueryImpl) executionBuilder.getProcessInstanceQuery();
    if (processInstanceQuery != null) {
        collectedProcessInstanceIds.addAll(processInstanceQuery.listIds());
    }
    return collectedProcessInstanceIds;
}
Also used : ProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.ProcessInstanceQueryImpl) HashSet(java.util.HashSet)

Example 9 with ProcessInstanceQueryImpl

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

the class ProcessDefinitionManager method deleteProcessDefinition.

/**
 * Deletes the given process definition from the database and cache.
 * If cascadeToHistory and cascadeToInstances is set to true it deletes
 * the history and the process instances.
 *
 * *Note*: If more than one process definition, from one deployment, is deleted in
 * a single transaction and the cascadeToHistory and cascadeToInstances flag was set to true it
 * can cause a dirty deployment cache. The process instances of ALL process definitions must be deleted,
 * before every process definition can be deleted! In such cases the cascadeToInstances flag
 * have to set to false!
 *
 * On deletion of all process instances, the task listeners will be deleted as well.
 * Deletion of tasks and listeners needs the redeployment of deployments.
 * It can cause to problems if is done sequential with the deletion of process definition
 * in a single transaction.
 *
 * *For example*:
 * Deployment contains two process definition. First process definition
 * and instances will be removed, also cleared from the cache.
 * Second process definition will be removed and his instances.
 * Deletion of instances will cause redeployment this deploys again
 * first into the cache. Only the second will be removed from cache and
 * first remains in the cache after the deletion process.
 *
 * @param processDefinition the process definition which should be deleted
 * @param processDefinitionId the id of the process definition
 * @param cascadeToHistory if true the history will deleted as well
 * @param cascadeToInstances if true the process instances are deleted as well
 * @param skipCustomListeners if true skips the custom listeners on deletion of instances
 */
public void deleteProcessDefinition(ProcessDefinition processDefinition, String processDefinitionId, boolean cascadeToHistory, boolean cascadeToInstances, boolean skipCustomListeners) {
    if (cascadeToHistory) {
        cascadeDeleteHistoryForProcessDefinition(processDefinitionId);
        if (cascadeToInstances) {
            cascadeDeleteProcessInstancesForProcessDefinition(processDefinitionId, skipCustomListeners);
        }
    } else {
        ProcessInstanceQueryImpl procInstQuery = new ProcessInstanceQueryImpl().processDefinitionId(processDefinitionId);
        long processInstanceCount = getProcessInstanceManager().findProcessInstanceCountByQueryCriteria(procInstQuery);
        if (processInstanceCount != 0) {
            throw LOG.deleteProcessDefinitionWithProcessInstancesException(processDefinitionId, processInstanceCount);
        }
    }
    // remove related authorization parameters in IdentityLink table
    getIdentityLinkManager().deleteIdentityLinksByProcDef(processDefinitionId);
    // remove timer start events:
    deleteTimerStartEventsForProcessDefinition(processDefinition);
    // delete process definition from database
    getDbEntityManager().delete(ProcessDefinitionEntity.class, "deleteProcessDefinitionsById", processDefinitionId);
    // remove process definition from cache:
    Context.getProcessEngineConfiguration().getDeploymentCache().removeProcessDefinition(processDefinitionId);
    deleteSubscriptionsForProcessDefinition(processDefinitionId);
    // delete job definitions
    getJobDefinitionManager().deleteJobDefinitionsByProcessDefinitionId(processDefinition.getId());
}
Also used : ProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.ProcessInstanceQueryImpl)

Example 10 with ProcessInstanceQueryImpl

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

the class DeleteProcessInstancesJobHandler method createJobs.

@Override
public boolean createJobs(BatchEntity batch) {
    DeleteProcessInstanceBatchConfiguration configuration = readConfiguration(batch.getConfigurationBytes());
    List<String> ids = configuration.getIds();
    final CommandContext commandContext = Context.getCommandContext();
    int batchJobsPerSeed = batch.getBatchJobsPerSeed();
    int invocationsPerBatchJob = batch.getInvocationsPerBatchJob();
    int numberOfItemsToProcess = Math.min(invocationsPerBatchJob * batchJobsPerSeed, ids.size());
    // view of process instances to process
    final List<String> processIds = ids.subList(0, numberOfItemsToProcess);
    List<String> deploymentIds = commandContext.runWithoutAuthorization(new Callable<List<String>>() {

        @Override
        public List<String> call() throws Exception {
            return commandContext.getDeploymentManager().findDeploymentIdsByProcessInstances(processIds);
        }
    });
    for (final String deploymentId : deploymentIds) {
        List<String> processIdsPerDeployment = commandContext.runWithoutAuthorization(new Callable<List<String>>() {

            @Override
            public List<String> call() throws Exception {
                final ProcessInstanceQueryImpl processInstanceQueryToBeProcess = new ProcessInstanceQueryImpl();
                processInstanceQueryToBeProcess.processInstanceIds(new HashSet<String>(processIds)).deploymentId(deploymentId);
                return commandContext.getExecutionManager().findProcessInstancesIdsByQueryCriteria(processInstanceQueryToBeProcess);
            }
        });
        processIds.removeAll(processIdsPerDeployment);
        createJobEntities(batch, configuration, deploymentId, processIdsPerDeployment, invocationsPerBatchJob);
    }
    // when there are non existing process instance ids
    if (!processIds.isEmpty()) {
        createJobEntities(batch, configuration, null, processIds, invocationsPerBatchJob);
    }
    return ids.isEmpty();
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) List(java.util.List) ProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.ProcessInstanceQueryImpl)

Aggregations

ProcessInstanceQueryImpl (org.camunda.bpm.engine.impl.ProcessInstanceQueryImpl)17 ProcessInstanceQueryDto (org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceQueryDto)8 Test (org.junit.Test)8 Matchers.anyString (org.mockito.Matchers.anyString)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)5 Map (java.util.Map)4 HistoricProcessInstanceQueryImpl (org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl)4 ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)3 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)2 HistoricProcessInstanceQueryDto (org.camunda.bpm.engine.rest.dto.history.HistoricProcessInstanceQueryDto)2 MigrationExecutionDtoBuilder (org.camunda.bpm.engine.rest.util.migration.MigrationExecutionDtoBuilder)2 List (java.util.List)1 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)1 Batch (org.camunda.bpm.engine.batch.Batch)1 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)1 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)1 MockProvider.createMockBatch (org.camunda.bpm.engine.rest.helper.MockProvider.createMockBatch)1 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1