/** * 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.notification.recipient.script; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.resource.StringResourceRetriever; import com.liferay.portal.rules.engine.Fact; import com.liferay.portal.rules.engine.Query; import com.liferay.portal.rules.engine.RulesEngine; import com.liferay.portal.rules.engine.RulesResourceRetriever; import com.liferay.portal.workflow.kaleo.model.KaleoNotificationRecipient; import com.liferay.portal.workflow.kaleo.runtime.ExecutionContext; import com.liferay.portal.workflow.kaleo.runtime.notification.recipient.script.NotificationRecipientEvaluator; import com.liferay.portal.workflow.kaleo.runtime.util.RulesContextBuilder; import java.util.List; import java.util.Map; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** * @author Michael C. Han */ @Component( immediate = true, property = {"scripting.language=drl"}, service = NotificationRecipientEvaluator.class ) public class DRLNotificationRecipientEvaluator implements NotificationRecipientEvaluator { @Override public Map<String, ?> evaluate( KaleoNotificationRecipient kaleoNotificationRecipient, ExecutionContext executionContext) throws PortalException { RulesResourceRetriever rulesResourceRetriever = new RulesResourceRetriever( new StringResourceRetriever( kaleoNotificationRecipient.getRecipientScript())); List<Fact<?>> facts = _rulesContextBuilder.buildRulesContext( executionContext); Query query = Query.createStandardQuery(); return _rulesEngine.execute(rulesResourceRetriever, facts, query); } @Reference private RulesContextBuilder _rulesContextBuilder; @Reference private RulesEngine _rulesEngine; }