Search in sources :

Example 21 with ProcessEngineConfigurationImpl

use of org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl in project Activiti by Activiti.

the class DefaultHistoryManager method recordSubProcessInstanceStart.

/* (non-Javadoc)
   * @see org.activiti.engine.impl.history.HistoryManagerInterface#recordSubProcessInstanceStart(org.activiti.engine.impl.persistence.entity.ExecutionEntity, org.activiti.engine.impl.persistence.entity.ExecutionEntity)
   */
@Override
public void recordSubProcessInstanceStart(ExecutionEntity parentExecution, ExecutionEntity subProcessInstance) {
    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstanceEntity historicProcessInstance = new HistoricProcessInstanceEntity((ExecutionEntity) subProcessInstance);
        ActivityImpl initialActivity = subProcessInstance.getActivity();
        // Fix for ACT-1728: startActivityId not initialized with subprocess-instance
        if (historicProcessInstance.getStartActivityId() == null) {
            historicProcessInstance.setStartActivityId(subProcessInstance.getProcessDefinition().getInitial().getId());
            initialActivity = subProcessInstance.getProcessDefinition().getInitial();
        }
        getDbSqlSession().insert(historicProcessInstance);
        // Fire event
        ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
        if (config != null && config.getEventDispatcher().isEnabled()) {
            config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
        }
        HistoricActivityInstanceEntity activitiyInstance = findActivityInstance(parentExecution);
        if (activitiyInstance != null) {
            activitiyInstance.setCalledProcessInstanceId(subProcessInstance.getProcessInstanceId());
        }
        // Fix for ACT-1728: start-event not recorded for subprocesses
        IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator();
        // Also record the start-event manually, as there is no "start" activity history listener for this
        HistoricActivityInstanceEntity historicActivityInstance = new HistoricActivityInstanceEntity();
        historicActivityInstance.setId(idGenerator.getNextId());
        historicActivityInstance.setProcessDefinitionId(subProcessInstance.getProcessDefinitionId());
        historicActivityInstance.setProcessInstanceId(subProcessInstance.getProcessInstanceId());
        historicActivityInstance.setExecutionId(subProcessInstance.getId());
        historicActivityInstance.setActivityId(initialActivity.getId());
        historicActivityInstance.setActivityName((String) initialActivity.getProperty("name"));
        historicActivityInstance.setActivityType((String) initialActivity.getProperty("type"));
        Date now = Context.getProcessEngineConfiguration().getClock().getCurrentTime();
        historicActivityInstance.setStartTime(now);
        getDbSqlSession().insert(historicActivityInstance);
        // Fire event
        if (config != null && config.getEventDispatcher().isEnabled()) {
            config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, historicActivityInstance));
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) HistoricActivityInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity) HistoricProcessInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity) IdGenerator(org.activiti.engine.impl.cfg.IdGenerator) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) Date(java.util.Date)

Example 22 with ProcessEngineConfigurationImpl

use of org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl in project Activiti by Activiti.

the class TerminateEndEventActivityBehavior method endAllHistoricActivities.

protected void endAllHistoricActivities(String processInstanceId) {
    if (!Context.getProcessEngineConfiguration().getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        return;
    }
    Map<String, HistoricActivityInstanceEntity> historicActivityInstancMap = new HashMap<String, HistoricActivityInstanceEntity>();
    List<HistoricActivityInstance> historicActivityInstances = new HistoricActivityInstanceQueryImpl(Context.getCommandContext()).processInstanceId(processInstanceId).unfinished().list();
    for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        historicActivityInstancMap.put(historicActivityInstance.getId(), (HistoricActivityInstanceEntity) historicActivityInstance);
    }
    // Cached version overwites entity
    List<HistoricActivityInstanceEntity> cachedHistoricActivityInstances = Context.getCommandContext().getDbSqlSession().findInCache(HistoricActivityInstanceEntity.class);
    for (HistoricActivityInstanceEntity cachedHistoricActivityInstance : cachedHistoricActivityInstances) {
        if (processInstanceId.equals(cachedHistoricActivityInstance.getProcessInstanceId()) && (cachedHistoricActivityInstance.getEndTime() == null)) {
            historicActivityInstancMap.put(cachedHistoricActivityInstance.getId(), cachedHistoricActivityInstance);
        }
    }
    for (HistoricActivityInstanceEntity historicActivityInstance : historicActivityInstancMap.values()) {
        historicActivityInstance.markEnded(null);
        // Fire event
        ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
        if (config != null && config.getEventDispatcher().isEnabled()) {
            config.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_ENDED, historicActivityInstance));
        }
    }
}
Also used : HistoricActivityInstanceEntity(org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity) HashMap(java.util.HashMap) HistoricActivityInstanceQueryImpl(org.activiti.engine.impl.HistoricActivityInstanceQueryImpl) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 23 with ProcessEngineConfigurationImpl

use of org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl in project Activiti by Activiti.

