/**
* 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.action;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.workflow.kaleo.definition.ExecutionType;
import com.liferay.portal.workflow.kaleo.model.KaleoAction;
import com.liferay.portal.workflow.kaleo.model.KaleoInstanceToken;
import com.liferay.portal.workflow.kaleo.runtime.ExecutionContext;
import com.liferay.portal.workflow.kaleo.runtime.action.ActionExecutorManager;
import com.liferay.portal.workflow.kaleo.runtime.action.KaleoActionExecutor;
import com.liferay.portal.workflow.kaleo.service.KaleoActionLocalService;
import com.liferay.portal.workflow.kaleo.service.KaleoInstanceLocalService;
import com.liferay.portal.workflow.kaleo.service.KaleoLogLocalService;
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, service = KaleoActionExecutor.class)
public class KaleoActionExecutorImpl implements KaleoActionExecutor {
@Override
public void executeKaleoActions(
String kaleoClassName, long kaleoClassPK,
ExecutionType executionType, ExecutionContext executionContext)
throws PortalException {
List<KaleoAction> kaleoActions =
_kaleoActionLocalService.getKaleoActions(
kaleoClassName, kaleoClassPK, executionType.getValue());
for (KaleoAction kaleoAction : kaleoActions) {
long startTime = System.currentTimeMillis();
String comment = _COMMENT_ACTION_SUCCESS;
try {
actionExecutorManager.executeKaleoAction(
kaleoAction, executionContext);
KaleoInstanceToken kaleoInstanceToken =
executionContext.getKaleoInstanceToken();
_kaleoInstanceLocalService.updateKaleoInstance(
kaleoInstanceToken.getKaleoInstanceId(),
executionContext.getWorkflowContext(),
executionContext.getServiceContext());
}
catch (Exception e) {
if (_log.isDebugEnabled()) {
_log.debug(e, e);
}
comment = e.getMessage();
}
finally {
_kaleoLogLocalService.addActionExecutionKaleoLog(
executionContext.getKaleoInstanceToken(), kaleoAction,
startTime, System.currentTimeMillis(), comment,
executionContext.getServiceContext());
}
}
}
@Reference
protected ActionExecutorManager actionExecutorManager;
private static final String _COMMENT_ACTION_SUCCESS =
"Action completed successfully.";
private static final Log _log = LogFactoryUtil.getLog(
KaleoActionExecutorImpl.class);
@Reference
private KaleoActionLocalService _kaleoActionLocalService;
@Reference
private KaleoInstanceLocalService _kaleoInstanceLocalService;
@Reference
private KaleoLogLocalService _kaleoLogLocalService;
}