Search in sources :

Example 71 with CommandContext

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

the class ExecutionCachedEntityStateTest method testExecutionIncidentParallel.

@Deployment
public void testExecutionIncidentParallel() {
    runtimeService.startProcessInstanceByKey("testProcess");
    ExecutionEntity processInstance = (ExecutionEntity) runtimeService.createProcessInstanceQuery().singleResult();
    assertEquals(0, processInstance.getCachedEntityStateRaw());
    final ExecutionEntity execution = (ExecutionEntity) runtimeService.createExecutionQuery().activityId("task").singleResult();
    assertEquals(0, execution.getCachedEntityStateRaw());
    processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            IncidentContext incidentContext = new IncidentContext();
            incidentContext.setExecutionId(execution.getId());
            IncidentEntity.createAndInsertIncident("foo", incidentContext, null);
            return null;
        }
    });
    ExecutionEntity execution2 = (ExecutionEntity) runtimeService.createExecutionQuery().activityId("task").singleResult();
    assertEquals(BitMaskUtil.getMaskForBit(ExecutionEntity.INCIDENT_STATE_BIT), execution2.getCachedEntityStateRaw());
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) IncidentContext(org.camunda.bpm.engine.impl.incident.IncidentContext) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 72 with CommandContext

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

the class CaseDefinitionEntity method loadCaseDefinition.

/**
 * Returns the cached version if exists; does not update the entity from the database in that case
 */
protected CaseDefinitionEntity loadCaseDefinition(String caseDefinitionId) {
    ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration();
    DeploymentCache deploymentCache = configuration.getDeploymentCache();
    CaseDefinitionEntity caseDefinition = deploymentCache.findCaseDefinitionFromCache(caseDefinitionId);
    if (caseDefinition == null) {
        CommandContext commandContext = Context.getCommandContext();
        CaseDefinitionManager caseDefinitionManager = commandContext.getCaseDefinitionManager();
        caseDefinition = caseDefinitionManager.findCaseDefinitionById(caseDefinitionId);
        if (caseDefinition != null) {
            caseDefinition = deploymentCache.resolveCaseDefinition(caseDefinition);
        }
    }
    return caseDefinition;
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) DeploymentCache(org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)

Example 73 with CommandContext

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

the class CaseExecutionManager method deleteCaseInstance.

public void deleteCaseInstance(String caseInstanceId, String deleteReason, boolean cascade) {
    CaseExecutionEntity execution = findCaseExecutionById(caseInstanceId);
    if (execution == null) {
        throw new BadUserRequestException("No case instance found for id '" + caseInstanceId + "'");
    }
    CommandContext commandContext = Context.getCommandContext();
    commandContext.getTaskManager().deleteTasksByCaseInstanceId(caseInstanceId, deleteReason, cascade);
    execution.deleteCascade();
    if (cascade) {
        Context.getCommandContext().getHistoricCaseInstanceManager().deleteHistoricCaseInstancesByIds(Arrays.asList(caseInstanceId));
    }
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException)

Example 74 with CommandContext

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

the class FailedJobListener method fireHistoricJobFailedEvt.

protected void fireHistoricJobFailedEvt(JobEntity job) {
    CommandContext commandContext = Context.getCommandContext();
    // the given job failed and a rollback happened,
    // that's why we have to increment the job
    // sequence counter once again
    job.incrementSequenceCounter();
    commandContext.getHistoricJobLogManager().fireJobFailedEvent(job, exception);
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext)

Example 75 with CommandContext

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

the class StatisticsManager method checkReadProcessDefinition.

protected void checkReadProcessDefinition(ActivityStatisticsQueryImpl query) {
    CommandContext commandContext = getCommandContext();
    if (isAuthorizationEnabled() && getCurrentAuthentication() != null && commandContext.isAuthorizationCheckEnabled()) {
        String processDefinitionId = query.getProcessDefinitionId();
        ProcessDefinitionEntity definition = getProcessDefinitionManager().findLatestProcessDefinitionById(processDefinitionId);
        ensureNotNull("no deployed process definition found with id '" + processDefinitionId + "'", "processDefinition", definition);
        getAuthorizationManager().checkAuthorization(READ, PROCESS_DEFINITION, definition.getKey());
    }
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext)

Aggregations

CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)120 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)31 List (java.util.List)17 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)17 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)11 Deployment (org.camunda.bpm.engine.test.Deployment)11 ArrayList (java.util.ArrayList)10 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)10 Date (java.util.Date)9 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)8 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)8 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)8 Command (org.camunda.bpm.engine.impl.interceptor.Command)6 HistoricIncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity)6 After (org.junit.After)6 ProcessApplicationReference (org.camunda.bpm.application.ProcessApplicationReference)5 RepositoryService (org.camunda.bpm.engine.RepositoryService)5 ProcessEngineImpl (org.camunda.bpm.engine.impl.ProcessEngineImpl)5 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)5 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)4