Search in sources :

Example 1 with VariableScope

use of org.camunda.bpm.engine.delegate.VariableScope in project camunda-bpm-platform by camunda.

the class EventSubscriptionDeclaration method createSubscriptionForStartEvent.

public EventSubscriptionEntity createSubscriptionForStartEvent(ProcessDefinitionEntity processDefinition) {
    EventSubscriptionEntity eventSubscriptionEntity = new EventSubscriptionEntity(eventType);
    VariableScope scopeForExpression = StartProcessVariableScope.getSharedInstance();
    String eventName = resolveExpressionOfEventName(scopeForExpression);
    eventSubscriptionEntity.setEventName(eventName);
    eventSubscriptionEntity.setActivityId(activityId);
    eventSubscriptionEntity.setConfiguration(processDefinition.getId());
    eventSubscriptionEntity.setTenantId(processDefinition.getTenantId());
    return eventSubscriptionEntity;
}
Also used : EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity) VariableScope(org.camunda.bpm.engine.delegate.VariableScope) StartProcessVariableScope(org.camunda.bpm.engine.impl.el.StartProcessVariableScope)

Example 2 with VariableScope

use of org.camunda.bpm.engine.delegate.VariableScope in project camunda-bpm-platform by camunda.

the class DelegateExpressionTaskListener method notify.

public void notify(DelegateTask delegateTask) {
    // Note: we can't cache the result of the expression, because the
    // execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}'
    VariableScope variableScope = delegateTask.getExecution();
    if (variableScope == null) {
        variableScope = delegateTask.getCaseExecution();
    }
    Object delegate = expression.getValue(variableScope);
    applyFieldDeclaration(fieldDeclarations, delegate);
    if (delegate instanceof TaskListener) {
        try {
            Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new TaskListenerInvocation((TaskListener) delegate, delegateTask));
        } catch (Exception e) {
            throw new ProcessEngineException("Exception while invoking TaskListener: " + e.getMessage(), e);
        }
    } else {
        throw new ProcessEngineException("Delegate expression " + expression + " did not resolve to an implementation of " + TaskListener.class);
    }
}
Also used : TaskListenerInvocation(org.camunda.bpm.engine.impl.task.delegate.TaskListenerInvocation) TaskListener(org.camunda.bpm.engine.delegate.TaskListener) VariableScope(org.camunda.bpm.engine.delegate.VariableScope) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 3 with VariableScope

use of org.camunda.bpm.engine.delegate.VariableScope in project camunda-bpm-platform by camunda.

the class FormFieldHandler method createFormField.

public FormField createFormField(ExecutionEntity executionEntity) {
    FormFieldImpl formField = new FormFieldImpl();
    // set id
    formField.setId(id);
    // set label (evaluate expression)
    VariableScope variableScope = executionEntity != null ? executionEntity : StartProcessVariableScope.getSharedInstance();
    if (label != null) {
        Object labelValueObject = label.getValue(variableScope);
        if (labelValueObject != null) {
            formField.setLabel(labelValueObject.toString());
        }
    }
    formField.setBusinessKey(businessKey);
    // set type
    formField.setType(type);
    // set default value (evaluate expression)
    Object defaultValue = null;
    if (defaultValueExpression != null) {
        defaultValue = defaultValueExpression.getValue(variableScope);
        if (defaultValue != null) {
            formField.setDefaultValue(type.convertFormValueToModelValue(defaultValue));
        } else {
            formField.setDefaultValue(null);
        }
    }
    // value
    TypedValue value = variableScope.getVariableTyped(id);
    if (value != null) {
        formField.setValue(type.convertToFormValue(value));
    } else {
        // first, need to convert to model value since the default value may be a String Constant specified in the model xml.
        TypedValue typedDefaultValue = type.convertToModelValue(Variables.untypedValue(defaultValue));
        // now convert to form value
        formField.setValue(type.convertToFormValue(typedDefaultValue));
    }
    // properties
    formField.setProperties(properties);
    // validation
    List<FormFieldValidationConstraint> validationConstraints = formField.getValidationConstraints();
    for (FormFieldValidationConstraintHandler validationHandler : validationHandlers) {
        // do not add custom validators
        if (!"validator".equals(validationHandler.name)) {
            validationConstraints.add(validationHandler.createValidationConstraint(executionEntity));
        }
    }
    return formField;
}
Also used : FormFieldValidationConstraint(org.camunda.bpm.engine.form.FormFieldValidationConstraint) FormFieldImpl(org.camunda.bpm.engine.impl.form.FormFieldImpl) VariableScope(org.camunda.bpm.engine.delegate.VariableScope) StartProcessVariableScope(org.camunda.bpm.engine.impl.el.StartProcessVariableScope) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 4 with VariableScope

