Search in sources :

Example 6 with NoExecutionVariableScope

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

Example 7 with NoExecutionVariableScope

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();
    }
}
Also used : NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) ThreadLocalClock(org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock) Clock(org.activiti.engine.runtime.Clock) DefaultClockFactory(org.activiti.crystalball.simulator.impl.clock.DefaultClockFactory) SimulationProcessEngineFactory(org.activiti.crystalball.simulator.impl.SimulationProcessEngineFactory) AssertionFailedError(junit.framework.AssertionFailedError) ThreadLocalClock(org.activiti.crystalball.simulator.impl.clock.ThreadLocalClock) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl)

Example 8 with NoExecutionVariableScope

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();
}
Also used : ReplaySimulationRun(org.activiti.crystalball.simulator.ReplaySimulationRun) ClickEvent(com.vaadin.ui.Button.ClickEvent) SimpleEventCalendar(org.activiti.crystalball.simulator.SimpleEventCalendar) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) SimulationEventComparator(org.activiti.crystalball.simulator.SimulationEventComparator) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) EventLogTransformer(org.activiti.crystalball.simulator.delegate.event.impl.EventLogTransformer) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.data.Property.ValueChangeListener) Button(com.vaadin.ui.Button) NativeSelect(com.vaadin.ui.NativeSelect) ArrayList(java.util.ArrayList) List(java.util.List) ClickListener(com.vaadin.ui.Button.ClickListener)

Example 9 with NoExecutionVariableScope

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

Example 10 with NoExecutionVariableScope

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;
}
Also used : ExpressionManager(org.activiti.engine.impl.el.ExpressionManager) ActivitiException(org.activiti.engine.ActivitiException) IntermediateCatchEvent(org.activiti.bpmn.model.IntermediateCatchEvent) Date(java.util.Date) DateTime(org.joda.time.DateTime) Expression(org.activiti.engine.delegate.Expression) FlowElement(org.activiti.bpmn.model.FlowElement) DueDateBusinessCalendar(org.activiti.engine.impl.calendar.DueDateBusinessCalendar) CycleBusinessCalendar(org.activiti.engine.impl.calendar.CycleBusinessCalendar) DurationBusinessCalendar(org.activiti.engine.impl.calendar.DurationBusinessCalendar) BusinessCalendar(org.activiti.engine.impl.calendar.BusinessCalendar) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) VariableScope(org.activiti.engine.delegate.VariableScope) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope)

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