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