Search in sources :

Example 6 with Expression

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

the class UelExpressionCondition method evaluate.

public boolean evaluate(String sequenceFlowId, DelegateExecution execution) {
    String conditionExpression = null;
    if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
        ObjectNode elementProperties = Context.getBpmnOverrideElementProperties(sequenceFlowId, execution.getProcessDefinitionId());
        conditionExpression = getActiveValue(initialConditionExpression, DynamicBpmnConstants.SEQUENCE_FLOW_CONDITION, elementProperties);
    } else {
        conditionExpression = initialConditionExpression;
    }
    Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(conditionExpression);
    Object result = expression.getValue(execution);
    if (result == null) {
        throw new ActivitiException("condition expression returns null");
    }
    if (!(result instanceof Boolean)) {
        throw new ActivitiException("condition expression returns non-Boolean: " + result + " (" + result.getClass().getName() + ")");
    }
    return (Boolean) result;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Expression(org.activiti.engine.delegate.Expression)

Example 7 with Expression

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

the class DefaultFormHandler method parseConfiguration.

public void parseConfiguration(List<org.activiti.bpmn.model.FormProperty> formProperties, String formKey, DeploymentEntity deployment, ProcessDefinitionEntity processDefinition) {
    this.deploymentId = deployment.getId();
    ExpressionManager expressionManager = Context.getProcessEngineConfiguration().getExpressionManager();
    if (StringUtils.isNotEmpty(formKey)) {
        this.formKey = expressionManager.createExpression(formKey);
    }
    FormTypes formTypes = Context.getProcessEngineConfiguration().getFormTypes();
    for (org.activiti.bpmn.model.FormProperty formProperty : formProperties) {
        FormPropertyHandler formPropertyHandler = new FormPropertyHandler();
        formPropertyHandler.setId(formProperty.getId());
        formPropertyHandler.setName(formProperty.getName());
        AbstractFormType type = formTypes.parseFormPropertyType(formProperty);
        formPropertyHandler.setType(type);
        formPropertyHandler.setRequired(formProperty.isRequired());
        formPropertyHandler.setReadable(formProperty.isReadable());
        formPropertyHandler.setWritable(formProperty.isWriteable());
        formPropertyHandler.setVariableName(formProperty.getVariable());
        if (StringUtils.isNotEmpty(formProperty.getExpression())) {
            Expression expression = expressionManager.createExpression(formProperty.getExpression());
            formPropertyHandler.setVariableExpression(expression);
        }
        if (StringUtils.isNotEmpty(formProperty.getDefaultExpression())) {
            Expression defaultExpression = expressionManager.createExpression(formProperty.getDefaultExpression());
            formPropertyHandler.setDefaultExpression(defaultExpression);
        }
        formPropertyHandlers.add(formPropertyHandler);
    }
}
Also used : ExpressionManager(org.activiti.engine.impl.el.ExpressionManager) Expression(org.activiti.engine.delegate.Expression) AbstractFormType(org.activiti.engine.form.AbstractFormType)

Example 8 with Expression

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

the class UserTaskActivityBehavior method getActiveValueSet.

protected Set<Expression> getActiveValueSet(Set<Expression> originalValues, String propertyName, ObjectNode taskElementProperties) {
    Set<Expression> activeValues = originalValues;
    if (taskElementProperties != null) {
        JsonNode overrideValuesNode = taskElementProperties.get(propertyName);
        if (overrideValuesNode != null) {
            if (overrideValuesNode.isNull() || overrideValuesNode.isArray() == false || overrideValuesNode.size() == 0) {
                activeValues = null;
            } else {
                ExpressionManager expressionManager = Context.getProcessEngineConfiguration().getExpressionManager();
                activeValues = new HashSet<Expression>();
                for (JsonNode valueNode : overrideValuesNode) {
                    activeValues.add(expressionManager.createExpression(valueNode.asText()));
                }
            }
        }
    }
    return activeValues;
}
Also used : ExpressionManager(org.activiti.engine.impl.el.ExpressionManager) Expression(org.activiti.engine.delegate.Expression) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 9 with Expression

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

