Search in sources :

Example 26 with Expression

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

the class TestTaskListener method notify.

@Override
public void notify(DelegateTask delegateTask) {
    Expression inputExpression = DelegateHelper.getFieldExpression(delegateTask, "input");
    Number input = (Number) inputExpression.getValue(delegateTask);
    int result = input.intValue() / 2;
    Expression resultVarExpression = DelegateHelper.getFieldExpression(delegateTask, "resultVar");
    delegateTask.setVariable(resultVarExpression.getValue(delegateTask).toString(), result);
}
Also used : Expression(org.activiti.engine.delegate.Expression)

Example 27 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) {
    // 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 28 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)

Example 29 with Expression

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

the class BpmnDeployer method addAuthorizationsFromIterator.

private void addAuthorizationsFromIterator(Set<Expression> exprSet, ProcessDefinitionEntity processDefinition, ExprType exprType) {
    if (exprSet != null) {
        Iterator<Expression> iterator = exprSet.iterator();
        while (iterator.hasNext()) {
            Expression expr = (Expression) iterator.next();
            IdentityLinkEntity identityLink = new IdentityLinkEntity();
            identityLink.setProcessDef(processDefinition);
            if (exprType.equals(ExprType.USER)) {
                identityLink.setUserId(expr.toString());
            } else if (exprType.equals(ExprType.GROUP)) {
                identityLink.setGroupId(expr.toString());
            }
            identityLink.setType(IdentityLinkType.CANDIDATE);
            identityLink.insert();
        }
    }
}
Also used : IdentityLinkEntity(org.activiti.engine.impl.persistence.entity.IdentityLinkEntity) Expression(org.activiti.engine.delegate.Expression)

Example 30 with Expression

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

the class BpmnActivityBehavior method performOutgoingBehavior.

/**
   * Actual implementation of leaving an activity.
   * 
   * @param execution
   *          The current execution context
   * @param checkConditions
   *          Whether or not to check conditions before determining whether or
   *          not to take a transition.
   * @param throwExceptionIfExecutionStuck
   *          If true, an {@link ActivitiException} will be thrown in case no
   *          transition could be found to leave the activity.
   */
protected void performOutgoingBehavior(ActivityExecution execution, boolean checkConditions, boolean throwExceptionIfExecutionStuck, List<ActivityExecution> reusableExecutions) {
    if (log.isDebugEnabled()) {
        log.debug("Leaving activity '{}'", execution.getActivity().getId());
    }
    String defaultSequenceFlow = (String) execution.getActivity().getProperty("default");
    List<PvmTransition> transitionsToTake = new ArrayList<PvmTransition>();
    List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
    for (PvmTransition outgoingTransition : outgoingTransitions) {
        Expression skipExpression = outgoingTransition.getSkipExpression();
        if (!SkipExpressionUtil.isSkipExpressionEnabled(execution, skipExpression)) {
            if (defaultSequenceFlow == null || !outgoingTransition.getId().equals(defaultSequenceFlow)) {
                Condition condition = (Condition) outgoingTransition.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
                if (condition == null || !checkConditions || condition.evaluate(outgoingTransition.getId(), execution)) {
                    transitionsToTake.add(outgoingTransition);
                }
            }
        } else if (SkipExpressionUtil.shouldSkipFlowElement(execution, skipExpression)) {
            transitionsToTake.add(outgoingTransition);
        }
    }
    if (transitionsToTake.size() == 1) {
        execution.take(transitionsToTake.get(0));
    } else if (transitionsToTake.size() >= 1) {
        execution.inactivate();
        if (reusableExecutions == null || reusableExecutions.isEmpty()) {
            execution.takeAll(transitionsToTake, Arrays.asList(execution));
        } else {
            execution.takeAll(transitionsToTake, reusableExecutions);
        }
    } else {
        if (defaultSequenceFlow != null) {
            PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
            if (defaultTransition != null) {
                execution.take(defaultTransition);
            } else {
                throw new ActivitiException("Default sequence flow '" + defaultSequenceFlow + "' could not be not found");
            }
        } else {
            Object isForCompensation = execution.getActivity().getProperty(BpmnParse.PROPERTYNAME_IS_FOR_COMPENSATION);
            if (isForCompensation != null && (Boolean) isForCompensation) {
                if (execution instanceof ExecutionEntity) {
                    Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) execution);
                }
                InterpretableExecution parentExecution = (InterpretableExecution) execution.getParent();
                ((InterpretableExecution) execution).remove();
                parentExecution.signal("compensationDone", null);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("No outgoing sequence flow found for {}. Ending execution.", execution.getActivity().getId());
                }
                execution.end();
                if (throwExceptionIfExecutionStuck) {
                    throw new ActivitiException("No outgoing sequence flow of the inclusive gateway '" + execution.getActivity().getId() + "' could be selected for continuing the process");
                }
            }
        }
    }
}
Also used : Condition(org.activiti.engine.impl.Condition) ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Expression(org.activiti.engine.delegate.Expression) ArrayList(java.util.ArrayList) InterpretableExecution(org.activiti.engine.impl.pvm.runtime.InterpretableExecution) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition)

Aggregations

Expression (org.activiti.engine.delegate.Expression)61 ActivitiException (org.activiti.engine.ActivitiException)17 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)13 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)12 Test (org.junit.Test)12 Test (org.junit.jupiter.api.Test)12 ExpressionManager (org.activiti.engine.impl.el.ExpressionManager)11 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)8 Condition (org.activiti.engine.impl.Condition)6 Date (java.util.Date)5 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)5 BusinessCalendar (org.activiti.engine.impl.calendar.BusinessCalendar)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)4 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ArrayList (java.util.ArrayList)3 VariableScope (org.activiti.engine.delegate.VariableScope)3 CycleBusinessCalendar (org.activiti.engine.impl.calendar.CycleBusinessCalendar)3 DueDateBusinessCalendar (org.activiti.engine.impl.calendar.DueDateBusinessCalendar)3