Search in sources :

Example 11 with Expression

use of org.activiti.engine.delegate.Expression in project Activiti by Activiti.

the class SingletonDelegateExpressionBean method execute.

@Override
public void execute(DelegateExecution execution) throws Exception {
    // just a quick check to avoid creating a specific test for it
    int nrOfFieldExtensions = DelegateHelper.getFields(execution).size();
    if (nrOfFieldExtensions != 3) {
        throw new RuntimeException("Error: 3 field extensions expected, but was " + nrOfFieldExtensions);
    }
    Expression fieldAExpression = DelegateHelper.getFieldExpression(execution, "fieldA");
    Number fieldA = (Number) fieldAExpression.getValue(execution);
    Expression fieldBExpression = DelegateHelper.getFieldExpression(execution, "fieldB");
    Number fieldB = (Number) fieldBExpression.getValue(execution);
    int result = fieldA.intValue() + fieldB.intValue();
    String resultVariableName = DelegateHelper.getFieldExpression(execution, "resultVariableName").getValue(execution).toString();
    execution.setVariable(resultVariableName, result);
}
Also used : Expression(org.activiti.engine.delegate.Expression)

Example 12 with Expression

use of org.activiti.engine.delegate.Expression in project Activiti by Activiti.

the class TimerEntity method restoreExtraData.

protected void restoreExtraData(CommandContext commandContext, String jobHandlerConfiguration) {
    String embededActivityId = jobHandlerConfiguration;
    if (jobHandlerType.equalsIgnoreCase(TimerExecuteNestedActivityJobHandler.TYPE) || jobHandlerType.equalsIgnoreCase(TimerCatchIntermediateEventJobHandler.TYPE) || jobHandlerType.equalsIgnoreCase(TimerStartEventJobHandler.TYPE)) {
        embededActivityId = TimerEventHandler.getActivityIdFromConfiguration(jobHandlerConfiguration);
        String endDateExpressionString = TimerEventHandler.getEndDateFromConfiguration(jobHandlerConfiguration);
        if (endDateExpressionString != null) {
            Expression endDateExpression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(endDateExpressionString);
            String endDateString = null;
            BusinessCalendar businessCalendar = Context.getProcessEngineConfiguration().getBusinessCalendarManager().getBusinessCalendar(getBusinessCalendarName(TimerEventHandler.geCalendarNameFromConfiguration(jobHandlerConfiguration)));
            VariableScope executionEntity = null;
            if (executionId != null) {
                executionEntity = commandContext.getExecutionEntityManager().findExecutionById(executionId);
            }
            if (executionEntity == null) {
                executionEntity = NoExecutionVariableScope.getSharedInstance();
            }
            if (endDateExpression != null) {
                Object endDateValue = endDateExpression.getValue(executionEntity);
                if (endDateValue instanceof String) {
                    endDateString = (String) endDateValue;
                } else if (endDateValue instanceof Date) {
                    endDate = (Date) endDateValue;
                } else {
                    throw new ActivitiException("Timer '" + ((ExecutionEntity) 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 (endDate == null) {
                    endDate = businessCalendar.resolveEndDate(endDateString);
                }
            }
        }
    }
    if (processDefinitionId != null) {
        ProcessDefinition definition = commandContext.getProcessEngineConfiguration().getDeploymentManager().findDeployedProcessDefinitionById(processDefinitionId);
        maxIterations = checkStartEventDefinitions(definition, embededActivityId);
        if (maxIterations <= 1) {
            maxIterations = checkBoundaryEventsDefinitions(definition, embededActivityId);
        }
    } else {
        maxIterations = 1;
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Expression(org.activiti.engine.delegate.Expression) CycleBusinessCalendar(org.activiti.engine.impl.calendar.CycleBusinessCalendar) BusinessCalendar(org.activiti.engine.impl.calendar.BusinessCalendar) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) VariableScope(org.activiti.engine.delegate.VariableScope) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) Date(java.util.Date)

Example 13 with Expression

use of org.activiti.engine.delegate.Expression in project Activiti by Activiti.

the class SequenceFlowParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, SequenceFlow sequenceFlow) {
    ScopeImpl scope = bpmnParse.getCurrentScope();
    ActivityImpl sourceActivity = scope.findActivity(sequenceFlow.getSourceRef());
    ActivityImpl destinationActivity = scope.findActivity(sequenceFlow.getTargetRef());
    Expression skipExpression;
    if (StringUtils.isNotEmpty(sequenceFlow.getSkipExpression())) {
        ExpressionManager expressionManager = bpmnParse.getExpressionManager();
        skipExpression = expressionManager.createExpression(sequenceFlow.getSkipExpression());
    } else {
        skipExpression = null;
    }
    TransitionImpl transition = sourceActivity.createOutgoingTransition(sequenceFlow.getId(), skipExpression);
    bpmnParse.getSequenceFlows().put(sequenceFlow.getId(), transition);
    transition.setProperty("name", sequenceFlow.getName());
    transition.setProperty("documentation", sequenceFlow.getDocumentation());
    transition.setDestination(destinationActivity);
    if (StringUtils.isNotEmpty(sequenceFlow.getConditionExpression())) {
        Condition expressionCondition = new UelExpressionCondition(sequenceFlow.getConditionExpression());
        transition.setProperty(PROPERTYNAME_CONDITION_TEXT, sequenceFlow.getConditionExpression());
        transition.setProperty(PROPERTYNAME_CONDITION, expressionCondition);
    }
    createExecutionListenersOnTransition(bpmnParse, sequenceFlow.getExecutionListeners(), transition);
}
Also used : UelExpressionCondition(org.activiti.engine.impl.el.UelExpressionCondition) Condition(org.activiti.engine.impl.Condition) ExpressionManager(org.activiti.engine.impl.el.ExpressionManager) TransitionImpl(org.activiti.engine.impl.pvm.process.TransitionImpl) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) Expression(org.activiti.engine.delegate.Expression) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl) UelExpressionCondition(org.activiti.engine.impl.el.UelExpressionCondition)