the class UserTaskActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    TaskEntity task = TaskEntity.createAndInsert(execution);
    task.setExecution(execution);
    Expression activeNameExpression = null;
    Expression activeDescriptionExpression = null;
    Expression activeDueDateExpression = null;
    Expression activePriorityExpression = null;
    Expression activeCategoryExpression = null;
    Expression activeFormKeyExpression = null;
    Expression activeSkipExpression = null;
    Expression activeAssigneeExpression = null;
    Expression activeOwnerExpression = null;
    Set<Expression> activeCandidateUserExpressions = null;
    Set<Expression> activeCandidateGroupExpressions = null;
    if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
        ObjectNode taskElementProperties = Context.getBpmnOverrideElementProperties(userTaskId, execution.getProcessDefinitionId());
        activeNameExpression = getActiveValue(taskDefinition.getNameExpression(), DynamicBpmnConstants.USER_TASK_NAME, taskElementProperties);
        taskDefinition.setNameExpression(activeNameExpression);
        activeDescriptionExpression = getActiveValue(taskDefinition.getDescriptionExpression(), DynamicBpmnConstants.USER_TASK_DESCRIPTION, taskElementProperties);
        taskDefinition.setDescriptionExpression(activeDescriptionExpression);
        activeDueDateExpression = getActiveValue(taskDefinition.getDueDateExpression(), DynamicBpmnConstants.USER_TASK_DUEDATE, taskElementProperties);
        taskDefinition.setDueDateExpression(activeDueDateExpression);
        activePriorityExpression = getActiveValue(taskDefinition.getPriorityExpression(), DynamicBpmnConstants.USER_TASK_PRIORITY, taskElementProperties);
        taskDefinition.setPriorityExpression(activePriorityExpression);
        activeCategoryExpression = getActiveValue(taskDefinition.getCategoryExpression(), DynamicBpmnConstants.USER_TASK_CATEGORY, taskElementProperties);
        taskDefinition.setCategoryExpression(activeCategoryExpression);
        activeFormKeyExpression = getActiveValue(taskDefinition.getFormKeyExpression(), DynamicBpmnConstants.USER_TASK_FORM_KEY, taskElementProperties);
        taskDefinition.setFormKeyExpression(activeFormKeyExpression);
        activeSkipExpression = getActiveValue(taskDefinition.getSkipExpression(), DynamicBpmnConstants.TASK_SKIP_EXPRESSION, taskElementProperties);
        taskDefinition.setSkipExpression(activeSkipExpression);
        activeAssigneeExpression = getActiveValue(taskDefinition.getAssigneeExpression(), DynamicBpmnConstants.USER_TASK_ASSIGNEE, taskElementProperties);
        taskDefinition.setAssigneeExpression(activeAssigneeExpression);
        activeOwnerExpression = getActiveValue(taskDefinition.getOwnerExpression(), DynamicBpmnConstants.USER_TASK_OWNER, taskElementProperties);
        taskDefinition.setOwnerExpression(activeOwnerExpression);
        activeCandidateUserExpressions = getActiveValueSet(taskDefinition.getCandidateUserIdExpressions(), DynamicBpmnConstants.USER_TASK_CANDIDATE_USERS, taskElementProperties);
        taskDefinition.setCandidateUserIdExpressions(activeCandidateUserExpressions);
        activeCandidateGroupExpressions = getActiveValueSet(taskDefinition.getCandidateGroupIdExpressions(), DynamicBpmnConstants.USER_TASK_CANDIDATE_GROUPS, taskElementProperties);
        taskDefinition.setCandidateGroupIdExpressions(activeCandidateGroupExpressions);
    } else {
        activeNameExpression = taskDefinition.getNameExpression();
        activeDescriptionExpression = taskDefinition.getDescriptionExpression();
        activeDueDateExpression = taskDefinition.getDueDateExpression();
        activePriorityExpression = taskDefinition.getPriorityExpression();
        activeCategoryExpression = taskDefinition.getCategoryExpression();
        activeFormKeyExpression = taskDefinition.getFormKeyExpression();
        activeSkipExpression = taskDefinition.getSkipExpression();
        activeAssigneeExpression = taskDefinition.getAssigneeExpression();
        activeOwnerExpression = taskDefinition.getOwnerExpression();
        activeCandidateUserExpressions = taskDefinition.getCandidateUserIdExpressions();
        activeCandidateGroupExpressions = taskDefinition.getCandidateGroupIdExpressions();
    }
    task.setTaskDefinition(taskDefinition);
    if (activeNameExpression != null) {
        String name = null;
        try {
            name = (String) activeNameExpression.getValue(execution);
        } catch (ActivitiException e) {
            name = activeNameExpression.getExpressionText();
            LOGGER.warn("property not found in task name expression " + e.getMessage());
        }
        task.setName(name);
    }
    if (activeDescriptionExpression != null) {
        String description = null;
        try {
            description = (String) activeDescriptionExpression.getValue(execution);
        } catch (ActivitiException e) {
            description = activeDescriptionExpression.getExpressionText();
            LOGGER.warn("property not found in task description expression " + e.getMessage());
        }
        task.setDescription(description);
    }
    if (activeDueDateExpression != null) {
        Object dueDate = activeDueDateExpression.getValue(execution);
        if (dueDate != null) {
            if (dueDate instanceof Date) {
                task.setDueDate((Date) dueDate);
            } else if (dueDate instanceof String) {
                BusinessCalendar businessCalendar = Context.getProcessEngineConfiguration().getBusinessCalendarManager().getBusinessCalendar(taskDefinition.getBusinessCalendarNameExpression().getValue(execution).toString());
                task.setDueDate(businessCalendar.resolveDuedate((String) dueDate));
            } else {
                throw new ActivitiIllegalArgumentException("Due date expression does not resolve to a Date or Date string: " + activeDueDateExpression.getExpressionText());
            }
        }
    }
    if (activePriorityExpression != null) {
        final Object priority = activePriorityExpression.getValue(execution);
        if (priority != null) {
            if (priority instanceof String) {
                try {
                    task.setPriority(Integer.valueOf((String) priority));
                } catch (NumberFormatException e) {
                    throw new ActivitiIllegalArgumentException("Priority does not resolve to a number: " + priority, e);
                }
            } else if (priority instanceof Number) {
                task.setPriority(((Number) priority).intValue());
            } else {
                throw new ActivitiIllegalArgumentException("Priority expression does not resolve to a number: " + activePriorityExpression.getExpressionText());
            }
        }
    }
    if (activeCategoryExpression != null) {
        final Object category = activeCategoryExpression.getValue(execution);
        if (category != null) {
            if (category instanceof String) {
                task.setCategory((String) category);
            } else {
                throw new ActivitiIllegalArgumentException("Category expression does not resolve to a string: " + activeCategoryExpression.getExpressionText());
            }
        }
    }
    if (activeFormKeyExpression != null) {
        final Object formKey = activeFormKeyExpression.getValue(execution);
        if (formKey != null) {
            if (formKey instanceof String) {
                task.setFormKey((String) formKey);
            } else {
                throw new ActivitiIllegalArgumentException("FormKey expression does not resolve to a string: " + activeFormKeyExpression.getExpressionText());
            }
        }
    }
    boolean skipUserTask = SkipExpressionUtil.isSkipExpressionEnabled(execution, activeSkipExpression) && SkipExpressionUtil.shouldSkipFlowElement(execution, activeSkipExpression);
    if (!skipUserTask) {
        handleAssignments(activeAssigneeExpression, activeOwnerExpression, activeCandidateUserExpressions, activeCandidateGroupExpressions, task, execution);
    }
    task.fireEvent(TaskListener.EVENTNAME_CREATE);
    // All properties set, now firing 'create' events
    if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_CREATED, task));
    }
    if (skipUserTask) {
        task.complete(null, false);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Date(java.util.Date) Expression(org.activiti.engine.delegate.Expression) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) DueDateBusinessCalendar(org.activiti.engine.impl.calendar.DueDateBusinessCalendar) BusinessCalendar(org.activiti.engine.impl.calendar.BusinessCalendar)

