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));
}
}
}
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));
}
}
}
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);
}
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();
}
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();
}
Aggregations