Search in sources :

Example 26 with IPentahoResultSet

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);
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) Test(org.junit.Test)

Example 27 with IPentahoResultSet

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());
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) HashSet(java.util.HashSet) Set(java.util.Set) MDXResultSet(org.pentaho.platform.plugin.services.connections.mondrian.MDXResultSet) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with IPentahoResultSet

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));
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IParameterManager(org.pentaho.platform.api.engine.IParameterManager) Set(java.util.Set) HashSet(java.util.HashSet) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) HashSet(java.util.HashSet)

Example 29 with IPentahoResultSet

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;
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) Document(org.dom4j.Document) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalModel(org.pentaho.metadata.model.LogicalModel) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) StringTokenizer(java.util.StringTokenizer) Domain(org.pentaho.metadata.model.Domain) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 30 with IPentahoResultSet

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;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Aggregations

IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)113 Test (org.junit.Test)26 Node (org.dom4j.Node)18 ArrayList (java.util.ArrayList)17 IPentahoMetaData (org.pentaho.commons.connection.IPentahoMetaData)12 Iterator (java.util.Iterator)10 List (java.util.List)10 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)10 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)10 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)10 OutputStream (java.io.OutputStream)9 ResultSetCompareAction (org.pentaho.actionsequence.dom.actions.ResultSetCompareAction)8 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)8 XQConnection (org.pentaho.platform.plugin.services.connections.xquery.XQConnection)8 SQLException (java.sql.SQLException)7 HashMap (java.util.HashMap)6 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)6 Map (java.util.Map)5 Set (java.util.Set)5 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)5