Search in sources :

Example 16 with CommandContext

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

the class DatabaseTableSchemaTest method testTablePresentWithSchemaAndPrefix.

public void testTablePresentWithSchemaAndPrefix() throws SQLException {
    PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), "org.h2.Driver", "jdbc:h2:mem:DatabaseTablePrefixTest;DB_CLOSE_DELAY=1000", "sa", "");
    Connection connection = pooledDataSource.getConnection();
    connection.createStatement().execute("drop schema if exists " + SCHEMA_NAME);
    connection.createStatement().execute("create schema " + SCHEMA_NAME);
    connection.createStatement().execute("create table " + SCHEMA_NAME + "." + PREFIX_NAME + "SOME_TABLE(id varchar(64));");
    connection.close();
    ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration().setProcessEngineName("DatabaseTablePrefixTest-engine1").setDataSource(pooledDataSource).setDatabaseSchemaUpdate("NO_CHECK");
    config1.setDatabaseTablePrefix(SCHEMA_NAME + "." + PREFIX_NAME);
    config1.setDatabaseSchema(SCHEMA_NAME);
    config1.setDbMetricsReporterActivate(false);
    ProcessEngine engine = config1.buildProcessEngine();
    CommandExecutor commandExecutor = config1.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            DbSqlSession sqlSession = commandContext.getSession(DbSqlSession.class);
            assertTrue(sqlSession.isTablePresent("SOME_TABLE"));
            return null;
        }
    });
    engine.close();
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) Connection(java.sql.Connection) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) DbSqlSession(org.camunda.bpm.engine.impl.db.sql.DbSqlSession)

Example 17 with CommandContext

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

the class CaseExecutionEntity method remove.

// delete/remove ///////////////////////////////////////////////////////
@SuppressWarnings({ "unchecked", "rawtypes" })
public void remove() {
    super.remove();
    for (VariableInstanceEntity variableInstance : variableStore.getVariables()) {
        invokeVariableLifecycleListenersDelete(variableInstance, this, Arrays.<VariableInstanceLifecycleListener<CoreVariableInstance>>asList((VariableInstanceLifecycleListener) VariableInstanceEntityPersistenceListener.INSTANCE));
        variableStore.removeVariable(variableInstance.getName());
    }
    CommandContext commandContext = Context.getCommandContext();
    for (CaseSentryPartEntity sentryPart : getCaseSentryParts()) {
        commandContext.getCaseSentryPartManager().deleteSentryPart(sentryPart);
    }
    // finally delete this execution
    commandContext.getCaseExecutionManager().deleteCaseExecution(this);
}
Also used : CoreVariableInstance(org.camunda.bpm.engine.impl.core.variable.CoreVariableInstance) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) VariableInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity) VariableInstanceLifecycleListener(org.camunda.bpm.engine.impl.core.variable.scope.VariableInstanceLifecycleListener)

Example 18 with CommandContext

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

the class HistoryCleanupBatch method performCleanup.

public void performCleanup() {
    final CommandContext commandContext = Context.getCommandContext();
    if (historicProcessInstanceIds.size() > 0) {
        commandContext.getHistoricProcessInstanceManager().deleteHistoricProcessInstanceByIds(historicProcessInstanceIds);
        recordValue(Metrics.HISTORY_CLEANUP_REMOVED_PROCESS_INSTANCES, historicProcessInstanceIds.size());
    }
    if (historicDecisionInstanceIds.size() > 0) {
        commandContext.getHistoricDecisionInstanceManager().deleteHistoricDecisionInstanceByIds(historicDecisionInstanceIds);
        recordValue(Metrics.HISTORY_CLEANUP_REMOVED_DECISION_INSTANCES, historicDecisionInstanceIds.size());
    }
    if (historicCaseInstanceIds.size() > 0) {
        commandContext.getHistoricCaseInstanceManager().deleteHistoricCaseInstancesByIds(historicCaseInstanceIds);
        recordValue(Metrics.HISTORY_CLEANUP_REMOVED_CASE_INSTANCES, historicCaseInstanceIds.size());
    }
    if (historicBatchIds.size() > 0) {
        commandContext.getHistoricBatchManager().deleteHistoricBatchesByIds(historicBatchIds);
        recordValue(Metrics.HISTORY_CLEANUP_REMOVED_BATCH_OPERATIONS, historicBatchIds.size());
    }
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext)

Example 19 with CommandContext

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

