use of org.pentaho.platform.plugin.services.connections.javascript.JavaScriptResultSet in project pentaho-platform by pentaho.
the class OpenFlashChartComponentTest method testAutoRange.
@Test
public void testAutoRange() throws Exception {
// Line Chart
JavaScriptResultSet query_result = new JavaScriptResultSet();
List<String> cols = new ArrayList<String>();
cols.add("MESES");
cols.add("ACTUAL");
cols.add("ANTERIOR");
query_result.setMetaData(new MemoryMetaData(cols));
query_result.addRow(new Object[] { "Enero", 0, 0 });
query_result.addRow(new Object[] { "Febrero", 0, 0 });
query_result.addRow(new Object[] { "Marzo", 0, 0 });
query_result.addRow(new Object[] { "Abril", 0, 0 });
query_result.addRow(new Object[] { "Mayo", 0, 0 });
query_result.addRow(new Object[] { "Junio", 0, 0 });
query_result.addRow(new Object[] { "Julio", 6, 3 });
Document chartDocument = XmlDom4JHelper.getDocFromString("<chart><chart-type>LineChart</chart-type></chart>", new PentahoEntityResolver());
Node chartNode = chartDocument.selectSingleNode("chart");
String json = PentahoOFC4JChartHelper.generateChartJson(chartNode, query_result, false, null);
System.out.println(json);
Assert.assertTrue(json.indexOf("\"min\":0") >= 0 && json.indexOf("\"max\":6") >= 0);
}
use of org.pentaho.platform.plugin.services.connections.javascript.JavaScriptResultSet in project pentaho-platform by pentaho.
the class JavascriptRule method executeScript.
protected Object executeScript(final ScriptableObject scriptable, final Scriptable scope, final String script, final Context cx) throws Exception {
ScriptableObject.defineClass(scope, JavaScriptResultSet.class);
@SuppressWarnings("unchecked") Set<String> inputNames = getInputNames();
Iterator<String> inputNamesIterator = inputNames.iterator();
String inputName;
Object inputValue;
while (inputNamesIterator.hasNext()) {
inputName = (String) inputNamesIterator.next();
if (inputName.indexOf('-') >= 0) {
throw new IllegalArgumentException(Messages.getInstance().getErrorString("JSRULE.ERROR_0006_INVALID_JS_VARIABLE", // $NON-NLS-1$
inputName));
}
inputValue = getInputValue(inputName);
if (inputValue instanceof String) {
inputValue = StringEscapeUtils.escapeHtml((String) inputValue);
}
Object wrapper;
if (inputValue instanceof IPentahoResultSet) {
JavaScriptResultSet results = new JavaScriptResultSet();
// Required as of Rhino 1.7R1 to resolve caching, base object
// inheritance and property tree
results.setPrototype(scriptable);
results.setResultSet((IPentahoResultSet) inputValue);
wrapper = Context.javaToJS(inputValue, results);
} else {
wrapper = Context.javaToJS(inputValue, scope);
}
ScriptableObject.putProperty(scope, inputName, wrapper);
}
// Add system out and this object to the scope
Object wrappedOut = Context.javaToJS(System.out, scope);
Object wrappedThis = Context.javaToJS(this, scope);
// $NON-NLS-1$
ScriptableObject.putProperty(scope, "out", wrappedOut);
// $NON-NLS-1$
ScriptableObject.putProperty(scope, "rule", wrappedThis);
// $NON-NLS-1$
return cx.evaluateString(scope, script, "<cmd>", 1, null);
}
use of org.pentaho.platform.plugin.services.connections.javascript.JavaScriptResultSet in project pentaho-platform by pentaho.
the class JavaScriptResultSetIT method testIterators.
public void testIterators() {
MemoryMetaData metadata = new MemoryMetaData(new String[][] { { "col1", "col2" } }, null);
MemoryResultSet dataSet = new MemoryResultSet(metadata);
JavaScriptResultSet data = new JavaScriptResultSet();
data.setResultSet(dataSet);
data.addRow(new Object[] { "a", new Integer(1) });
data.addRow(new Object[] { "b", new Integer(2) });
data.addRow(new Object[] { "c", new Integer(3) });
assertEquals(3, data.getRowCount());
assertEquals("a", data.getValueAt(0, 0));
assertEquals(1, data.getValueAt(0, 1));
assertEquals("b", data.getValueAt(1, 0));
assertEquals(2, data.getValueAt(1, 1));
assertEquals("c", data.getValueAt(2, 0));
assertEquals(3, data.getValueAt(2, 1));
assertEquals("a", data.next()[0]);
assertEquals("b", data.next()[0]);
assertEquals("c", data.next()[0]);
assertNull(data.next());
data.beforeFirst();
assertEquals("a", data.next()[0]);
assertEquals("b", data.next()[0]);
assertEquals("c", data.next()[0]);
assertNull(data.next());
data.close();
assertEquals("a", data.next()[0]);
assertEquals("b", data.next()[0]);
assertEquals("c", data.next()[0]);
assertNull(data.next());
data.closeConnection();
assertEquals("a", data.next()[0]);
assertEquals("b", data.next()[0]);
assertEquals("c", data.next()[0]);
assertNull(data.next());
data.dispose();
assertEquals("a", data.next()[0]);
assertEquals("b", data.next()[0]);
assertEquals("c", data.next()[0]);
assertNull(data.next());
}
use of org.pentaho.platform.plugin.services.connections.javascript.JavaScriptResultSet in project pentaho-platform by pentaho.
the class JavaScriptResultSetIT method testGetDataRow.
public void testGetDataRow() {
MemoryMetaData metadata = new MemoryMetaData(new String[][] { { "col1", "col2" } }, null);
MemoryResultSet dataSet = new MemoryResultSet(metadata);
JavaScriptResultSet data = new JavaScriptResultSet();
data.setResultSet(dataSet);
data.addRow(new Object[] { "a", new Integer(1) });
data.addRow(new Object[] { "b", new Integer(2) });
data.addRow(new Object[] { "c", new Integer(3) });
Object[] row = data.getDataRow(0);
assertEquals(2, row.length);
assertEquals("a", row[0]);
assertEquals(1, row[1]);
row = data.getDataRow(1);
assertEquals("b", row[0]);
assertEquals(2, row[1]);
row = data.getDataRow(2);
assertEquals("c", row[0]);
assertEquals(3, row[1]);
assertNull(data.getDataRow(99));
}
use of org.pentaho.platform.plugin.services.connections.javascript.JavaScriptResultSet in project pentaho-platform by pentaho.
the class JavaScriptResultSetIT method testGetDataColumn.
public void testGetDataColumn() {
MemoryMetaData metadata = new MemoryMetaData(new String[][] { { "col1", "col2" } }, null);
MemoryResultSet dataSet = new MemoryResultSet(metadata);
JavaScriptResultSet data = new JavaScriptResultSet();
data.setResultSet(dataSet);
data.addRow(new Object[] { "a", new Integer(1) });
data.addRow(new Object[] { "b", new Integer(2) });
data.addRow(new Object[] { "c", new Integer(3) });
Object[] col = data.getDataColumn(0);
assertEquals(3, col.length);
assertEquals("a", col[0]);
assertEquals("b", col[1]);
assertEquals("c", col[2]);
col = data.getDataColumn(1);
assertEquals(3, col.length);
assertEquals(1, col[0]);
assertEquals(2, col[1]);
assertEquals(3, col[2]);
}
Aggregations