the class BusinessRuleTaskActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) execution.getEngineServices().getProcessEngineConfiguration();
    ProcessDefinition processDefinition = processEngineConfiguration.getDeploymentManager().findDeployedProcessDefinitionById(execution.getProcessDefinitionId());
    String deploymentId = processDefinition.getDeploymentId();
    KnowledgeBase knowledgeBase = RulesHelper.findKnowledgeBaseByDeploymentId(deploymentId);
    StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession();
    if (variablesInputExpressions != null) {
        Iterator<Expression> itVariable = variablesInputExpressions.iterator();
        while (itVariable.hasNext()) {
            Expression variable = itVariable.next();
            ksession.insert(variable.getValue(execution));
        }
    }
    if (!rulesExpressions.isEmpty()) {
        RulesAgendaFilter filter = new RulesAgendaFilter();
        Iterator<Expression> itRuleNames = rulesExpressions.iterator();
        while (itRuleNames.hasNext()) {
            Expression ruleName = itRuleNames.next();
            filter.addSuffic(ruleName.getValue(execution).toString());
        }
        filter.setAccept(!exclude);
        ksession.fireAllRules(filter);
    } else {
        ksession.fireAllRules();
    }
    Collection<Object> ruleOutputObjects = ksession.getObjects();
    if (ruleOutputObjects != null && !ruleOutputObjects.isEmpty()) {
        Collection<Object> outputVariables = new ArrayList<Object>();
        for (Object object : ruleOutputObjects) {
            outputVariables.add(object);
        }
        execution.setVariable(resultVariable, outputVariables);
    }
    ksession.dispose();
    leave(execution);
}
Also used : KnowledgeBase(org.drools.KnowledgeBase) Expression(org.activiti.engine.delegate.Expression) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) RulesAgendaFilter(org.activiti.engine.impl.rules.RulesAgendaFilter) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)

Example 24 with ProcessEngineConfigurationImpl

use of org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl in project Activiti by Activiti.

the class SimpleSimulationRunTest method recordEvents.

private void recordEvents() {
    Clock clock = new DefaultClockImpl();
    clock.setCurrentTime(new Date(0));
    ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
    config.setClock(clock);
    ProcessEngine processEngine = (new RecordableProcessEngineFactory(config, listener)).getObject();
    processEngine.getRepositoryService().createDeployment().addClasspathResource(USERTASK_PROCESS).deploy();
    EventRecorderTestUtils.increaseTime(clock);
    TaskService taskService = processEngine.getTaskService();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put(TEST_VARIABLE, TEST_VALUE);
    processEngine.getRuntimeService().startProcessInstanceByKey("oneTaskProcess", "oneTaskProcessBusinessKey", variables);
    EventRecorderTestUtils.increaseTime(clock);
    Task task = taskService.createTaskQuery().taskDefinitionKey("userTask").singleResult();
    taskService.complete(task.getId());
    checkStatus(processEngine.getHistoryService());
    EventRecorderTestUtils.closeProcessEngine(processEngine, listener);
    ProcessEngines.destroy();
}
Also used : Task(org.activiti.engine.task.Task) DefaultClockImpl(org.activiti.engine.impl.util.DefaultClockImpl) ThreadLocalClock(org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock) Clock(org.activiti.engine.runtime.Clock) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)

Example 25 with ProcessEngineConfigurationImpl

use of org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl in project Activiti by Activiti.

the class PlaybackRunTest method recordEvents.

private void recordEvents() {
    Clock clock = new DefaultClockImpl();
    ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
    config.setClock(clock);
    ProcessEngine processEngine = (new RecordableProcessEngineFactory(config, listener)).getObject();
    processEngine.getProcessEngineConfiguration().setClock(clock);
    processEngine.getRepositoryService().createDeployment().addClasspathResource(THE_SIMPLEST_PROCESS).deploy();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put(TEST_VARIABLE, TEST_VALUE);
    processEngine.getRuntimeService().startProcessInstanceByKey(SIMPLEST_PROCESS, BUSINESS_KEY, variables);
    checkStatus(processEngine);
    EventRecorderTestUtils.closeProcessEngine(processEngine, listener);
    ProcessEngines.destroy();
}
Also used : DefaultClockImpl(org.activiti.engine.impl.util.DefaultClockImpl) HashMap(java.util.HashMap) ThreadLocalClock(org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock) Clock(org.activiti.engine.runtime.Clock) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)

Aggregations

ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)36 ThreadLocalClock (org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock)5 Clock (org.activiti.engine.runtime.Clock)5 ActivitiException (org.activiti.engine.ActivitiException)4 ProcessEngine (org.activiti.engine.ProcessEngine)4 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)4 HistoricActivityInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntity)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 IdGenerator (org.activiti.engine.impl.cfg.IdGenerator)3 StandaloneInMemProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration)3 HistoricProcessInstanceEntity (org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity)3 DefaultClockImpl (org.activiti.engine.impl.util.DefaultClockImpl)3 EntityManagerSession (org.activiti.engine.impl.variable.EntityManagerSession)3 EntityManagerSessionFactory (org.activiti.engine.impl.variable.EntityManagerSessionFactory)3 Task (org.activiti.engine.task.Task)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ArrayList (java.util.ArrayList)2 DefaultClockFactory (org.activiti.crystalball.simulator.impl.clock.DefaultClockFactory)2