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;
}
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();
}
}
}
}
}
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;
}
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;
}
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;
}
Aggregations