use of org.activiti.engine.impl.el.NoExecutionVariableScope in project Activiti by Activiti.
the class SimpleSimulationRunTest method testRunToEvent.
@Test
public void testRunToEvent() throws Exception {
recordEvents();
SimulationDebugger simDebugger = createDebugger();
simDebugger.init(new NoExecutionVariableScope());
try {
simDebugger.runTo(USER_TASK_COMPLETED_EVENT_TYPE);
step1Check(SimulationRunContext.getRuntimeService(), SimulationRunContext.getTaskService());
simDebugger.runContinue();
} finally {
simDebugger.close();
ProcessEngines.destroy();
}
}
use of org.activiti.engine.impl.el.NoExecutionVariableScope in project Activiti by Activiti.
the class AbstractPlaybackTest method runPlayback.
private void runPlayback() throws Throwable {
SimulationDebugger simDebugger = null;
try {
// init simulation run
Clock clock = new ThreadLocalClock(new DefaultClockFactory());
FactoryBean<ProcessEngineImpl> simulationProcessEngineFactory = new SimulationProcessEngineFactory(ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault());
final SimpleSimulationRun.Builder builder = new SimpleSimulationRun.Builder();
builder.processEngine(simulationProcessEngineFactory.getObject()).eventCalendar((new SimpleEventCalendarFactory(clock, new SimulationEventComparator(), listener.getSimulationEvents())).getObject()).eventHandlers(getHandlers());
simDebugger = builder.build();
simDebugger.init(new NoExecutionVariableScope());
this.processEngine = SimulationRunContext.getProcessEngine();
initializeServices();
deploymentIdFromDeploymentAnnotation = TestHelper.annotationDeploymentSetUp(processEngine, getClass(), getName());
simDebugger.runContinue();
_checkStatus();
} catch (AssertionFailedError e) {
log.warn("Playback simulation {} has failed", getName());
log.error(EMPTY_LINE);
log.error("ASSERTION FAILED: {}", e, e);
exception = e;
throw e;
} catch (Throwable e) {
log.warn("Playback simulation {} has failed", getName());
log.error(EMPTY_LINE);
log.error("EXCEPTION: {}", e, e);
exception = e;
throw e;
} finally {
if (simDebugger != null) {
TestHelper.annotationDeploymentTearDown(processEngine, deploymentIdFromDeploymentAnnotation, getClass(), getName());
simDebugger.close();
assertAndEnsureCleanDb();
}
this.processEngineConfiguration.getClock().reset();
// Can't do this in the teardown, as the teardown will be called as part of the super.runBare
closeDownProcessEngine();
}
}
use of org.activiti.engine.impl.el.NoExecutionVariableScope in project Activiti by Activiti.
the class EventOverviewPanel method initProcessInstances.
protected void initProcessInstances() {
HorizontalLayout instancesHeader = new HorizontalLayout();
instancesHeader.setSpacing(false);
instancesHeader.setMargin(false);
instancesHeader.setWidth(100, UNITS_PERCENTAGE);
instancesHeader.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
addDetailComponent(instancesHeader);
initProcessInstanceTitle(instancesHeader);
HorizontalLayout selectLayout = new HorizontalLayout();
selectLayout.setSpacing(true);
selectLayout.setMargin(true);
selectLayout.setWidth(50, UNITS_PERCENTAGE);
addDetailComponent(selectLayout);
definitionSelect = new NativeSelect(i18nManager.getMessage(Messages.DEPLOYMENT_HEADER_DEFINITIONS));
definitionSelect.setImmediate(true);
for (ProcessDefinition definition : definitionList) {
definitionSelect.addItem(definition.getId());
definitionSelect.setItemCaption(definition.getId(), definition.getName());
}
definitionSelect.addListener(new ValueChangeListener() {
private static final long serialVersionUID = 1L;
@Override
public void valueChange(ValueChangeEvent event) {
if (definitionSelect.getValue() != null) {
String selectedDefinitionId = (String) definitionSelect.getValue();
ExplorerApp.get().setCrystalBallCurrentDefinitionId(selectedDefinitionId);
refreshInstances(selectedDefinitionId);
}
}
});
selectLayout.addComponent(definitionSelect);
replayButton = new Button(i18nManager.getMessage(Messages.CRYSTALBALL_BUTTON_REPLAY));
replayButton.setEnabled(false);
replayButton.addListener(new ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
if (instanceTable.getValue() != null) {
String processInstanceId = (String) instanceTable.getValue();
ExplorerApp.get().setCrystalBallCurrentInstanceId(processInstanceId);
List<EventLogEntry> eventLogEntries = managementService.getEventLogEntriesByProcessInstanceId(processInstanceId);
if (eventLogEntries == null || eventLogEntries.isEmpty())
return;
EventLogTransformer transformer = new EventLogTransformer(getTransformers());
simulationEvents = transformer.transform(eventLogEntries);
ExplorerApp.get().setCrystalBallSimulationEvents(simulationEvents);
SimpleEventCalendar eventCalendar = new SimpleEventCalendar(ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration().getClock(), new SimulationEventComparator());
eventCalendar.addEvents(simulationEvents);
// replay process instance run
simulationDebugger = new ReplaySimulationRun(ProcessEngines.getDefaultProcessEngine(), eventCalendar, getReplayHandlers(processInstanceId));
ExplorerApp.get().setCrystalBallSimulationDebugger(simulationDebugger);
simulationDebugger.init(new NoExecutionVariableScope());
simulationDebugger.step();
// replay process was started
List<HistoricProcessInstance> replayProcessInstanceList = historyService.createHistoricProcessInstanceQuery().processInstanceBusinessKey(SIMULATION_BUSINESS_KEY).orderByProcessInstanceStartTime().desc().list();
if (replayProcessInstanceList != null && !replayProcessInstanceList.isEmpty()) {
replayHistoricInstance = replayProcessInstanceList.get(0);
}
refreshEvents();
}
}
});
selectLayout.addComponent(replayButton);
selectLayout.setComponentAlignment(replayButton, Alignment.MIDDLE_LEFT);
instanceLayout = new HorizontalLayout();
instanceLayout.setWidth(100, UNITS_PERCENTAGE);
addDetailComponent(instanceLayout);
initInstancesTable();
}
use of org.activiti.engine.impl.el.NoExecutionVariableScope in project Activiti by Activiti.
the class DelegateExpressionTransactionDependentTaskListener method notify.
@Override
public void notify(String processInstanceId, String executionId, Task task, Map<String, Object> executionVariables, Map<String, Object> customPropertiesMap) {
NoExecutionVariableScope scope = new NoExecutionVariableScope();
Object delegate = expression.getValue(scope);
if (delegate instanceof TransactionDependentTaskListener) {
((TransactionDependentTaskListener) delegate).notify(processInstanceId, executionId, task, executionVariables, customPropertiesMap);
} else {
throw new ActivitiIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + TransactionDependentTaskListener.class);
}
}
use of org.activiti.engine.impl.el.NoExecutionVariableScope in project Activiti by Activiti.
the class TimerUtil method createTimerEntityForTimerEventDefinition.
/**
* The event definition on which the timer is based.
*
* Takes in an optional execution, if missing the {@link NoExecutionVariableScope} will be used (eg Timer start event)
*/
public static TimerJobEntity createTimerEntityForTimerEventDefinition(TimerEventDefinition timerEventDefinition, boolean isInterruptingTimer, ExecutionEntity executionEntity, String jobHandlerType, String jobHandlerConfig) {
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
String businessCalendarRef = null;
Expression expression = null;
ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager();
// ACT-1415: timer-declaration on start-event may contain expressions NOT
// evaluating variables but other context, evaluating should happen nevertheless
VariableScope scopeForExpression = executionEntity;
if (scopeForExpression == null) {
scopeForExpression = NoExecutionVariableScope.getSharedInstance();
}
if (StringUtils.isNotEmpty(timerEventDefinition.getTimeDate())) {
businessCalendarRef = DueDateBusinessCalendar.NAME;
expression = expressionManager.createExpression(timerEventDefinition.getTimeDate());
} else if (StringUtils.isNotEmpty(timerEventDefinition.getTimeCycle())) {
businessCalendarRef = CycleBusinessCalendar.NAME;
expression = expressionManager.createExpression(timerEventDefinition.getTimeCycle());
} else if (StringUtils.isNotEmpty(timerEventDefinition.getTimeDuration())) {
businessCalendarRef = DurationBusinessCalendar.NAME;
expression = expressionManager.createExpression(timerEventDefinition.getTimeDuration());
}
if (StringUtils.isNotEmpty(timerEventDefinition.getCalendarName())) {
businessCalendarRef = timerEventDefinition.getCalendarName();
Expression businessCalendarExpression = expressionManager.createExpression(businessCalendarRef);
businessCalendarRef = businessCalendarExpression.getValue(scopeForExpression).toString();
}
if (expression == null) {
throw new ActivitiException("Timer needs configuration (either timeDate, timeCycle or timeDuration is needed) (" + timerEventDefinition.getId() + ")");
}
BusinessCalendar businessCalendar = processEngineConfiguration.getBusinessCalendarManager().getBusinessCalendar(businessCalendarRef);
String dueDateString = null;
Date duedate = null;
Object dueDateValue = expression.getValue(scopeForExpression);
if (dueDateValue instanceof String) {
dueDateString = (String) dueDateValue;
} else if (dueDateValue instanceof Date) {
duedate = (Date) dueDateValue;
} else if (dueDateValue instanceof DateTime) {
// JodaTime support
duedate = ((DateTime) dueDateValue).toDate();
} else if (dueDateValue != null) {
throw new ActivitiException("Timer '" + executionEntity.getActivityId() + "' was not configured with a valid duration/time, either hand in a java.util.Date or a String in format 'yyyy-MM-dd'T'hh:mm:ss'");
}
if (duedate == null && dueDateString != null) {
duedate = businessCalendar.resolveDuedate(dueDateString);
}
TimerJobEntity timer = null;
if (duedate != null) {
timer = Context.getCommandContext().getTimerJobEntityManager().create();
timer.setJobType(JobEntity.JOB_TYPE_TIMER);
timer.setRevision(1);
timer.setJobHandlerType(jobHandlerType);
timer.setJobHandlerConfiguration(jobHandlerConfig);
timer.setExclusive(true);
timer.setRetries(processEngineConfiguration.getAsyncExecutorNumberOfRetries());
timer.setDuedate(duedate);
if (executionEntity != null) {
timer.setExecution(executionEntity);
timer.setProcessDefinitionId(executionEntity.getProcessDefinitionId());
timer.setProcessInstanceId(executionEntity.getProcessInstanceId());
// Inherit tenant identifier (if applicable)
if (executionEntity.getTenantId() != null) {
timer.setTenantId(executionEntity.getTenantId());
}
}
}
if (StringUtils.isNotEmpty(timerEventDefinition.getTimeCycle())) {
// See ACT-1427: A boundary timer with a cancelActivity='true', doesn't need to repeat itself
boolean repeat = !isInterruptingTimer;
// ACT-1951: intermediate catching timer events shouldn't repeat according to spec
if (executionEntity != null) {
FlowElement currentElement = executionEntity.getCurrentFlowElement();
if (currentElement instanceof IntermediateCatchEvent) {
repeat = false;
}
}
if (repeat) {
String prepared = prepareRepeat(dueDateString);
timer.setRepeat(prepared);
}
}
if (timer != null && executionEntity != null) {
timer.setExecution(executionEntity);
timer.setProcessDefinitionId(executionEntity.getProcessDefinitionId());
// Inherit tenant identifier (if applicable)
if (executionEntity.getTenantId() != null) {
timer.setTenantId(executionEntity.getTenantId());
}
}
return timer;
}
Aggregations