use of org.camunda.bpm.engine.delegate.VariableScope in project camunda-bpm-platform by camunda.

the class TimerDeclarationImpl method initializeConfiguration.

protected void initializeConfiguration(ExecutionEntity context, TimerEntity job) {
    BusinessCalendar businessCalendar = Context.getProcessEngineConfiguration().getBusinessCalendarManager().getBusinessCalendar(type.calendarName);
    if (description == null) {
        throw new ProcessEngineException("Timer '" + context.getActivityId() + "' was not configured with a valid duration/time");
    }
    String dueDateString = null;
    Date duedate = null;
    // ACT-1415: timer-declaration on start-event may contain expressions NOT
    // evaluating variables but other context, evaluating should happen nevertheless
    VariableScope scopeForExpression = context;
    if (scopeForExpression == null) {
        scopeForExpression = StartProcessVariableScope.getSharedInstance();
    }
    Object dueDateValue = description.getValue(scopeForExpression);
    if (dueDateValue instanceof String) {
        dueDateString = (String) dueDateValue;
    } else if (dueDateValue instanceof Date) {
        duedate = (Date) dueDateValue;
    } else {
        throw new ProcessEngineException("Timer '" + context.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) {
        duedate = businessCalendar.resolveDuedate(dueDateString);
    }
    job.setDuedate(duedate);
    if (type == TimerDeclarationType.CYCLE && jobHandlerType != TimerCatchIntermediateEventJobHandler.TYPE) {
        // See ACT-1427: A boundary timer with a cancelActivity='true', doesn't need to repeat itself
        if (!isInterruptingTimer) {
            String prepared = prepareRepeat(dueDateString);
            job.setRepeat(prepared);
        }
    }
}
Also used : BusinessCalendar(org.camunda.bpm.engine.impl.calendar.BusinessCalendar) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Date(java.util.Date) VariableScope(org.camunda.bpm.engine.delegate.VariableScope) StartProcessVariableScope(org.camunda.bpm.engine.impl.el.StartProcessVariableScope)

Example 5 with VariableScope

use of org.camunda.bpm.engine.delegate.VariableScope in project camunda-bpm-platform by camunda.

the class VariableScopeElResolver method setValue.

public void setValue(ELContext context, Object base, Object property, Object value) {
    if (base == null) {
        String variable = (String) property;
        Object object = context.getContext(VariableScope.class);
        if (object != null) {
            VariableScope variableScope = (VariableScope) object;
            if (variableScope.hasVariable(variable)) {
                variableScope.setVariable(variable, value);
            }
        }
    }
}
Also used : VariableScope(org.camunda.bpm.engine.delegate.VariableScope)

Aggregations

VariableScope (org.camunda.bpm.engine.delegate.VariableScope)5 StartProcessVariableScope (org.camunda.bpm.engine.impl.el.StartProcessVariableScope)3 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 Date (java.util.Date)1 TaskListener (org.camunda.bpm.engine.delegate.TaskListener)1 FormFieldValidationConstraint (org.camunda.bpm.engine.form.FormFieldValidationConstraint)1 BusinessCalendar (org.camunda.bpm.engine.impl.calendar.BusinessCalendar)1 FormFieldImpl (org.camunda.bpm.engine.impl.form.FormFieldImpl)1 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)1 TaskListenerInvocation (org.camunda.bpm.engine.impl.task.delegate.TaskListenerInvocation)1 TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)1