use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class ResultSetCompareComponentTest method validation_fails_without_first_resultSets.
@Test
public void validation_fails_without_first_resultSets() {
IPentahoResultSet rs = Mockito.mock(IPentahoResultSet.class);
int actualValidateResult = callValidationWithResultSets(null, rs);
assertEquals(IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_FAIL, actualValidateResult);
}
use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class MDXBaseComponentTest method testExecutePrepared.
@Test
public void testExecutePrepared() throws Exception {
Map params = new HashMap();
when(conn.initialized()).thenReturn(true);
mdxBaseComponent.setConnection(conn);
mdxBaseComponent.preparedQuery = "select * from table where x = ?";
when(conn.executeQuery(anyString())).thenReturn(resultSet);
doReturn(runtimeContext).when(mdxBaseComponent).getRuntimeContext();
Set inputs = new HashSet();
when(runtimeContext.getInputNames()).thenReturn(inputs);
when(runtimeContext.getParameterManager()).thenReturn(paramManager);
when(paramManager.getCurrentInputNames()).thenReturn(inputs);
IPentahoResultSet result = mdxBaseComponent.executePrepared(params);
assertNotNull(result);
assertEquals(resultSet, result);
assertEquals(resultSet, mdxBaseComponent.getResultSet());
}
use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class TemplateUtilTest method testKeyedTableTemplate.
public void testKeyedTableTemplate() {
IRuntimeContext mockRuntimeContext = mock(IRuntimeContext.class);
IPentahoSession mockSession = mock(IPentahoSession.class);
IParameterManager mockParameterManager = mock(IParameterManager.class);
IPentahoResultSet mockPentahoResultSet = createMockResultSet();
IPentahoMetaData mockPentahoMetaData = mock(IPentahoMetaData.class);
final Set inputNames = new HashSet<Object>(Arrays.asList(new String[] { "param1" }));
when(mockParameterManager.getCurrentInputNames()).thenReturn(inputNames);
when(mockRuntimeContext.getSession()).thenReturn(mockSession);
when(mockRuntimeContext.getParameterManager()).thenReturn(mockParameterManager);
when(mockRuntimeContext.getInputParameterValue("param1")).thenReturn(mockPentahoResultSet);
when(mockRuntimeContext.getInputNames()).thenReturn(inputNames);
// "key_value" is parsed as "key value"
String template = "{param1:keycol:key_Value:valcol:defaultValue}";
assertEquals("field Value", TemplateUtil.applyTemplate(template, mockRuntimeContext));
}
use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class PMDUIComponent method getLookup.
public Document getLookup() {
// Create a document that describes the result
Document doc = DocumentHelper.createDocument();
// $NON-NLS-1$
Element root = doc.addElement("metadata");
if (domainName == null) {
// we can't do this without a model
// $NON-NLS-1$ //$NON-NLS-2$
root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_NO_DOMAIN_SPECIFIED"));
return doc;
}
if (modelId == null) {
// we can't do this without a view
// $NON-NLS-1$ //$NON-NLS-2$
root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_NO_MODEL_SPECIFIED"));
return doc;
}
if (columnId == null) {
// we can't do this without a view
// $NON-NLS-1$ //$NON-NLS-2$
root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_NO_COLUMN_SPECIFIED"));
return doc;
}
Domain domain = getMetadataRepository().getDomain(domainName);
String locale = LocaleHelper.getClosestLocale(LocaleHelper.getLocale().toString(), domain.getLocaleCodes());
// This is the business view that was selected.
LogicalModel model = domain.findLogicalModel(modelId);
if (model == null) {
// $NON-NLS-1$ //$NON-NLS-2$
root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_MODEL_LOADING_ERROR", modelId));
return doc;
}
LogicalColumn column = model.findLogicalColumn(columnId);
if (column == null) {
// $NON-NLS-1$ //$NON-NLS-2$
root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_COLUMN_NOT_FOUND"));
return doc;
}
// Temporary hack to get the BusinessCategory. When fixed properly, you should be able to interrogate the
// business column thingie for it's containing BusinessCategory.
Category view = null;
for (Category category : model.getCategories()) {
for (LogicalColumn col : category.getLogicalColumns()) {
if (col.getId().equals(column.getId())) {
view = category;
break;
}
}
}
if (view == null) {
// $NON-NLS-1$ //$NON-NLS-2$
root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_VIEW_NOT_FOUND"));
return doc;
}
String mql = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"<mql><domain_type>relational</domain_type><domain_id>" + domainName + "</domain_id><model_id>" + modelId + "</model_id>";
if (column.getProperty("lookup") == null) {
// $NON-NLS-1$
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
mql += "<selection><view>" + view.getId() + "</view><column>" + column.getId() + "</column></selection>";
mql += // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"<orders><order><direction>asc</direction><view_id>" + view.getId() + "</view_id><column_id>" + column.getId() + "</column_id></order></orders>";
} else {
// $NON-NLS-1$
String lookup = (String) column.getProperty("lookup");
// assume model and view are the same...
// $NON-NLS-1$
StringTokenizer tokenizer1 = new StringTokenizer(lookup, ";");
while (tokenizer1.hasMoreTokens()) {
// $NON-NLS-1$
StringTokenizer tokenizer2 = new StringTokenizer(tokenizer1.nextToken(), ".");
if (tokenizer2.countTokens() == 2) {
String lookupViewId = tokenizer2.nextToken();
String lookupColumnId = tokenizer2.nextToken();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
mql += "<selection><view>" + lookupViewId + "</view><column>" + lookupColumnId + "</column></selection>";
}
}
}
// $NON-NLS-1$
mql += "</mql>";
ArrayList messages = new ArrayList();
SimpleParameterProvider lookupParameters = new SimpleParameterProvider();
// $NON-NLS-1$
lookupParameters.setParameter("mql", mql);
IRuntimeContext runtime = SolutionHelper.doAction("/system/metadata/PickList.xaction", "lookup-list", lookupParameters, getSession(), messages, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
this);
IPentahoResultSet results = null;
if (runtime != null) {
if (runtime.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
if (runtime.getOutputNames().contains("data")) {
// $NON-NLS-1$
// $NON-NLS-1$
results = runtime.getOutputParameter("data").getValueAsResultSet();
Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
boolean hasColumnHeaders = columnHeaders != null;
Element rowElement;
// $NON-NLS-1$
Element dataElement = root.addElement("data");
if (hasColumnHeaders) {
for (int rowNo = 0; rowNo < columnHeaders.length; rowNo++) {
// $NON-NLS-1$
rowElement = dataElement.addElement("COLUMN-HDR-ROW");
for (int columnNo = 0; columnNo < columnHeaders[rowNo].length; columnNo++) {
// $NON-NLS-1$
Object nameAttr = results.getMetaData().getAttribute(rowNo, columnNo, "name");
if ((nameAttr != null) && (nameAttr instanceof LocalizedString)) {
LocalizedString str = (LocalizedString) nameAttr;
String name = str.getLocalizedString(locale);
if (name != null) {
// $NON-NLS-1$
rowElement.addElement("COLUMN-HDR-ITEM").setText(name);
} else {
// $NON-NLS-1$
rowElement.addElement("COLUMN-HDR-ITEM").setText(columnHeaders[rowNo][columnNo].toString());
}
} else {
// $NON-NLS-1$
rowElement.addElement("COLUMN-HDR-ITEM").setText(columnHeaders[rowNo][columnNo].toString());
}
}
}
}
Object[] row = results.next();
while (row != null) {
// $NON-NLS-1$
rowElement = dataElement.addElement("DATA-ROW");
for (Object element : row) {
if (element == null) {
// $NON-NLS-1$ //$NON-NLS-2$
rowElement.addElement("DATA-ITEM").setText("");
} else {
// $NON-NLS-1$
rowElement.addElement("DATA-ITEM").setText(element.toString());
}
}
row = results.next();
}
}
}
}
return doc;
}
use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.
the class WidgetGridComponent method getActionData.
protected IPentahoResultSet getActionData() {
// create an instance of the solution engine to execute the specified
// action
ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, getSession());
solutionEngine.setLoggingLevel(ILogger.DEBUG);
solutionEngine.init(getSession());
HashMap parameterProviders = getParameterProviders();
OutputStream outputStream = null;
SimpleOutputHandler outputHandler = null;
outputHandler = new SimpleOutputHandler(outputStream, false);
ArrayList messages = new ArrayList();
String processId = this.getClass().getName();
String actionSeqPath = ActionInfo.buildSolutionPath(solution, actionPath, actionName);
context = solutionEngine.execute(actionSeqPath, processId, false, true, instanceId, false, parameterProviders, outputHandler, null, urlFactory, messages);
if (actionOutput != null) {
if (context.getOutputNames().contains(actionOutput)) {
IActionParameter output = context.getOutputParameter(actionOutput);
IPentahoResultSet results = output.getValueAsResultSet();
if (results != null) {
results = results.memoryCopy();
}
return results;
} else {
// this is an error
return null;
}
} else {
// return the first list that we find...
Iterator it = context.getOutputNames().iterator();
while (it.hasNext()) {
IActionParameter output = (IActionParameter) it.next();
if (output.getType().equalsIgnoreCase(IActionParameter.TYPE_RESULT_SET)) {
IPentahoResultSet results = output.getValueAsResultSet();
if (results != null) {
results = results.memoryCopy();
}
return results;
}
}
}
return null;
}
Aggregations