use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class MultipleComponentIT method testDataUtility3.
public void testDataUtility3() {
startTest();
IPentahoResultSet rs3 = getResultSet2();
String xmlString3 = DataUtilities.getXMLString(rs3);
// $NON-NLS-1$
assertTrue(xmlString3.indexOf("DATA2") > 0);
finishTest();
}
use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class TemplateUtilTest method createMockResultSet.
private IPentahoResultSet createMockResultSet() {
final Object[] mockRow = new Object[] { "key Value", "field Value" };
IPentahoResultSet mockPentahoResultSet = mock(IPentahoResultSet.class);
IPentahoMetaData mockPentahoMetaData = mock(IPentahoMetaData.class);
when(mockPentahoResultSet.getColumnCount()).thenReturn(mockRow.length);
when(mockPentahoResultSet.getDataRow(0)).thenReturn(mockRow);
when(mockPentahoResultSet.getMetaData()).thenReturn(mockPentahoMetaData);
when(mockPentahoResultSet.getRowCount()).thenReturn(1);
when(mockPentahoResultSet.getValueAt(0, 0)).thenReturn(mockRow[0]);
when(mockPentahoResultSet.getValueAt(0, 1)).thenReturn(mockRow[1]);
when(mockPentahoMetaData.getColumnIndex("keycol")).thenReturn(0);
when(mockPentahoMetaData.getColumnIndex("valcol")).thenReturn(1);
return mockPentahoResultSet;
}
use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class TemplateUtilTest method testTableTemplate.
public void testTableTemplate() {
IRuntimeContext mockRuntimeContext = mock(IRuntimeContext.class);
IPentahoSession mockSession = mock(IPentahoSession.class);
IParameterManager mockParameterManager = mock(IParameterManager.class);
IPentahoResultSet mockPentahoResultSet = mock(IPentahoResultSet.class);
Object[] mockRow = new Object[] { "field0", "field1" };
when(mockPentahoResultSet.getColumnCount()).thenReturn(mockRow.length);
when(mockPentahoResultSet.getDataRow(0)).thenReturn(mockRow);
when(mockParameterManager.getCurrentInputNames()).thenReturn(new HashSet<Object>(Arrays.asList(new String[] { "param1" })));
when(mockRuntimeContext.getSession()).thenReturn(mockSession);
when(mockRuntimeContext.getParameterManager()).thenReturn(mockParameterManager);
when(mockRuntimeContext.getInputParameterValue("param1")).thenReturn(mockPentahoResultSet);
String template = "table {param1:col:1} and text";
IParameterResolver resolver = mock(IParameterResolver.class);
assertEquals("table field1 and text", TemplateUtil.applyTemplate(template, mockRuntimeContext, resolver));
}
use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class XQueryBaseComponent method runFinalQuery.
protected boolean runFinalQuery(final IPentahoConnection localConnection, final String rawQuery, final String[] columnTypes) {
XQueryAction xQueryAction = (XQueryAction) getActionDefinition();
boolean success = false;
String finalQuery = applyInputsToFormat(rawQuery);
// execute the query, read the results and cache them
try {
IPentahoResultSet resultSet = ((XQConnection) localConnection).executeQuery(finalQuery, columnTypes);
if (resultSet != null) {
if (!xQueryAction.getLive().getBooleanValue(true)) {
resultSet = resultSet.memoryCopy();
}
try {
IActionOutput resultSetOutput = xQueryAction.getOutputResultSet();
if (resultSetOutput != null) {
resultSetOutput.setValue(resultSet);
}
success = true;
} finally {
resultSet.close();
}
}
} catch (XPathException e) {
error(Messages.getInstance().getErrorString("XQueryBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), // $NON-NLS-1$
e);
}
return success;
}
use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class OpenFlashChartComponent method executeAction.
protected boolean executeAction() {
// $NON-NLS-1$
log.debug("start to run open flash chart component......");
// input data
IPentahoResultSet data = (IPentahoResultSet) getInputValue(CHART_DATA);
if (!data.isScrollable()) {
// $NON-NLS-1$
getLogger().debug("ResultSet is not scrollable. Copying into memory");
IPentahoResultSet memSet = data.memoryCopy();
data.close();
data = memSet;
}
// chart width
String chartWidth = null;
String inputWidth = getInputStringValue(CHART_WIDTH);
if (inputWidth == null) {
chartWidth = DEFAULT_WIDTH;
} else {
chartWidth = inputWidth;
}
// chart height
String chartHeight = null;
String inputHeight = getInputStringValue(CHART_HEIGHT);
if (null == inputHeight) {
chartHeight = DEFAULT_HEIGHT;
} else {
chartHeight = inputHeight;
}
// swf file location
String ofcURL = getInputStringValue(OFC_URL);
if (ofcURL == null || "".equals(ofcURL)) {
// $NON-NLS-1$
ofcURL = PentahoRequestContextHolder.getRequestContext().getContextPath() + DEFAULT_FLASH_LOC;
}
// swf file name
String ofclibname = getInputStringValue(OFC_LIB_NAME);
if (ofclibname == null || "".equals(ofclibname)) {
// $NON-NLS-1$
ofclibname = DEFAULT_FLASH_SWF;
}
// chart definition
String chartAttributeString = null;
if (getInputNames().contains(CHART_ATTRIBUTES)) {
chartAttributeString = getInputStringValue(CHART_ATTRIBUTES);
} else if (isDefinedResource(CHART_ATTRIBUTES)) {
IActionSequenceResource resource = getResource(CHART_ATTRIBUTES);
chartAttributeString = getResourceAsString(resource);
}
Node chartNode = null;
if (chartAttributeString != null) {
// apply any additional inputs to the chart definition
chartAttributeString = applyInputsToFormat(chartAttributeString);
try {
Document chartDocument = XmlDom4JHelper.getDocFromString(chartAttributeString, new PentahoEntityResolver());
chartNode = chartDocument.selectSingleNode(CHART_NODE_LOC);
if (chartNode == null) {
chartNode = chartDocument.selectSingleNode(CHART_ATTRIBUTES);
}
} catch (XmlParseException e) {
getLogger().error(Messages.getInstance().getErrorString("OpenFlashChartComponent.ERROR_0001_CANT_DOCUMENT_FROM_STRING"), // $NON-NLS-1$
e);
return false;
}
} else {
// see if the chart-attributes node is available in the component definition
chartNode = getComponentDefinition(true).selectSingleNode(CHART_ATTRIBUTES);
}
if (chartNode == null) {
getLogger().error(// $NON-NLS-1$
Messages.getInstance().getErrorString("OpenFlashChartComponent.ERROR_0002_CHART_DEFINITION_NOT_FOUND"));
return false;
}
// Determine if we are going to read the chart data set by row or by column
boolean byRow = false;
if (getInputStringValue(BY_ROW_PROP) != null) {
byRow = Boolean.valueOf(getInputStringValue(BY_ROW_PROP)).booleanValue();
}
String chartJson = generateChartJson(data, chartNode, byRow);
// generate a unique name for the function
// $NON-NLS-1$ //$NON-NLS-2$
String chartId = UUIDUtil.getUUIDAsString().replaceAll("[^\\w]", "");
// populate the flash html template
Properties props = new Properties();
// $NON-NLS-1$
props.setProperty("chartId", chartId);
// $NON-NLS-1$ //$NON-NLS-2$
props.setProperty("dataFunction", "getData" + chartId);
// $NON-NLS-1$
props.setProperty("chart-width", chartWidth);
// $NON-NLS-1$
props.setProperty("chart-height", chartHeight);
// $NON-NLS-1$
props.setProperty("ofc-url", ofcURL);
// $NON-NLS-1$
props.setProperty("ofc-libname", ofclibname);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
props.setProperty("chartJson", chartJson.replaceAll("\"", "\\\\\""));
String flashContent = TemplateUtil.applyTemplate(getFlashFragment(), props, null);
// set output value
// $NON-NLS-1$
log.debug("html_fragment=" + flashContent);
if (this.isDefinedOutput("html_fragment")) {
// $NON-NLS-1$
// $NON-NLS-1$
this.setOutputValue("html_fragment", flashContent);
}
if (this.isDefinedOutput("image-tag")) {
// $NON-NLS-1$
// $NON-NLS-1$
this.setOutputValue("image-tag", flashContent);
}
return true;
}
Aggregations