Search in sources :

Example 1 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.

the class ScriptableCondition method shouldExecute.

public boolean shouldExecute(final Map currentInputs, final Log logger) throws Exception {
    boolean shouldExecute = this.getDefaultResult();
    ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine engine = mgr.getEngineByName(this.getScriptLanguage());
    if (engine == null) {
        throw new IllegalArgumentException(Messages.getInstance().getErrorString("ScriptableCondition.ERROR_0001_ENGINE_NOT_AVAILABLE", // $NON-NLS-1$
        this.getScriptLanguage()));
    }
    Object inputValue;
    IActionParameter inputParameter;
    String inputName = null;
    Iterator inputs = currentInputs.entrySet().iterator();
    Map.Entry mapEntry;
    while (inputs.hasNext()) {
        mapEntry = (Map.Entry) inputs.next();
        inputName = (String) mapEntry.getKey();
        if (this.getIgnoreInputNamesWithMinus() && inputName.indexOf('-') >= 0) {
            // $NON-NLS-1$
            logger.info(Messages.getInstance().getString("ScriptableCondition.INFO_IGNORED_INPUT", inputName));
            continue;
        }
        inputParameter = (IActionParameter) mapEntry.getValue();
        inputValue = inputParameter.getValue();
        // What happens to resultset objects I wonder...
        engine.put(inputName, inputValue);
    }
    engine.put("out", System.out);
    engine.put("rule", this);
    Object resultObject = engine.eval(this.getScript());
    if (resultObject instanceof Boolean) {
        return ((Boolean) resultObject).booleanValue();
    } else if (resultObject instanceof String) {
        return ("true".equalsIgnoreCase(resultObject.toString())) || ("yes".equalsIgnoreCase(// $NON-NLS-1$ //$NON-NLS-2$
        resultObject.toString()));
    } else if (resultObject instanceof Number) {
        return ((Number) resultObject).intValue() > 0;
    } else if (resultObject instanceof IPentahoResultSet) {
        return ((IPentahoResultSet) resultObject).getRowCount() > 0;
    }
    // $NON-NLS-1$
    logger.info(Messages.getInstance().getString("ScriptableCondition.INFO_DEFAULT_RESULT_RETURNED"));
    return shouldExecute;
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) Iterator(java.util.Iterator) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) Map(java.util.Map)

Example 2 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.

the class PentahoSystem method globalStartup.

public static void globalStartup(final IPentahoSession session) {
    // getGlobalStartupActions doesn't pay any attention to session class
    List<ISessionStartupAction> globalStartupActions = PentahoSystem.getGlobalStartupActions();
    if (globalStartupActions == null) {
        // nothing to do...
        return;
    }
    boolean doGlobals = PentahoSystem.globalAttributes.size() == 0;
    // see if this has been done already
    if (!doGlobals) {
        return;
    }
    if (globalStartupActions != null) {
        for (ISessionStartupAction globalStartupAction : globalStartupActions) {
            // now execute the action...
            SimpleOutputHandler outputHandler = null;
            String instanceId = null;
            ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
            solutionEngine.setLoggingLevel(PentahoSystem.loggingLevel);
            solutionEngine.init(session);
            // $NON-NLS-1$
            String baseUrl = "";
            HashMap parameterProviderMap = new HashMap();
            IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
            ArrayList messages = new ArrayList();
            IRuntimeContext context = null;
            try {
                context = solutionEngine.execute(globalStartupAction.getActionPath(), "Global startup actions", false, true, instanceId, false, parameterProviderMap, outputHandler, null, urlFactory, // $NON-NLS-1$
                messages);
                // if context is null, then we cannot check the status
                if (null == context) {
                    return;
                }
                if (context.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
                    // now grab any outputs
                    Iterator outputNameIterator = context.getOutputNames().iterator();
                    while (outputNameIterator.hasNext()) {
                        String attributeName = (String) outputNameIterator.next();
                        IActionParameter output = context.getOutputParameter(attributeName);
                        Object data = output.getValue();
                        if (data != null) {
                            PentahoSystem.globalAttributes.remove(attributeName);
                            PentahoSystem.globalAttributes.put(attributeName, data);
                        }
                    }
                }
            } catch (Throwable th) {
                Logger.warn(PentahoSystem.class.getName(), Messages.getInstance().getString("PentahoSystem.WARN_UNABLE_TO_EXECUTE_GLOBAL_ACTION", th.getLocalizedMessage()), // $NON-NLS-1$
                th);
            } finally {
                if (context != null) {
                    context.dispose();
                }
            }
        }
    }
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) ISessionStartupAction(org.pentaho.platform.api.engine.ISessionStartupAction) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 3 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.

