Search in sources :

Example 1 with Expression

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

the class GetFormKeyCmd method execute.

public String execute(CommandContext commandContext) {
    ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
    DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache();
    ProcessDefinitionEntity processDefinition = deploymentCache.findDeployedProcessDefinitionById(processDefinitionId);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkReadProcessDefinition(processDefinition);
    }
    Expression formKeyExpression = null;
    if (taskDefinitionKey == null) {
        // TODO: Maybe add getFormKey() to FormHandler interface to avoid the following cast
        FormHandler formHandler = processDefinition.getStartFormHandler();
        if (formHandler instanceof DelegateStartFormHandler) {
            DelegateStartFormHandler delegateFormHandler = (DelegateStartFormHandler) formHandler;
            formHandler = delegateFormHandler.getFormHandler();
        }
        // form handler (for a startForm) has always to extend the DefaultStartFormHandler!
        if (formHandler instanceof DefaultStartFormHandler) {
            DefaultStartFormHandler startFormHandler = (DefaultStartFormHandler) formHandler;
            formKeyExpression = startFormHandler.getFormKey();
        }
    } else {
        TaskDefinition taskDefinition = processDefinition.getTaskDefinitions().get(taskDefinitionKey);
        formKeyExpression = taskDefinition.getFormKey();
    }
    String formKey = null;
    if (formKeyExpression != null) {
        formKey = formKeyExpression.getExpressionText();
    }
    return formKey;
}
Also used : TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition) Expression(org.camunda.bpm.engine.delegate.Expression) DefaultStartFormHandler(org.camunda.bpm.engine.impl.form.handler.DefaultStartFormHandler) FormHandler(org.camunda.bpm.engine.impl.form.handler.FormHandler) DelegateStartFormHandler(org.camunda.bpm.engine.impl.form.handler.DelegateStartFormHandler) DelegateStartFormHandler(org.camunda.bpm.engine.impl.form.handler.DelegateStartFormHandler) DeploymentCache(org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache) DefaultStartFormHandler(org.camunda.bpm.engine.impl.form.handler.DefaultStartFormHandler) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 2 with Expression

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

the class SentryHandler method initializeIfPart.

protected void initializeIfPart(IfPart ifPart, CmmnSentryDeclaration sentryDeclaration, CmmnHandlerContext context) {
    if (ifPart == null) {
        return;
    }
    Collection<ConditionExpression> conditions = ifPart.getConditions();
    if (conditions.size() > 1) {
        String id = sentryDeclaration.getId();
        LOG.multipleIgnoredConditions(id);
    }
    ExpressionManager expressionManager = context.getExpressionManager();
    ConditionExpression condition = conditions.iterator().next();
    Expression conditionExpression = expressionManager.createExpression(condition.getText());
    CmmnIfPartDeclaration ifPartDeclaration = new CmmnIfPartDeclaration();
    ifPartDeclaration.setCondition(conditionExpression);
    sentryDeclaration.setIfPart(ifPartDeclaration);
}
Also used : ExpressionManager(org.camunda.bpm.engine.impl.el.ExpressionManager) CmmnIfPartDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration) Expression(org.camunda.bpm.engine.delegate.Expression) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression)

Example 3 with Expression

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

the class TaskDecorator method initializeTaskCandidateGroups.

@SuppressWarnings({ "rawtypes", "unchecked" })
protected void initializeTaskCandidateGroups(TaskEntity task, VariableScope variableScope) {
    Set<Expression> candidateGroupIdExpressions = taskDefinition.getCandidateGroupIdExpressions();
    for (Expression groupIdExpr : candidateGroupIdExpressions) {
        Object value = groupIdExpr.getValue(variableScope);
        if (value instanceof String) {
            List<String> candiates = extractCandidates((String) value);
            task.addCandidateGroups(candiates);
        } else if (value instanceof Collection) {
            task.addCandidateGroups((Collection) value);
        } else {
            throw new ProcessEngineException("Expression did not resolve to a string or collection of strings");
        }
    }
}
Also used : Expression(org.camunda.bpm.engine.delegate.Expression) Collection(java.util.Collection) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 4 with Expression

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

the class CmmnExecution method isSentryPartsSatisfied.

