/** * 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.kernel.util.Validator; import com.liferay.portal.workflow.kaleo.model.KaleoInstanceToken; import com.liferay.portal.workflow.kaleo.model.KaleoInstanceTokenConstants; 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.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.KaleoInstanceLocalService; import com.liferay.portal.workflow.kaleo.service.KaleoInstanceTokenLocalService; 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=STATE"}, service = NodeExecutor.class ) public class StateNodeExecutor 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(); String transitionName = executionContext.getTransitionName(); if (!currentKaleoNode.hasKaleoTransition()) { kaleoInstanceToken = _kaleoInstanceTokenLocalService.completeKaleoInstanceToken( kaleoInstanceToken.getKaleoInstanceTokenId()); if (kaleoInstanceToken.getParentKaleoInstanceTokenId() == KaleoInstanceTokenConstants. PARENT_KALEO_INSTANCE_TOKEN_ID_DEFAULT) { _kaleoInstanceLocalService.completeKaleoInstance( kaleoInstanceToken.getKaleoInstanceId()); } return; } KaleoTransition kaleoTransition = null; if (Validator.isNull(transitionName)) { kaleoTransition = currentKaleoNode.getDefaultKaleoTransition(); } else { 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 private KaleoInstanceLocalService _kaleoInstanceLocalService; @Reference private KaleoInstanceTokenLocalService _kaleoInstanceTokenLocalService; }