the class MigratingInstanceParser method parse.

public MigratingProcessInstance parse(String processInstanceId, MigrationPlan migrationPlan, MigratingProcessInstanceValidationReportImpl processInstanceReport) {
    CommandContext commandContext = Context.getCommandContext();
    List<EventSubscriptionEntity> eventSubscriptions = fetchEventSubscriptions(commandContext, processInstanceId);
    List<ExecutionEntity> executions = fetchExecutions(commandContext, processInstanceId);
    List<ExternalTaskEntity> externalTasks = fetchExternalTasks(commandContext, processInstanceId);
    List<IncidentEntity> incidents = fetchIncidents(commandContext, processInstanceId);
    List<JobEntity> jobs = fetchJobs(commandContext, processInstanceId);
    List<TaskEntity> tasks = fetchTasks(commandContext, processInstanceId);
    List<VariableInstanceEntity> variables = fetchVariables(commandContext, processInstanceId);
    ExecutionEntity processInstance = commandContext.getExecutionManager().findExecutionById(processInstanceId);
    processInstance.restoreProcessInstance(executions, eventSubscriptions, variables, tasks, jobs, incidents, externalTasks);
    ProcessDefinitionEntity targetProcessDefinition = Context.getProcessEngineConfiguration().getDeploymentCache().findDeployedProcessDefinitionById(migrationPlan.getTargetProcessDefinitionId());
    List<JobDefinitionEntity> targetJobDefinitions = fetchJobDefinitions(commandContext, targetProcessDefinition.getId());
    final MigratingInstanceParseContext parseContext = new MigratingInstanceParseContext(this, migrationPlan, processInstance, targetProcessDefinition).eventSubscriptions(eventSubscriptions).externalTasks(externalTasks).incidents(incidents).jobs(jobs).tasks(tasks).targetJobDefinitions(targetJobDefinitions).variables(variables);
    ActivityInstance activityInstance = engine.getRuntimeService().getActivityInstance(processInstanceId);
    ActivityInstanceWalker activityInstanceWalker = new ActivityInstanceWalker(activityInstance);
    activityInstanceWalker.addPreVisitor(new TreeVisitor<ActivityInstance>() {

        @Override
        public void visit(ActivityInstance obj) {
            activityInstanceHandler.handle(parseContext, obj);
        }
    });
    activityInstanceWalker.walkWhile();
    CompensationEventSubscriptionWalker compensateSubscriptionsWalker = new CompensationEventSubscriptionWalker(parseContext.getMigratingActivityInstances());
    compensateSubscriptionsWalker.addPreVisitor(new TreeVisitor<EventSubscriptionEntity>() {

        @Override
        public void visit(EventSubscriptionEntity obj) {
            compensationInstanceHandler.handle(parseContext, obj);
        }
    });
    compensateSubscriptionsWalker.walkWhile();
    for (IncidentEntity incidentEntity : incidents) {
        incidentHandler.handle(parseContext, incidentEntity);
    }
    parseContext.validateNoEntitiesLeft(processInstanceReport);
    return parseContext.getMigratingProcessInstance();
}
Also used : ExternalTaskEntity(org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity) TaskEntity(org.camunda.bpm.engine.impl.persistence.entity.TaskEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) MigratingActivityInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) VariableInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity) JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity) IncidentEntity(org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity) ExternalTaskEntity(org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity) JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 20 with CommandContext

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

the class StatisticsManager method checkReadDecisionRequirementsDefinition.

protected void checkReadDecisionRequirementsDefinition(HistoricDecisionInstanceStatisticsQueryImpl query) {
    CommandContext commandContext = getCommandContext();
    if (isAuthorizationEnabled() && getCurrentAuthentication() != null && commandContext.isAuthorizationCheckEnabled()) {
        String decisionRequirementsDefinitionId = query.getDecisionRequirementsDefinitionId();
        DecisionRequirementsDefinition definition = getDecisionRequirementsDefinitionManager().findDecisionRequirementsDefinitionById(decisionRequirementsDefinitionId);
        ensureNotNull("no deployed decision requirements definition found with id '" + decisionRequirementsDefinitionId + "'", "decisionRequirementsDefinition", definition);
        getAuthorizationManager().checkAuthorization(READ, DECISION_REQUIREMENTS_DEFINITION, definition.getKey());
    }
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) DecisionRequirementsDefinition(org.camunda.bpm.engine.repository.DecisionRequirementsDefinition)

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