/** * 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.node; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.service.ServiceContext; import com.liferay.portal.workflow.kaleo.definition.ExecutionType; 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.KaleoTimerInstanceToken; import com.liferay.portal.workflow.kaleo.runtime.ExecutionContext; import com.liferay.portal.workflow.kaleo.runtime.action.KaleoActionExecutor; import com.liferay.portal.workflow.kaleo.runtime.graph.PathElement; import com.liferay.portal.workflow.kaleo.runtime.notification.NotificationHelper; import com.liferay.portal.workflow.kaleo.runtime.util.ExecutionContextHelper; import com.liferay.portal.workflow.kaleo.service.KaleoTimerInstanceTokenLocalService; import com.liferay.portal.workflow.kaleo.service.KaleoTimerLocalService; import java.util.List; import org.osgi.service.component.annotations.Reference; /** * @author Michael C. Han */ public abstract class BaseNodeExecutor implements NodeExecutor { @Override public boolean enter( KaleoNode currentKaleoNode, ExecutionContext executionContext) throws PortalException { KaleoInstanceToken kaleoInstanceToken = executionContext.getKaleoInstanceToken(); kaleoInstanceToken.setCurrentKaleoNode(currentKaleoNode); boolean performExecute = doEnter(currentKaleoNode, executionContext); kaleoActionExecutor.executeKaleoActions( KaleoNode.class.getName(), currentKaleoNode.getKaleoNodeId(), ExecutionType.ON_ENTRY, executionContext); notificationHelper.sendKaleoNotifications( KaleoNode.class.getName(), currentKaleoNode.getKaleoNodeId(), ExecutionType.ON_ENTRY, executionContext); List<KaleoTimer> kaleoTimers = kaleoTimerLocalService.getKaleoTimers( KaleoNode.class.getName(), currentKaleoNode.getKaleoNodeId()); kaleoTimerInstanceTokenLocalService.addKaleoTimerInstanceTokens( executionContext.getKaleoInstanceToken(), executionContext.getKaleoTaskInstanceToken(), kaleoTimers, executionContext.getWorkflowContext(), executionContext.getServiceContext()); return performExecute; } @Override public void execute( KaleoNode currentKaleoNode, ExecutionContext executionContext, List<PathElement> remainingPathElements) throws PortalException { if (executionContextHelper.isKaleoInstanceBlocked(executionContext)) { return; } doExecute(currentKaleoNode, executionContext, remainingPathElements); } @Override public void executeTimer( KaleoNode currentKaleoNode, ExecutionContext executionContext) throws PortalException { ServiceContext serviceContext = executionContext.getServiceContext(); KaleoTimerInstanceToken kaleoTimerInstanceToken = executionContext.getKaleoTimerInstanceToken(); KaleoTimer kaleoTimer = kaleoTimerInstanceToken.getKaleoTimer(); kaleoActionExecutor.executeKaleoActions( KaleoTimer.class.getName(), kaleoTimer.getKaleoTimerId(), ExecutionType.ON_TIMER, executionContext); notificationHelper.sendKaleoNotifications( KaleoTimer.class.getName(), kaleoTimer.getKaleoTimerId(), ExecutionType.ON_TIMER, executionContext); doExecuteTimer(currentKaleoNode, kaleoTimer, executionContext); if (!kaleoTimer.isRecurring()) { kaleoTimerInstanceTokenLocalService.completeKaleoTimerInstanceToken( kaleoTimerInstanceToken.getKaleoTimerInstanceTokenId(), serviceContext); } } @Override public void exit( KaleoNode currentKaleoNode, ExecutionContext executionContext, List<PathElement> remainingPathElements) throws PortalException { executionContextHelper.completeKaleoTimerInstances(executionContext); doExit(currentKaleoNode, executionContext, remainingPathElements); kaleoActionExecutor.executeKaleoActions( KaleoNode.class.getName(), currentKaleoNode.getKaleoNodeId(), ExecutionType.ON_EXIT, executionContext); notificationHelper.sendKaleoNotifications( KaleoNode.class.getName(), currentKaleoNode.getKaleoNodeId(), ExecutionType.ON_EXIT, executionContext); } protected abstract boolean doEnter( KaleoNode currentKaleoNode, ExecutionContext executionContext) throws PortalException; protected abstract void doExecute( KaleoNode currentKaleoNode, ExecutionContext executionContext, List<PathElement> remainingPathElements) throws PortalException; protected abstract void doExecuteTimer( KaleoNode currentKaleoNode, KaleoTimer kaleoTimer, ExecutionContext executionContext) throws PortalException; protected abstract void doExit( KaleoNode currentKaleoNode, ExecutionContext executionContext, List<PathElement> remainingPathElements) throws PortalException; @Reference protected ExecutionContextHelper executionContextHelper; @Reference protected KaleoActionExecutor kaleoActionExecutor; @Reference protected KaleoTimerInstanceTokenLocalService kaleoTimerInstanceTokenLocalService; @Reference protected KaleoTimerLocalService kaleoTimerLocalService; @Reference protected NotificationHelper notificationHelper; }