protected boolean isSentryPartsSatisfied(String sentryId, List<? extends CmmnSentryPart> sentryParts) {
    // if part will be evaluated in the end
    CmmnSentryPart ifPart = null;
    if (sentryParts != null && !sentryParts.isEmpty()) {
        for (CmmnSentryPart sentryPart : sentryParts) {
            if (PLAN_ITEM_ON_PART.equals(sentryPart.getType())) {
                if (!sentryPart.isSatisfied()) {
                    return false;
                }
            } else if (VARIABLE_ON_PART.equals(sentryPart.getType())) {
                if (!sentryPart.isSatisfied()) {
                    return false;
                }
            } else {
                /* IF_PART.equals(sentryPart.getType) == true */
                ifPart = sentryPart;
                // once the ifPart has been satisfied the whole sentry is satisfied
                if (ifPart.isSatisfied()) {
                    return true;
                }
            }
        }
    }
    if (ifPart != null) {
        CmmnExecution execution = ifPart.getCaseExecution();
        ensureNotNull("Case execution of sentry '" + ifPart.getSentryId() + "': is null", execution);
        CmmnActivity activity = ifPart.getCaseExecution().getActivity();
        ensureNotNull("Case execution '" + id + "': has no current activity", "activity", activity);
        CmmnSentryDeclaration sentryDeclaration = activity.getSentry(sentryId);
        ensureNotNull("Case execution '" + id + "': has no declaration for sentry '" + sentryId + "'", "sentryDeclaration", sentryDeclaration);
        CmmnIfPartDeclaration ifPartDeclaration = sentryDeclaration.getIfPart();
        ensureNotNull("Sentry declaration '" + sentryId + "' has no definied ifPart, but there should be one defined for case execution '" + id + "'.", "ifPartDeclaration", ifPartDeclaration);
        Expression condition = ifPartDeclaration.getCondition();
        ensureNotNull("A condition was expected for ifPart of Sentry declaration '" + sentryId + "' for case execution '" + id + "'.", "condition", condition);
        Object result = condition.getValue(this);
        ensureInstanceOf("condition expression returns non-Boolean", "result", result, Boolean.class);
        Boolean booleanResult = (Boolean) result;
        ifPart.setSatisfied(booleanResult);
        return booleanResult;
    }
    // ifPart then the whole sentry is satisfied.
    return true;
}
Also used : CmmnIfPartDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration) CmmnSentryDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration) Expression(org.camunda.bpm.engine.delegate.Expression) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)

Example 5 with Expression

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

the class HumanTaskItemHandler method initializeTaskDefinitionName.

protected void initializeTaskDefinitionName(CmmnElement element, TaskDefinition taskDefinition, CmmnHandlerContext context) {
    String name = getName(element);
    if (name == null) {
        HumanTask definition = getDefinition(element);
        name = definition.getName();
    }
    if (name != null) {
        ExpressionManager expressionManager = context.getExpressionManager();
        Expression nameExpression = expressionManager.createExpression(name);
        taskDefinition.setNameExpression(nameExpression);
    }
}
Also used : ExpressionManager(org.camunda.bpm.engine.impl.el.ExpressionManager) Expression(org.camunda.bpm.engine.delegate.Expression) HumanTask(org.camunda.bpm.model.cmmn.instance.HumanTask)

Aggregations

Expression (org.camunda.bpm.engine.delegate.Expression)62 ConditionExpression (org.camunda.bpm.model.cmmn.instance.ConditionExpression)18 Test (org.junit.Test)15 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)14 ExpressionManager (org.camunda.bpm.engine.impl.el.ExpressionManager)14 HumanTaskActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.HumanTaskActivityBehavior)12 TaskDefinition (org.camunda.bpm.engine.impl.task.TaskDefinition)12 HumanTask (org.camunda.bpm.model.cmmn.instance.HumanTask)8 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 CmmnIfPartDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration)4 IdentityLink (org.camunda.bpm.engine.task.IdentityLink)4 CamundaField (org.camunda.bpm.model.cmmn.instance.camunda.CamundaField)4 FieldDeclaration (org.camunda.bpm.engine.impl.bpmn.parser.FieldDeclaration)3 CaseControlRuleImpl (org.camunda.bpm.engine.impl.cmmn.behavior.CaseControlRuleImpl)3 CmmnSentryDeclaration (org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration)3 ExecutableScript (org.camunda.bpm.engine.impl.scripting.ExecutableScript)3 CamundaExpression (org.camunda.bpm.model.cmmn.instance.camunda.CamundaExpression)3 CamundaString (org.camunda.bpm.model.cmmn.instance.camunda.CamundaString)3 Collection (java.util.Collection)2