use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class PentahoSystem method sessionStartup.
public static void sessionStartup(final IPentahoSession session, IParameterProvider sessionParameters) {
List<ISessionStartupAction> sessionStartupActions = PentahoSystem.getSessionStartupActionsForType(session.getClass().getName());
if (sessionStartupActions == null) {
// nothing to do...
return;
}
if (!session.isAuthenticated()) {
return;
}
Boolean startupActionsFired = (Boolean) session.getAttribute("StartupActionsFired");
if ((startupActionsFired == null) || (!startupActionsFired)) {
try {
if (debug) {
// $NON-NLS-1$
Logger.debug(PentahoSystem.class, "Process session startup actions");
}
if (sessionStartupActions != null) {
for (ISessionStartupAction sessionStartupAction : sessionStartupActions) {
// parse the actionStr out to identify an action
// 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();
if (sessionParameters == null) {
sessionParameters = new PentahoSessionParameterProvider(session);
}
parameterProviderMap.put(SCOPE_SESSION, sessionParameters);
IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
ArrayList messages = new ArrayList();
IRuntimeContext context = null;
try {
context = solutionEngine.execute(sessionStartupAction.getActionPath(), "Session 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) {
session.removeAttribute(attributeName);
session.setAttribute(attributeName, data);
}
}
}
} catch (Throwable th) {
Logger.warn(PentahoSystem.class.getName(), Messages.getInstance().getString("PentahoSystem.WARN_UNABLE_TO_EXECUTE_SESSION_ACTION", th.getLocalizedMessage()), // $NON-NLS-1$
th);
} finally {
if (context != null) {
context.dispose();
}
}
}
}
} finally {
session.setAttribute("StartupActionsFired", true);
}
} else {
if (debug) {
Logger.debug(PentahoSystem.class, "Session startup actions already fired");
}
}
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class ReportWizardSpecComponent 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 validateAction.
@Override
protected boolean validateAction() {
if (isDefinedResource(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN)) {
return true;
}
if (isDefinedInput(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN)) {
IActionParameter o = getInputParameter(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN);
if ((o != null) && (o.getValue() instanceof String)) {
return true;
}
return false;
}
// Handle late-bind of report resource name
if (isDefinedInput(AbstractJFreeReportComponent.REPORTLOAD_RESOURCENAME)) {
if (isDefinedResource(getInputStringValue(AbstractJFreeReportComponent.REPORTLOAD_RESOURCENAME))) {
return true;
} else {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0004_REPORT_DEFINITION_UNREADABLE"));
return false;
}
}
if (isDefinedResource(AbstractJFreeReportComponent.DATACOMPONENT_JARINPUT)) {
if (!isDefinedInput(AbstractJFreeReportComponent.REPORTLOAD_REPORTLOC)) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0011_REPORT_LOCATION_MISSING"));
return false;
}
final IActionSequenceResource resource = getResource(AbstractJFreeReportComponent.DATACOMPONENT_JARINPUT);
final InputStream in;
in = resource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale());
try {
// not being able to read a single char is definitly a big boo ..
if (in.read() == -1) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE"));
return false;
}
} catch (Exception e) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE"));
return false;
}
if (!isDefinedInput(AbstractJFreeReportComponent.REPORTLOAD_REPORTLOC)) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0012_CLASS_LOCATION_MISSING"));
return false;
}
return true;
}
return false;
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class TestComponent method validateAction.
@Override
protected boolean validateAction() {
// describe the inputs, outputs and resources available to us
Set inputNames = getInputNames();
Iterator inputNamesIterator = inputNames.iterator();
String inputName;
IActionParameter actionParameter;
while (inputNamesIterator.hasNext()) {
inputName = (String) inputNamesIterator.next();
actionParameter = getInputParameter(inputName);
message(Messages.getInstance().getString("TestComponent.DEBUG_INPUT_DESCRIPTION", inputName, // $NON-NLS-1$
actionParameter.getType()));
}
Set outputNames = getOutputNames();
Iterator outputNamesIterator = outputNames.iterator();
String outputName;
while (outputNamesIterator.hasNext()) {
outputName = (String) outputNamesIterator.next();
actionParameter = getOutputItem(outputName);
message(Messages.getInstance().getString("TestComponent.DEBUG_OUTPUT_DESCRIPTION", outputName, // $NON-NLS-1$
actionParameter.getType()));
}
Set resourceNames = getResourceNames();
Iterator resourceNamesIterator = resourceNames.iterator();
String resourceName;
IActionSequenceResource actionResource;
while (resourceNamesIterator.hasNext()) {
resourceName = (String) resourceNamesIterator.next();
actionResource = getResource(resourceName);
message(Messages.getInstance().getString("TestComponent.DEBUG_RESOURCE_DESCRIPTION", resourceName, actionResource.getMimeType(), // $NON-NLS-1$
actionResource.getAddress()));
try {
String content = getResourceAsString(actionResource);
message(Messages.getInstance().getString("TestComponent.DEBUG_RESOURCE_CONTENTS", // $NON-NLS-1$ //$NON-NLS-2$
((content == null) ? "null" : content.substring(0, 100))));
} catch (Exception e) {
// $NON-NLS-1$
message(Messages.getInstance().getString("TestComponent.ERROR_0005_RESOURCE_NOT_LOADED", e.getMessage()));
}
}
return true;
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class SecureFilterComponent method validateAction.
@Override
public boolean validateAction() {
Node compDef = getComponentDefinition();
// $NON-NLS-1$
List selNodes = compDef.selectNodes("selections/*");
String inputName = null;
boolean isOk = true;
for (Iterator it = selNodes.iterator(); it.hasNext(); ) {
Node node = (Node) it.next();
try {
// Get the Data Node
inputName = node.getName();
IActionParameter inputParam = getInputParameter(inputName);
// $NON-NLS-1$
String filterType = XmlDom4JHelper.getNodeText("@filter", node, null);
// BISERVER-149 Changed isOptional param to default to false in order to
// enable prompting when no default value AND no selection list is given...
// This is also the default that Design Studio presumes.
// $NON-NLS-1$ //$NON-NLS-2$
String optionalParm = XmlDom4JHelper.getNodeText("@optional", node, "false");
// $NON-NLS-1$
boolean isOptional = "true".equals(optionalParm);
if ("none".equalsIgnoreCase(filterType)) {
// $NON-NLS-1$
IActionParameter selectParam = getInputParameter(inputName);
// $NON-NLS-1$
String title = XmlDom4JHelper.getNodeText("title", node, inputName);
// $NON-NLS-1$
String valueCol = "";
// $NON-NLS-1$
String dispCol = "";
// $NON-NLS-1$
String displayStyle = XmlDom4JHelper.getNodeText("@style", node, null);
boolean promptOne = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"true".equalsIgnoreCase(XmlDom4JHelper.getNodeText("@prompt-if-one-value", node, "false"));
if ("hidden".equals(displayStyle)) {
// $NON-NLS-1$
hiddenList.add(new SelEntry(inputParam, selectParam, valueCol, dispCol, title, displayStyle, promptOne, isOptional));
} else {
selList.add(new SelEntry(inputParam, selectParam, valueCol, dispCol, title, displayStyle, promptOne, isOptional));
}
} else {
// $NON-NLS-1$
Node filterNode = node.selectSingleNode("filter");
IActionParameter selectParam = getInputParameter(filterNode.getText().trim());
// $NON-NLS-1$
String valueCol = XmlDom4JHelper.getNodeText("@value-col-name", filterNode, null);
// $NON-NLS-1$
String dispCol = XmlDom4JHelper.getNodeText("@display-col-name", filterNode, null);
// $NON-NLS-1$
String title = XmlDom4JHelper.getNodeText("title", node, null);
// $NON-NLS-1$
String displayStyle = XmlDom4JHelper.getNodeText("@style", node, null);
boolean promptOne = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"true".equalsIgnoreCase(XmlDom4JHelper.getNodeText("@prompt-if-one-value", node, "false"));
selList.add(new SelEntry(inputParam, selectParam, valueCol, dispCol, title, displayStyle, promptOne, isOptional));
}
} catch (Exception e) {
// Catch the exception to let us test all
// the params
isOk = false;
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("SecureFilterComponent.ERROR_0001_PARAM_MISSING", inputName));
}
}
return (isOk);
}
Aggregations