Search in sources :

Example 16 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 17 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)

Example 18 with Expression

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

the class BusinessRuleTaskActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) execution.getEngineServices().getProcessEngineConfiguration();
    ProcessDefinition processDefinition = processEngineConfiguration.getDeploymentManager().findDeployedProcessDefinitionById(execution.getProcessDefinitionId());
    String deploymentId = processDefinition.getDeploymentId();
    KnowledgeBase knowledgeBase = RulesHelper.findKnowledgeBaseByDeploymentId(deploymentId);
    StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession();
    if (variablesInputExpressions != null) {
        Iterator<Expression> itVariable = variablesInputExpressions.iterator();
        while (itVariable.hasNext()) {
            Expression variable = itVariable.next();
            ksession.insert(variable.getValue(execution));
        }
    }
    if (!rulesExpressions.isEmpty()) {
        RulesAgendaFilter filter = new RulesAgendaFilter();
        Iterator<Expression> itRuleNames = rulesExpressions.iterator();
        while (itRuleNames.hasNext()) {
            Expression ruleName = itRuleNames.next();
            filter.addSuffic(ruleName.getValue(execution).toString());
        }
        filter.setAccept(!exclude);
        ksession.fireAllRules(filter);
    } else {
        ksession.fireAllRules();
    }
    Collection<Object> ruleOutputObjects = ksession.getObjects();
    if (ruleOutputObjects != null && !ruleOutputObjects.isEmpty()) {
        Collection<Object> outputVariables = new ArrayList<Object>();
        for (Object object : ruleOutputObjects) {
            outputVariables.add(object);
        }
        execution.setVariable(resultVariable, outputVariables);
    }
    ksession.dispose();
    leave(execution);
}
Also used : KnowledgeBase(org.drools.KnowledgeBase) Expression(org.activiti.engine.delegate.Expression) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) RulesAgendaFilter(org.activiti.engine.impl.rules.RulesAgendaFilter) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)

Example 19 with Expression

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

the class DefaultActivityBehaviorFactory method createCallActivityBehavior.

// Call activity
public CallActivityBehavior createCallActivityBehavior(CallActivity callActivity) {
    String expressionRegex = "\\$+\\{+.+\\}";
    CallActivityBehavior callActivityBehaviour = null;
    if (StringUtils.isNotEmpty(callActivity.getCalledElement()) && callActivity.getCalledElement().matches(expressionRegex)) {
        callActivityBehaviour = new CallActivityBehavior(expressionManager.createExpression(callActivity.getCalledElement()), callActivity.getMapExceptions());
    } else {
        callActivityBehaviour = new CallActivityBehavior(callActivity.getCalledElement(), callActivity.getMapExceptions());
    }
    callActivityBehaviour.setInheritVariables(callActivity.isInheritVariables());
    for (IOParameter ioParameter : callActivity.getInParameters()) {
        if (StringUtils.isNotEmpty(ioParameter.getSourceExpression())) {
            Expression expression = expressionManager.createExpression(ioParameter.getSourceExpression().trim());
            callActivityBehaviour.addDataInputAssociation(new SimpleDataInputAssociation(expression, ioParameter.getTarget()));
        } else {
            callActivityBehaviour.addDataInputAssociation(new SimpleDataInputAssociation(ioParameter.getSource(), ioParameter.getTarget()));
        }
    }
    for (IOParameter ioParameter : callActivity.getOutParameters()) {
        if (StringUtils.isNotEmpty(ioParameter.getSourceExpression())) {
            Expression expression = expressionManager.createExpression(ioParameter.getSourceExpression().trim());
            callActivityBehaviour.addDataOutputAssociation(new MessageImplicitDataOutputAssociation(ioParameter.getTarget(), expression));
        } else {
            callActivityBehaviour.addDataOutputAssociation(new MessageImplicitDataOutputAssociation(ioParameter.getTarget(), ioParameter.getSource()));
        }
    }
    return callActivityBehaviour;
}
Also used : MessageImplicitDataOutputAssociation(org.activiti.engine.impl.bpmn.webservice.MessageImplicitDataOutputAssociation) IOParameter(org.activiti.bpmn.model.IOParameter) Expression(org.activiti.engine.delegate.Expression) SimpleDataInputAssociation(org.activiti.engine.impl.bpmn.data.SimpleDataInputAssociation) CallActivityBehavior(org.activiti.engine.impl.bpmn.behavior.CallActivityBehavior)

Example 20 with Expression

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

the class InclusiveGatewayActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    execution.inactivate();
    lockConcurrentRoot(execution);
    PvmActivity activity = execution.getActivity();
    if (!activeConcurrentExecutionsExist(execution)) {
        if (log.isDebugEnabled()) {
            log.debug("inclusive gateway '{}' activates", activity.getId());
        }
        List<ActivityExecution> joinedExecutions = execution.findInactiveConcurrentExecutions(activity);
        String defaultSequenceFlow = (String) execution.getActivity().getProperty("default");
        List<PvmTransition> transitionsToTake = new ArrayList<PvmTransition>();
        for (PvmTransition outgoingTransition : execution.getActivity().getOutgoingTransitions()) {
            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 || condition.evaluate(outgoingTransition.getId(), execution)) {
                        transitionsToTake.add(outgoingTransition);
                    }
                }
            } else if (SkipExpressionUtil.shouldSkipFlowElement(execution, skipExpression)) {
                transitionsToTake.add(outgoingTransition);
            }
        }
        if (!transitionsToTake.isEmpty()) {
            execution.takeAll(transitionsToTake, joinedExecutions);
        } else {
            if (defaultSequenceFlow != null) {
                PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
                if (defaultTransition != null) {
                    transitionsToTake.add(defaultTransition);
                    execution.takeAll(transitionsToTake, joinedExecutions);
                } else {
                    throw new ActivitiException("Default sequence flow '" + defaultSequenceFlow + "' could not be not found");
                }
            } else {
                // No sequence flow could be found, not even a default one
                throw new ActivitiException("No outgoing sequence flow of the inclusive gateway '" + execution.getActivity().getId() + "' could be selected for continuing the process");
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Inclusive gateway '{}' does not activate", activity.getId());
        }
    }
}
Also used : Condition(org.activiti.engine.impl.Condition) ActivitiException(org.activiti.engine.ActivitiException) Expression(org.activiti.engine.delegate.Expression) ArrayList(java.util.ArrayList) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution) PvmActivity(org.activiti.engine.impl.pvm.PvmActivity) 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