Search in sources :

Example 11 with NoExecutionVariableScope

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());
        }
    }
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) ActivitiEventListener(org.activiti.engine.delegate.event.ActivitiEventListener)

Example 12 with NoExecutionVariableScope

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();
    }
}
Also used : NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) Test(org.junit.Test)

Example 13 with NoExecutionVariableScope

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();
}
Also used : NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) Test(org.junit.Test)

Example 14 with NoExecutionVariableScope

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();
}
Also used : NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) Test(org.junit.Test)

Example 15 with NoExecutionVariableScope

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;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) BusinessCalendar(org.activiti.engine.impl.calendar.BusinessCalendar) VariableScope(org.activiti.engine.delegate.VariableScope) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) Date(java.util.Date) DateTime(org.joda.time.DateTime)

Aggregations

NoExecutionVariableScope (org.activiti.engine.impl.el.NoExecutionVariableScope)16 Test (org.junit.Test)9 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)4 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)4 ReplaySimulationRun (org.activiti.crystalball.simulator.ReplaySimulationRun)3 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)3 Date (java.util.Date)2 SimpleEventCalendar (org.activiti.crystalball.simulator.SimpleEventCalendar)2 SimulationDebugger (org.activiti.crystalball.simulator.SimulationDebugger)2 SimulationEventComparator (org.activiti.crystalball.simulator.SimulationEventComparator)2 EventLogTransformer (org.activiti.crystalball.simulator.delegate.event.impl.EventLogTransformer)2 DefaultClockFactory (org.activiti.crystalball.simulator.impl.clock.DefaultClockFactory)2 ThreadLocalClock (org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock)2 ActivitiException (org.activiti.engine.ActivitiException)2 RuntimeService (org.activiti.engine.RuntimeService)2 TaskService (org.activiti.engine.TaskService)2 VariableScope (org.activiti.engine.delegate.VariableScope)2 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)2 Clock (org.activiti.engine.runtime.Clock)2 Task (org.activiti.engine.task.Task)2