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;
}
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);
}
}
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());
}
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());
}
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);
}
}
}
Aggregations