/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.portal.workflow.kaleo.runtime.internal.node; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.workflow.kaleo.model.KaleoCondition; import com.liferay.portal.workflow.kaleo.model.KaleoInstanceToken; import com.liferay.portal.workflow.kaleo.model.KaleoNode; import com.liferay.portal.workflow.kaleo.model.KaleoTimer; import com.liferay.portal.workflow.kaleo.model.KaleoTransition; import com.liferay.portal.workflow.kaleo.runtime.ExecutionContext; import com.liferay.portal.workflow.kaleo.runtime.condition.ConditionEvaluator; import com.liferay.portal.workflow.kaleo.runtime.graph.PathElement; import com.liferay.portal.workflow.kaleo.runtime.node.BaseNodeExecutor; import com.liferay.portal.workflow.kaleo.runtime.node.NodeExecutor; import com.liferay.portal.workflow.kaleo.service.KaleoConditionLocalService; import com.liferay.portal.workflow.kaleo.service.KaleoInstanceLocalService; import java.util.List; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** * @author Michael C. Han */ @Component( immediate = true, property = {"node.type=CONDITION"}, service = NodeExecutor.class ) public class ConditionNodeExecutor extends BaseNodeExecutor { @Override protected boolean doEnter( KaleoNode currentKaleoNode, ExecutionContext executionContext) { return true; } @Override protected void doExecute( KaleoNode currentKaleoNode, ExecutionContext executionContext, List<PathElement> remainingPathElements) throws PortalException { KaleoInstanceToken kaleoInstanceToken = executionContext.getKaleoInstanceToken(); KaleoCondition kaleoCondition = _kaleoConditionLocalService.getKaleoNodeKaleoCondition( currentKaleoNode.getKaleoNodeId()); String transitionName = _conditionEvaluator.evaluate( kaleoCondition, executionContext); _kaleoInstanceLocalService.updateKaleoInstance( kaleoInstanceToken.getKaleoInstanceId(), executionContext.getWorkflowContext(), executionContext.getServiceContext()); KaleoTransition kaleoTransition = currentKaleoNode.getKaleoTransition( transitionName); ExecutionContext newExecutionContext = new ExecutionContext( kaleoInstanceToken, executionContext.getWorkflowContext(), executionContext.getServiceContext()); PathElement pathElement = new PathElement( currentKaleoNode, kaleoTransition.getTargetKaleoNode(), newExecutionContext); remainingPathElements.add(pathElement); } @Override protected void doExecuteTimer( KaleoNode currentKaleoNode, KaleoTimer kaleoTimer, ExecutionContext executionContext) { } @Override protected void doExit( KaleoNode currentKaleoNode, ExecutionContext executionContext, List<PathElement> remainingPathElements) { } @Reference(target = "(!(scripting.language=*))") private ConditionEvaluator _conditionEvaluator; @Reference private KaleoConditionLocalService _kaleoConditionLocalService; @Reference private KaleoInstanceLocalService _kaleoInstanceLocalService; }