use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class TemplateComponent method executeAction.
@Override
protected boolean executeAction() {
try {
TemplateMsgAction actionDefinition = (TemplateMsgAction) getActionDefinition();
String template = null;
template = actionDefinition.getTemplate().getStringValue();
if ((null == template) && isDefinedResource(TemplateComponent.TEMPLATE)) {
// $NON-NLS-1$
IActionSequenceResource resource = getResource("template");
template = getResourceAsString(resource);
}
String outputName = (String) getOutputNames().iterator().next();
IActionParameter outputParam = getOutputItem(outputName);
if (outputParam.getType().equals(IActionParameter.TYPE_CONTENT)) {
String mimeType = actionDefinition.getMimeType().getStringValue();
String extension = actionDefinition.getExtension().getStringValue();
// This would prevent null values being passed as parameters to getOutputItem
if (mimeType == null) {
// $NON-NLS-1$
mimeType = "";
}
if (extension == null) {
// $NON-NLS-1$
extension = "";
}
// Removing the null check here because if we avoid null exception it gives misleading hibernate
// stale data exception which has nothing to do with a report that simply reads data.
IContentItem outputItem = getOutputContentItem(outputName, mimeType);
// IContentItem outputItem = getOutputItem(outputName, mimeType, extension);
OutputStream outputStream = outputItem.getOutputStream(getActionName());
outputStream.write(applyInputsToFormat(template).getBytes(LocaleHelper.getSystemEncoding()));
outputItem.closeOutputStream();
return true;
} else {
setOutputValue(outputName, applyInputsToFormat(template));
}
return true;
} catch (Exception e) {
// $NON-NLS-1$
error(Messages.getInstance().getString("Template.ERROR_0004_COULD_NOT_FORMAT_TEMPLATE"), e);
return false;
}
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class TestComponent method executeAction.
/*
* (non-Javadoc)
*
* @see org.pentaho.component.ComponentBase#execute()
*/
@Override
protected boolean executeAction() {
// $NON-NLS-1$
message(Messages.getInstance().getString("TestComponent.DEBUG_EXECUTING_TEST"));
Node componentNode = getComponentDefinition();
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$ //$NON-NLS-2$
actionParameter.getValue().getClass().toString() + "=" + actionParameter.getValue().toString()));
}
// $NON-NLS-1$
String test = XmlDom4JHelper.getNodeText("test", componentNode);
if ((test == null) || (test.length() < 1)) {
message(componentNode.asXML());
return (true);
}
// $NON-NLS-1$
String newName = XmlDom4JHelper.getNodeText("newname", componentNode);
Object theResult = null;
if ("format".equals(test)) {
// $NON-NLS-1$
// $NON-NLS-1$ //$NON-NLS-2$
MessageFormat mf = new MessageFormat(XmlDom4JHelper.getNodeText("p1", componentNode, ""));
Object[] obj = // $NON-NLS-1$ //$NON-NLS-2$
{ getParamFromComponentNode("p2", componentNode), getParamFromComponentNode("p3", componentNode) };
theResult = mf.format(obj);
} else {
// $NON-NLS-1$
Object p1 = getParamFromComponentNode("p1", componentNode);
if (p1 == null) {
return (false);
} else if ("toupper".equals(test)) {
// $NON-NLS-1$
theResult = p1.toString().toUpperCase();
} else if ("rename".equals(test)) {
// $NON-NLS-1$
theResult = p1;
} else if ("map2params".equals(test)) {
if (!(p1 instanceof Map)) {
// $NON-NLS-1$ //$NON-NLS-2$
error(Messages.getInstance().getErrorString("TestComponent.ERROR_0003_PARAMETER_NOT_MAP", "p1"));
return (false);
}
Map srcMap = (Map) p1;
for (Iterator it = srcMap.keySet().iterator(); it.hasNext(); ) {
String key = it.next().toString();
setOutputValue(key, srcMap.get(key));
}
} else if ("print".equals(test)) {
// $NON-NLS-1$
// $NON-NLS-1$
String delim = "\r\n***************************************************************\r\n";
theResult = delim + p1.toString() + delim;
} else if ("getkeys".equals(test)) {
if (!(p1 instanceof Map)) {
// $NON-NLS-1$ //$NON-NLS-2$
error(Messages.getInstance().getErrorString("TestComponent.ERROR_0003_PARAMETER_NOT_MAP", "p1"));
return (false);
}
theResult = new ArrayList(((Map) p1).keySet());
} else {
// $NON-NLS-1$
Object p2 = getParamFromComponentNode("p2", componentNode);
if (p2 == null) {
return (false);
}
if ("concat".equals(test)) {
// $NON-NLS-1$
theResult = p1.toString() + p2.toString();
} else if ("print2".equals(test)) {
// $NON-NLS-1$
// $NON-NLS-1$
String delim = Messages.getInstance().getString("TestComponent.CODE_PRINT_DELIM");
// $NON-NLS-1$
theResult = delim + p1.toString() + " - " + p2.toString() + delim;
} else {
// $NON-NLS-1$
Object p3 = getParamFromComponentNode("p3", componentNode);
if (p3 == null) {
return (false);
}
if ("merge".equals(test)) {
if (!(p1 instanceof Map) || !(p2 instanceof List) || !(p3 instanceof String)) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("TestComponent.ERROR_0004_P1_P2_WRONG_TYPE"));
return (false);
}
theResult = merge((Map) p1, (List) p2, (String) p3);
} else {
// $NON-NLS-1$
message(Messages.getInstance().getErrorString("TestComponent.ERROR_0001_TEST_NODE_NOT_FOUND"));
return false;
}
}
}
}
if (newName != null) {
// $NON-NLS-1$
message(newName + " = " + theResult);
try {
setOutputValue(newName, theResult);
} catch (Exception e) {
// ignore
}
// setOutputValue logs an error mesage
} else {
// $NON-NLS-1$
message("The result = " + theResult);
}
return (true);
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class IPreparedComponentIT method testIPreparedComponentSQLAvailable.
public void testIPreparedComponentSQLAvailable() {
startTest();
// $NON-NLS-1$
info("Expected: Successful execution with object available");
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IRuntimeContext context = run("/test/ipreparedcomponents/ipreparedcomponent_sql_available.xaction");
assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
context.getStatus());
// $NON-NLS-1$
IActionParameter rtn = context.getOutputParameter("prepared_component");
assertNotNull(rtn);
IPreparedComponent preparedComponent = (IPreparedComponent) rtn.getValue();
assertNotNull(preparedComponent);
finishTest();
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class IPreparedComponentIT method testIPreparedComponentXQueryShareConnection.
public void testIPreparedComponentXQueryShareConnection() {
startTest();
// $NON-NLS-1$
info("Expected: Successful execution with object available");
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IRuntimeContext context = run("/test/ipreparedcomponents/ipreparedcomponent_xquery_shareconn.xaction");
assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
context.getStatus());
// $NON-NLS-1$
IActionParameter rtn1 = context.getOutputParameter("prepared_component");
assertNotNull(rtn1);
IPreparedComponent preparedComponent1 = (IPreparedComponent) rtn1.getValue();
assertNotNull(preparedComponent1);
IPentahoResultSet resultset1 = preparedComponent1.executePrepared(null);
assertTrue(resultset1.getRowCount() >= 1);
Object val1 = resultset1.getValueAt(0, 0);
assertNotNull(val1);
finishTest();
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class IPreparedComponentIT method testIPreparedComponentXQueryAvailable.
/*
* public void testIPreparedComponentSQLTempTables() { startTest();
* info("Expected: Successful execution with one row of data"); //$NON-NLS-1$ IRuntimeContext context = run("test",
* "ipreparedcomponents", "ipreparedcomponent_sql_temptables.xaction"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
* assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$
*
* IActionParameter rtn1 = context.getOutputParameter("a_result"); //$NON-NLS-1$ assertNotNull(rtn1); IPentahoResultSet
* resultset1 = (IPentahoResultSet) rtn1.getValue(); assertEquals(1, resultset1.getRowCount()); assertEquals(
* "Expected first row of 'a_result' to contain a 1 in the first column.", new Integer(1), resultset1.getValueAt(0,
* 0)); //$NON-NLS-1$
*
* IActionParameter rtn2 = context.getOutputParameter("no_results"); //$NON-NLS-1$ assertNotNull(rtn2);
* IPentahoResultSet resultset2 = (IPentahoResultSet) rtn2.getValue(); assertEquals(1, resultset2.getRowCount());
* assertEquals( "Expected first row of 'no_results' to contain a 0 in the first column.", new Integer(0),
* resultset2.getValueAt(0, 0)); //$NON-NLS-1$
*
* finishTest(); }
*/
/*
* public void testIPreparedComponentSQLPrepareLater() { startTest();
* info("Expected: Successful execution with object available"); //$NON-NLS-1$ IRuntimeContext context = run("test",
* "ipreparedcomponents", "ipreparedcomponent_sql_preparelater.xaction"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
* assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$
*
* IActionParameter rtn1 = context.getOutputParameter("prepared_component"); //$NON-NLS-1$ assertNotNull(rtn1);
* IPreparedComponent preparedComponent1 = (IPreparedComponent) rtn1.getValue(); assertNotNull(preparedComponent1);
* IPentahoResultSet resultset1 = preparedComponent1.executePrepared(null); assertEquals(1, resultset1.getRowCount());
* Number val1 = (Number) resultset1.getValueAt(0, 0);
*
* IActionParameter rtn2 = context.getOutputParameter("second_prepared_component"); //$NON-NLS-1$ assertNotNull(rtn2);
* IPreparedComponent preparedComponent2 = (IPreparedComponent) rtn2.getValue(); assertNotNull(preparedComponent2);
* HashMap map = new HashMap(); map.put("DEPARTMENT", "Sales"); //$NON-NLS-1$ //$NON-NLS-2$ map.put("REGION",
* "Eastern"); //$NON-NLS-1$ //$NON-NLS-2$ IPentahoResultSet resultset2 = preparedComponent2.executePrepared(map);
* assertEquals(1, resultset2.getRowCount()); Number val2 = (Number) resultset2.getValueAt(0, 0);
*
* assertEquals("Values from the first and second query should be equal", val1, val2); //$NON-NLS-1$
*
* finishTest(); }
*/
/*
* public void testIPreparedComponentMDXAvailable() { startTest();
* info("Expected: Successful execution with object available"); //$NON-NLS-1$ IRuntimeContext context = run("test",
* "ipreparedcomponents", "ipreparedcomponent_mdx_available.xaction"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
* assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$
*
* IActionParameter rtn = context.getOutputParameter("prepared_component"); //$NON-NLS-1$ assertNotNull(rtn);
* IPreparedComponent preparedComponent = (IPreparedComponent) rtn.getValue();
*
* assertNotNull(preparedComponent);
*
* finishTest(); }
*/
/*
* public void testIPreparedComponentMDXShareConnection() { startTest();
* info("Expected: Successful execution with object available"); //$NON-NLS-1$ IRuntimeContext context = run("test",
* "ipreparedcomponents", "ipreparedcomponent_mdx_shareconn.xaction"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
* assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$
*
* IActionParameter rtn = context.getOutputParameter("prepared_component"); //$NON-NLS-1$ assertNotNull(rtn);
* IPreparedComponent preparedComponent = (IPreparedComponent) rtn.getValue();
*
* assertNotNull(preparedComponent);
*
* IPentahoResultSet resultset = preparedComponent.executePrepared(null); assertNotNull(resultset);
* assertTrue(resultset.getRowCount() >= 1); Object val1 = resultset.getValueAt(0, 0); assertNotNull(val1);
*
* finishTest(); }
*/
/*
* public void testIPreparedComponentMDXPrepareLater() { startTest();
* info("Expected: Successful execution with object available"); //$NON-NLS-1$ IRuntimeContext context = run("test",
* "ipreparedcomponents", "ipreparedcomponent_mdx_preparelater.xaction"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
* assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$
*
* IActionParameter rtn1 = context.getOutputParameter("prepared_component"); //$NON-NLS-1$ assertNotNull(rtn1);
* IPreparedComponent preparedComponent1 = (IPreparedComponent) rtn1.getValue(); assertNotNull(preparedComponent1);
* IPentahoResultSet resultset1 = preparedComponent1.executePrepared(null); assertNotNull(resultset1);
* assertTrue(resultset1.getRowCount() >= 1); Object val1 = resultset1.getValueAt(0, 0);
*
* IActionParameter rtn2 = context.getOutputParameter("second_prepared_component"); //$NON-NLS-1$ assertNotNull(rtn2);
* IPreparedComponent preparedComponent2 = (IPreparedComponent) rtn2.getValue(); assertNotNull(preparedComponent2);
* HashMap map = new HashMap(); map.put("productline", "Classic Cars"); //$NON-NLS-1$ //$NON-NLS-2$ IPentahoResultSet
* resultset2 = preparedComponent2.executePrepared(map); assertTrue(resultset2.getRowCount() >= 1);
* assertEquals(resultset1.getRowCount(), resultset2.getRowCount());
*
* Object val2 = resultset2.getValueAt(0, 0);
*
* assertEquals("Values from the first and second query should be equal", val1, val2); //$NON-NLS-1$
*
* finishTest(); }
*/
public void testIPreparedComponentXQueryAvailable() {
startTest();
// $NON-NLS-1$
info("Expected: Successful execution with object available");
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IRuntimeContext context = run("/test/ipreparedcomponents/ipreparedcomponent_xquery_available.xaction");
assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
context.getStatus());
// $NON-NLS-1$
IActionParameter rtn = context.getOutputParameter("prepared_component");
assertNotNull(rtn);
IPreparedComponent preparedComponent = (IPreparedComponent) rtn.getValue();
assertNotNull(preparedComponent);
finishTest();
}
Aggregations