Example 14 with Expression

use of org.activiti.engine.delegate.Expression in project Activiti by Activiti.

the class UserTaskParseHandler method parseTaskDefinition.

public TaskDefinition parseTaskDefinition(BpmnParse bpmnParse, UserTask userTask, String taskDefinitionKey, ProcessDefinitionEntity processDefinition) {
    TaskFormHandler taskFormHandler = new DefaultTaskFormHandler();
    taskFormHandler.parseConfiguration(userTask.getFormProperties(), userTask.getFormKey(), bpmnParse.getDeployment(), processDefinition);
    TaskDefinition taskDefinition = new TaskDefinition(taskFormHandler);
    taskDefinition.setKey(taskDefinitionKey);
    processDefinition.getTaskDefinitions().put(taskDefinitionKey, taskDefinition);
    ExpressionManager expressionManager = bpmnParse.getExpressionManager();
    if (StringUtils.isNotEmpty(userTask.getName())) {
        taskDefinition.setNameExpression(expressionManager.createExpression(userTask.getName()));
    }
    if (StringUtils.isNotEmpty(userTask.getDocumentation())) {
        taskDefinition.setDescriptionExpression(expressionManager.createExpression(userTask.getDocumentation()));
    }
    if (StringUtils.isNotEmpty(userTask.getAssignee())) {
        taskDefinition.setAssigneeExpression(expressionManager.createExpression(userTask.getAssignee()));
    }
    if (StringUtils.isNotEmpty(userTask.getOwner())) {
        taskDefinition.setOwnerExpression(expressionManager.createExpression(userTask.getOwner()));
    }
    for (String candidateUser : userTask.getCandidateUsers()) {
        taskDefinition.addCandidateUserIdExpression(expressionManager.createExpression(candidateUser));
    }
    for (String candidateGroup : userTask.getCandidateGroups()) {
        taskDefinition.addCandidateGroupIdExpression(expressionManager.createExpression(candidateGroup));
    }
    // Task listeners
    for (ActivitiListener taskListener : userTask.getTaskListeners()) {
        taskDefinition.addTaskListener(taskListener.getEvent(), createTaskListener(bpmnParse, taskListener, userTask.getId()));
    }
    // Due date
    if (StringUtils.isNotEmpty(userTask.getDueDate())) {
        taskDefinition.setDueDateExpression(expressionManager.createExpression(userTask.getDueDate()));
    }
    // Business calendar name
    if (StringUtils.isNotEmpty(userTask.getBusinessCalendarName())) {
        taskDefinition.setBusinessCalendarNameExpression(expressionManager.createExpression(userTask.getBusinessCalendarName()));
    } else {
        taskDefinition.setBusinessCalendarNameExpression(expressionManager.createExpression(DueDateBusinessCalendar.NAME));
    }
    // Category
    if (StringUtils.isNotEmpty(userTask.getCategory())) {
        taskDefinition.setCategoryExpression(expressionManager.createExpression(userTask.getCategory()));
    }
    // Priority
    if (StringUtils.isNotEmpty(userTask.getPriority())) {
        taskDefinition.setPriorityExpression(expressionManager.createExpression(userTask.getPriority()));
    }
    if (StringUtils.isNotEmpty(userTask.getFormKey())) {
        taskDefinition.setFormKeyExpression(expressionManager.createExpression(userTask.getFormKey()));
    }
    // CustomUserIdentityLinks
    for (String customUserIdentityLinkType : userTask.getCustomUserIdentityLinks().keySet()) {
        Set<Expression> userIdentityLinkExpression = new HashSet<Expression>();
        for (String userIdentityLink : userTask.getCustomUserIdentityLinks().get(customUserIdentityLinkType)) {
            userIdentityLinkExpression.add(expressionManager.createExpression(userIdentityLink));
        }
        taskDefinition.addCustomUserIdentityLinkExpression(customUserIdentityLinkType, userIdentityLinkExpression);
    }
    // CustomGroupIdentityLinks
    for (String customGroupIdentityLinkType : userTask.getCustomGroupIdentityLinks().keySet()) {
        Set<Expression> groupIdentityLinkExpression = new HashSet<Expression>();
        for (String groupIdentityLink : userTask.getCustomGroupIdentityLinks().get(customGroupIdentityLinkType)) {
            groupIdentityLinkExpression.add(expressionManager.createExpression(groupIdentityLink));
        }
        taskDefinition.addCustomGroupIdentityLinkExpression(customGroupIdentityLinkType, groupIdentityLinkExpression);
    }
    if (StringUtils.isNotEmpty(userTask.getSkipExpression())) {
        taskDefinition.setSkipExpression(expressionManager.createExpression(userTask.getSkipExpression()));
    }
    return taskDefinition;
}
Also used : ExpressionManager(org.activiti.engine.impl.el.ExpressionManager) TaskDefinition(org.activiti.engine.impl.task.TaskDefinition) TaskFormHandler(org.activiti.engine.impl.form.TaskFormHandler) DefaultTaskFormHandler(org.activiti.engine.impl.form.DefaultTaskFormHandler) Expression(org.activiti.engine.delegate.Expression) DefaultTaskFormHandler(org.activiti.engine.impl.form.DefaultTaskFormHandler) ActivitiListener(org.activiti.bpmn.model.ActivitiListener) HashSet(java.util.HashSet)

