Search in sources :

Example 11 with Expression

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

the class FormValidators method createValidator.

/**
 * factory method for creating validator instances
 */
public FormFieldValidator createValidator(Element constraint, BpmnParse bpmnParse, ExpressionManager expressionManager) {
    String name = constraint.attribute("name");
    String config = constraint.attribute("config");
    if ("validator".equals(name)) {
        if (config == null || config.isEmpty()) {
            bpmnParse.addError("validator configuration needs to provide either a fully " + "qualified classname or an expression resolving to a custom FormFieldValidator implementation.", constraint);
        } else {
            if (StringUtil.isExpression(config)) {
                // expression
                Expression validatorExpression = expressionManager.createExpression(config);
                return new DelegateFormFieldValidator(validatorExpression);
            } else {
                // classname
                return new DelegateFormFieldValidator(config);
            }
        }
    } else {
        // built-in validators
        Class<? extends FormFieldValidator> validator = validators.get(name);
        if (validator != null) {
            FormFieldValidator validatorInstance = createValidatorInstance(validator);
            return validatorInstance;
        } else {
            bpmnParse.addError("Cannot find validator implementation for name '" + name + "'.", constraint);
        }
    }
    return null;
}
Also used : Expression(org.camunda.bpm.engine.delegate.Expression)

Example 12 with Expression

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

the class ScriptUtil method getScriptFormSource.

/**
 * Creates a new {@link ExecutableScript} from a source. It excepts static and dynamic sources.
 * Dynamic means that the source is an expression which will be evaluated during execution.
 *
 * @param language the language of the script
 * @param source the source code of the script or an expression which evaluates to the source code
 * @param expressionManager the expression manager to use to generate the expressions of dynamic scripts
 * @param scriptFactory the script factory used to create the script
 * @return the newly created script
 * @throws NotValidException if language is null or empty or source is null
 */
public static ExecutableScript getScriptFormSource(String language, String source, ExpressionManager expressionManager, ScriptFactory scriptFactory) {
    ensureNotEmpty(NotValidException.class, "Script language", language);
    ensureNotNull(NotValidException.class, "Script source", source);
    if (isDynamicScriptExpression(language, source)) {
        Expression sourceExpression = expressionManager.createExpression(source);
        return getScriptFromSourceExpression(language, sourceExpression, scriptFactory);
    } else {
        return getScriptFromSource(language, source, scriptFactory);
    }
}
Also used : Expression(org.camunda.bpm.engine.delegate.Expression)

Example 13 with Expression

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

the class SentryHandlerTest method testSentryWithIfPart.

@Test
public void testSentryWithIfPart() {
    // given
    IfPart ifPart = createElement(sentry, "abc", IfPart.class);
    ConditionExpression conditionExpression = createElement(ifPart, "def", ConditionExpression.class);
    Body body = createElement(conditionExpression, null, Body.class);
    String expression = "${test}";
    body.setTextContent(expression);
    // when
    CmmnSentryDeclaration sentryDeclaration = sentryHandler.handleElement(sentry, context);
    // then
    assertNotNull(sentryDeclaration);
    CmmnIfPartDeclaration ifPartDeclaration = sentryDeclaration.getIfPart();
    assertNotNull(ifPartDeclaration);
    Expression condition = ifPartDeclaration.getCondition();
    assertNotNull(condition);
    assertEquals(expression, condition.getExpressionText());
    assertTrue(sentryDeclaration.getOnParts().isEmpty());
}
Also used : CmmnIfPartDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnIfPartDeclaration) CmmnSentryDeclaration(org.camunda.bpm.engine.impl.cmmn.model.CmmnSentryDeclaration) IfPart(org.camunda.bpm.model.cmmn.instance.IfPart) Expression(org.camunda.bpm.engine.delegate.Expression) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression) Body(org.camunda.bpm.model.cmmn.instance.Body) Test(org.junit.Test)

Example 14 with Expression

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

the class HumanTaskPlanItemHandlerTest method testHumanTaskDescription.

@Test
public void testHumanTaskDescription() {
    // given
    String description = "A description";
    humanTask.setDescription(description);
    // when
    CmmnActivity activity = handler.handleElement(planItem, context);
    // then
    HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
    TaskDefinition taskDefinition = behavior.getTaskDefinition();
    Expression descriptionExpression = taskDefinition.getDescriptionExpression();
    assertNotNull(descriptionExpression);
    assertEquals(description, descriptionExpression.getExpressionText());
}
Also used : TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition) Expression(org.camunda.bpm.engine.delegate.Expression) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression) HumanTaskActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.HumanTaskActivityBehavior) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) Test(org.junit.Test)

Example 15 with Expression

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

the class HumanTaskPlanItemHandlerTest method testTaskDefinitionCandidateUsers.

@Test
public void testTaskDefinitionCandidateUsers() {
    // given
    String aCandidateUsers = "mary,john,peter";
    humanTask.setCamundaCandidateUsers(aCandidateUsers);
    // when
    CmmnActivity activity = handler.handleElement(planItem, context);
    // then
    HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
    TaskDefinition taskDefinition = behavior.getTaskDefinition();
    Set<Expression> candidateUserExpressions = taskDefinition.getCandidateUserIdExpressions();
    assertEquals(3, candidateUserExpressions.size());
    for (Expression candidateUserExpression : candidateUserExpressions) {
        String candidateUser = candidateUserExpression.getExpressionText();
        if ("mary".equals(candidateUser)) {
            assertEquals("mary", candidateUser);
        } else if ("john".equals(candidateUser)) {
            assertEquals("john", candidateUser);
        } else if ("peter".equals(candidateUser)) {
            assertEquals("peter", candidateUser);
        } else {
            fail("Unexpected candidate user: " + candidateUser);
        }
    }
}
Also used : TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition) Expression(org.camunda.bpm.engine.delegate.Expression) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression) HumanTaskActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.HumanTaskActivityBehavior) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) Test(org.junit.Test)

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