the class JFreeReportComponent method initReportParams.

private int initReportParams() {
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    int result = JFreeReportComponent.INIT_REPORT_PARAMS_STATUS_PASSED;
    // $NON-NLS-1$
    final String defaultValue = "";
    IActionInput[] actionInputs = jFreeReportAction.getInputs();
    for (IActionInput element : actionInputs) {
        Object paramValue = element.getValue();
        String inputName = element.getName();
        if (// $NON-NLS-1$
        (paramValue == null) || ("".equals(paramValue))) {
            IActionParameter paramParameter = getInputParameter(inputName);
            if (paramParameter.getPromptStatus() == IActionParameter.PROMPT_PENDING) {
                result = JFreeReportComponent.INIT_REPORT_PARAMS_STATUS_PROMPT_PENDING;
                continue;
            }
            if (isParameterUIAvailable()) {
                // The parameter value was not provided, and we are allowed
                // to
                // create user interface forms
                // $NON-NLS-1$
                createFeedbackParameter(inputName, inputName, "", defaultValue, true);
                result = JFreeReportComponent.INIT_REPORT_PARAMS_STATUS_PROMPT_PENDING;
            } else {
                result = JFreeReportComponent.INIT_REPORT_PARAMS_STATUS_FAILED;
            }
        }
    }
    return result;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) IActionInput(org.pentaho.actionsequence.dom.IActionInput) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 4 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.

the class JFreeReportGenerateDefinitionComponent method setupQueryParameters.

public String setupQueryParameters(String query) {
    Set inputNames = getInputNames();
    Iterator iter = inputNames.iterator();
    while (iter.hasNext()) {
        String inputName = (String) iter.next();
        final IActionParameter inputParameter = getInputParameter(inputName);
        final Object value = inputParameter.getValue();
        if ((value instanceof String) == false) {
            continue;
        }
        String paramValue = (String) value;
        // $NON-NLS-1$ //$NON-NLS-2$
        String param = "\\{" + inputName + "\\}";
        query = query.replaceAll(param, paramValue);
    }
    return query;
}
Also used : Set(java.util.Set) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) Iterator(java.util.Iterator) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 5 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.

the class JFreeReportLoadComponent method getReportFromInputParam.

private MasterReport getReportFromInputParam() throws ResourceException, UnsupportedEncodingException, IOException {
    MasterReport report = null;
    if (isDefinedInput(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN)) {
        IActionParameter o = getInputParameter(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN);
        if (o != null) {
            String repDef = o.getStringValue();
            ReportGenerator generator = ReportGenerator.getInstance();
            IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
            URL url = null;
            try {
                url = new URL(requestContext.getContextPath());
            } catch (Exception e) {
                // a null URL is ok
                // $NON-NLS-1$
                warn(Messages.getInstance().getString("JFreeReportLoadComponent.WARN_COULD_NOT_CREATE_URL"));
            }
            report = generator.parseReport(new InputSource(new ByteArrayInputStream(repDef.getBytes("UTF-8"))), // $NON-NLS-1$
            getDefinedResourceURL(url));
        }
    }
    return report;
}
Also used : MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) ReportGenerator(org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) URL(java.net.URL) ResourceException(org.pentaho.reporting.libraries.resourceloader.ResourceException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

IActionParameter (org.pentaho.platform.api.engine.IActionParameter)68 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)24 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)22 Iterator (java.util.Iterator)19 Map (java.util.Map)14 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)14 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)13 List (java.util.List)9 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)9 Set (java.util.Set)8 IContentItem (org.pentaho.platform.api.repository.IContentItem)8 IOException (java.io.IOException)7 OutputStream (java.io.OutputStream)6 Test (org.junit.Test)6 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)6 ActionParameter (org.pentaho.platform.engine.services.actionsequence.ActionParameter)6 Document (org.dom4j.Document)5 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4