Example 15 with Expression

use of org.activiti.engine.delegate.Expression in project Activiti by Activiti.

the class UserTaskActivityBehavior method handleAssignments.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void handleAssignments(Expression assigneeExpression, Expression ownerExpression, Set<Expression> candidateUserExpressions, Set<Expression> candidateGroupExpressions, TaskEntity task, ActivityExecution execution) {
    if (assigneeExpression != null) {
        Object assigneeExpressionValue = assigneeExpression.getValue(execution);
        String assigneeValue = null;
        if (assigneeExpressionValue != null) {
            assigneeValue = assigneeExpressionValue.toString();
        }
        task.setAssignee(assigneeValue, true, false);
    }
    if (ownerExpression != null) {
        Object ownerExpressionValue = ownerExpression.getValue(execution);
        String ownerValue = null;
        if (ownerExpressionValue != null) {
            ownerValue = ownerExpressionValue.toString();
        }
        task.setOwner(ownerValue);
    }
    if (candidateGroupExpressions != null && !candidateGroupExpressions.isEmpty()) {
        for (Expression groupIdExpr : candidateGroupExpressions) {
            Object value = groupIdExpr.getValue(execution);
            if (value instanceof String) {
                List<String> candidates = extractCandidates((String) value);
                task.addCandidateGroups(candidates);
            } else if (value instanceof Collection) {
                task.addCandidateGroups((Collection) value);
            } else {
                throw new ActivitiIllegalArgumentException("Expression did not resolve to a string or collection of strings");
            }
        }
    }
    if (candidateUserExpressions != null && !candidateUserExpressions.isEmpty()) {
        for (Expression userIdExpr : candidateUserExpressions) {
            Object value = userIdExpr.getValue(execution);
            if (value instanceof String) {
                List<String> candiates = extractCandidates((String) value);
                task.addCandidateUsers(candiates);
            } else if (value instanceof Collection) {
                task.addCandidateUsers((Collection) value);
            } else {
                throw new ActivitiException("Expression did not resolve to a string or collection of strings");
            }
        }
    }
    if (!taskDefinition.getCustomUserIdentityLinkExpressions().isEmpty()) {
        Map<String, Set<Expression>> identityLinks = taskDefinition.getCustomUserIdentityLinkExpressions();
        for (String identityLinkType : identityLinks.keySet()) {
            for (Expression idExpression : identityLinks.get(identityLinkType)) {
                Object value = idExpression.getValue(execution);
                if (value instanceof String) {
                    List<String> userIds = extractCandidates((String) value);
                    for (String userId : userIds) {
                        task.addUserIdentityLink(userId, identityLinkType);
                    }
                } else if (value instanceof Collection) {
                    Iterator userIdSet = ((Collection) value).iterator();
                    while (userIdSet.hasNext()) {
                        task.addUserIdentityLink((String) userIdSet.next(), identityLinkType);
                    }
                } else {
                    throw new ActivitiException("Expression did not resolve to a string or collection of strings");
                }
            }
        }
    }
    if (!taskDefinition.getCustomGroupIdentityLinkExpressions().isEmpty()) {
        Map<String, Set<Expression>> identityLinks = taskDefinition.getCustomGroupIdentityLinkExpressions();
        for (String identityLinkType : identityLinks.keySet()) {
            for (Expression idExpression : identityLinks.get(identityLinkType)) {
                Object value = idExpression.getValue(execution);
                if (value instanceof String) {
                    List<String> groupIds = extractCandidates((String) value);
                    for (String groupId : groupIds) {
                        task.addGroupIdentityLink(groupId, identityLinkType);
                    }
                } else if (value instanceof Collection) {
                    Iterator groupIdSet = ((Collection) value).iterator();
                    while (groupIdSet.hasNext()) {
                        task.addGroupIdentityLink((String) groupIdSet.next(), identityLinkType);
                    }
                } else {
                    throw new ActivitiException("Expression did not resolve to a string or collection of strings");
                }
            }
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) HashSet(java.util.HashSet) Set(java.util.Set) Expression(org.activiti.engine.delegate.Expression) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Iterator(java.util.Iterator) Collection(java.util.Collection)

Aggregations

Expression (org.activiti.engine.delegate.Expression)20 ActivitiException (org.activiti.engine.ActivitiException)7 ExpressionManager (org.activiti.engine.impl.el.ExpressionManager)5 Condition (org.activiti.engine.impl.Condition)4 ArrayList (java.util.ArrayList)3 PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 SimpleDataInputAssociation (org.activiti.engine.impl.bpmn.data.SimpleDataInputAssociation)2 MessageImplicitDataOutputAssociation (org.activiti.engine.impl.bpmn.webservice.MessageImplicitDataOutputAssociation)2 BusinessCalendar (org.activiti.engine.impl.calendar.BusinessCalendar)2 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)1 IOParameter (org.activiti.bpmn.model.IOParameter)1