/** * 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.scripting.internal.condition; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.workflow.kaleo.model.KaleoCondition; import com.liferay.portal.workflow.kaleo.runtime.ExecutionContext; import com.liferay.portal.workflow.kaleo.runtime.condition.ConditionEvaluator; import com.liferay.portal.workflow.kaleo.runtime.scripting.internal.util.KaleoScriptingEvaluator; import com.liferay.portal.workflow.kaleo.runtime.util.WorkflowContextUtil; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** * @author Michael C. Han */ @Component( immediate = true, property = { "scripting.language=beanshell", "scripting.language=groovy", "scripting.language=javascript", "scripting.language=python", "scripting.language=ruby" }, service = ConditionEvaluator.class ) public class ScriptingConditionEvaluator implements ConditionEvaluator { @Override public String evaluate( KaleoCondition kaleoCondition, ExecutionContext executionContext) throws PortalException { Map<String, Object> results = _kaleoScriptingEvaluator.execute( executionContext, _outputNames, kaleoCondition.getScriptLanguage(), kaleoCondition.getScript()); String returnValue = (String)results.get(_RETURN_VALUE); if (returnValue != null) { return returnValue; } throw new IllegalStateException( "Conditional did not return value for script " + kaleoCondition.getScript()); } private static final String _RETURN_VALUE = "returnValue"; private static final Set<String> _outputNames = new HashSet<>(); static { _outputNames.add(_RETURN_VALUE); _outputNames.add(WorkflowContextUtil.WORKFLOW_CONTEXT_NAME); } @Reference private KaleoScriptingEvaluator _kaleoScriptingEvaluator; }