use of org.activiti.engine.impl.el.NoExecutionVariableScope in project Activiti by Activiti.
the class DelegateExpressionActivitiEventListener method onEvent.
@Override
public void onEvent(ActivitiEvent event) {
if (isValidEvent(event)) {
Object delegate = DelegateExpressionUtil.resolveDelegateExpression(expression, new NoExecutionVariableScope());
if (delegate instanceof ActivitiEventListener) {
// Cache result of isFailOnException() from delegate-instance
// until next event is received. This prevents us from having to resolve
// the expression twice when an error occurs.
failOnException = ((ActivitiEventListener) delegate).isFailOnException();
// Call the delegate
((ActivitiEventListener) delegate).onEvent(event);
} else {
// Force failing, since the exception we're about to throw
// cannot be ignored, because it did not originate from the listener itself
failOnException = true;
throw new ActivitiIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + ActivitiEventListener.class.getName());
}
}
}
use of org.activiti.engine.impl.el.NoExecutionVariableScope in project Activiti by Activiti.
the class SimpleSimulationRunTest method testRunToTimeInThePast.
@Test(expected = RuntimeException.class)
public void testRunToTimeInThePast() throws Exception {
recordEvents();
SimulationDebugger simDebugger = createDebugger();
simDebugger.init(new NoExecutionVariableScope());
try {
simDebugger.runTo(-1);
fail("RuntimeException expected - unable to execute event from the past");
} finally {
simDebugger.close();
ProcessEngines.destroy();
}
}
use of org.activiti.engine.impl.el.NoExecutionVariableScope in project Activiti by Activiti.
the class SimpleSimulationRunTest method testRunContinue.
@Test
public void testRunContinue() throws Exception {
recordEvents();
SimulationDebugger simDebugger = createDebugger();
simDebugger.init(new NoExecutionVariableScope());
simDebugger.runContinue();
checkStatus(SimulationRunContext.getHistoryService());
simDebugger.close();
ProcessEngines.destroy();
}
use of org.activiti.engine.impl.el.NoExecutionVariableScope in project Activiti by Activiti.
the class SimpleSimulationRunTest method testStep.
@Test
public void testStep() throws Exception {
recordEvents();
SimulationDebugger simDebugger = createDebugger();
simDebugger.init(new NoExecutionVariableScope());
RuntimeService runtimeService = SimulationRunContext.getRuntimeService();
TaskService taskService = SimulationRunContext.getTaskService();
HistoryService historyService = SimulationRunContext.getHistoryService();
// debuger step - deploy processDefinition
simDebugger.step();
step0Check(SimulationRunContext.getRepositoryService());
// debuger step - start process and stay on the userTask
simDebugger.step();
step1Check(runtimeService, taskService);
// debugger step - complete userTask and finish process
simDebugger.step();
step2Check(runtimeService, taskService);
checkStatus(historyService);
simDebugger.close();
ProcessEngines.destroy();
}
use of org.activiti.engine.impl.el.NoExecutionVariableScope in project Activiti by Activiti.
the class TimerDeclarationImpl method prepareTimerEntity.
public TimerEntity prepareTimerEntity(ExecutionEntity executionEntity) {
// 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();
}
String calendarNameValue = type.calendarName;
if (this.calendarNameExpression != null) {
calendarNameValue = (String) this.calendarNameExpression.getValue(scopeForExpression);
}
BusinessCalendar businessCalendar = Context.getProcessEngineConfiguration().getBusinessCalendarManager().getBusinessCalendar(calendarNameValue);
if (description == null) {
// Prevent NPE from happening in the next line
throw new ActivitiIllegalArgumentException("Timer '" + executionEntity.getActivityId() + "' was not configured with a valid duration/time");
}
String endDateString = null;
String dueDateString = null;
Date duedate = null;
Date endDate = null;
if (endDateExpression != null && !(scopeForExpression instanceof NoExecutionVariableScope)) {
Object endDateValue = endDateExpression.getValue(scopeForExpression);
if (endDateValue instanceof String) {
endDateString = (String) endDateValue;
} else if (endDateValue instanceof Date) {
endDate = (Date) endDateValue;
} else if (endDateValue instanceof DateTime) {
// Joda DateTime support
duedate = ((DateTime) endDateValue).toDate();
} else {
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 (endDate == null) {
endDate = businessCalendar.resolveEndDate(endDateString);
}
}
Object dueDateValue = description.getValue(scopeForExpression);
if (dueDateValue instanceof String) {
dueDateString = (String) dueDateValue;
} else if (dueDateValue instanceof Date) {
duedate = (Date) dueDateValue;
} else if (dueDateValue instanceof DateTime) {
// Joda DateTime support
duedate = ((DateTime) dueDateValue).toDate();
} else if (dueDateValue != null) {
//dueDateValue==null is OK - but unexpected class type must throw an error.
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);
}
TimerEntity timer = null;
// if dueDateValue is null -> this is OK - timer will be null and job not scheduled
if (duedate != null) {
timer = new TimerEntity(this);
timer.setDuedate(duedate);
timer.setEndDate(endDate);
if (executionEntity != null) {
timer.setExecution(executionEntity);
timer.setProcessDefinitionId(executionEntity.getProcessDefinitionId());
timer.setProcessInstanceId(executionEntity.getProcessInstanceId());
// Inherit tenant identifier (if applicable)
if (executionEntity != null && executionEntity.getTenantId() != null) {
timer.setTenantId(executionEntity.getTenantId());
}
}
if (type == TimerDeclarationType.CYCLE) {
// 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 (TimerCatchIntermediateEventJobHandler.TYPE.equals(jobHandlerType)) {
repeat = false;
if (endDate != null) {
long endDateMiliss = endDate.getTime();
long dueDateMiliss = duedate.getTime();
long dueDate = Math.min(endDateMiliss, dueDateMiliss);
timer.setDuedate(new Date(dueDate));
}
}
if (repeat) {
String prepared = prepareRepeat(dueDateString);
timer.setRepeat(prepared);
}
}
}
return timer;
}
Aggregations