Example 10 with Expression

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

the class ExclusiveGatewayActivityBehavior method leave.

/**
   * The default behaviour of BPMN, taking every outgoing sequence flow
   * (where the condition evaluates to true), is not valid for an exclusive
   * gateway. 
   * 
   * Hence, this behaviour is overriden and replaced by the correct behavior:
   * selecting the first sequence flow which condition evaluates to true
   * (or which hasn't got a condition) and leaving the activity through that
   * sequence flow. 
   * 
   * If no sequence flow is selected (ie all conditions evaluate to false),
   * then the default sequence flow is taken (if defined).
   */
@Override
protected void leave(ActivityExecution execution) {
    if (log.isDebugEnabled()) {
        log.debug("Leaving activity '{}'", execution.getActivity().getId());
    }
    PvmTransition outgoingSeqFlow = null;
    String defaultSequenceFlow = (String) execution.getActivity().getProperty("default");
    Iterator<PvmTransition> transitionIterator = execution.getActivity().getOutgoingTransitions().iterator();
    while (outgoingSeqFlow == null && transitionIterator.hasNext()) {
        PvmTransition seqFlow = transitionIterator.next();
        Expression skipExpression = seqFlow.getSkipExpression();
        if (!SkipExpressionUtil.isSkipExpressionEnabled(execution, skipExpression)) {
            Condition condition = (Condition) seqFlow.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
            if ((condition == null && (defaultSequenceFlow == null || !defaultSequenceFlow.equals(seqFlow.getId()))) || (condition != null && condition.evaluate(seqFlow.getId(), execution))) {
                if (log.isDebugEnabled()) {
                    log.debug("Sequence flow '{}'selected as outgoing sequence flow.", seqFlow.getId());
                }
                outgoingSeqFlow = seqFlow;
            }
        } else if (SkipExpressionUtil.shouldSkipFlowElement(execution, skipExpression)) {
            outgoingSeqFlow = seqFlow;
        }
    }
    if (outgoingSeqFlow != null) {
        execution.take(outgoingSeqFlow);
    } else {
        if (defaultSequenceFlow != null) {
            PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
            if (defaultTransition != null) {
                execution.take(defaultTransition);
            } else {
                throw new ActivitiException("Default sequence flow '" + defaultSequenceFlow + "' not found");
            }
        } else {
            //No sequence flow could be found, not even a default one
            throw new ActivitiException("No outgoing sequence flow of the exclusive gateway '" + execution.getActivity().getId() + "' could be selected for continuing the process");
        }
    }
}
Also used : Condition(org.activiti.engine.impl.Condition) ActivitiException(org.activiti.engine.ActivitiException) Expression(org.activiti.engine.delegate.Expression) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition)

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