Search in sources :

Example 6 with PropertyList

use of mondrian.olap.Util.PropertyList in project mondrian by pentaho.

the class XmlaTest method runTest.

protected void runTest() throws Exception {
    if (!MondrianProperties.instance().SsasCompatibleNaming.get() && getName().equals("mdschemaLevelsCubeDimRestrictions")) {
        // fixed by a few sed-like comparisons.
        return;
    }
    DiffRepository diffRepos = getDiffRepos();
    String request = diffRepos.expand(null, "${request}");
    String expectedResponse = diffRepos.expand(null, "${response}");
    Properties props = new Properties();
    XmlaTestContext s = new XmlaTestContext();
    String con = s.getConnectString().replaceAll("&", "&");
    PropertyList pl = Util.parseConnectString(con);
    pl.remove(RolapConnectionProperties.Jdbc.name());
    pl.remove(RolapConnectionProperties.JdbcUser.name());
    pl.remove(RolapConnectionProperties.JdbcPassword.name());
    props.setProperty(DATA_SOURCE_INFO_RESPONSE_PROP, pl.toString());
    expectedResponse = Util.replaceProperties(expectedResponse, Util.toMap(props));
    Element requestElem = XmlaUtil.text2Element(XmlaTestContext.xmlFromTemplate(request, XmlaTestContext.ENV));
    Element responseElem = ignoreLastUpdateDate(executeRequest(requestElem));
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer();
    StringWriter bufWriter = new StringWriter();
    transformer.transform(new DOMSource(responseElem), new StreamResult(bufWriter));
    bufWriter.write(Util.nl);
    String actualResponse = TestContext.instance().upgradeActual(bufWriter.getBuffer().toString());
    try {
        // Start with a purely logical XML diff to avoid test noise
        // from non-determinism in XML generation.
        XMLAssert.assertXMLEqual(expectedResponse, actualResponse);
    } catch (AssertionFailedError e) {
        // In case of failure, re-diff using DiffRepository's comparison
        // method. It may have noise due to physical vs logical structure,
        // but it will maintain the expected/actual, and some IDEs can even
        // display visual diffs.
        diffRepos.assertEquals("response", "${response}", actualResponse);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) PropertyList(mondrian.olap.Util.PropertyList) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) DiffRepository(mondrian.test.DiffRepository) Properties(java.util.Properties) RolapConnectionProperties(mondrian.rolap.RolapConnectionProperties)

Example 7 with PropertyList

use of mondrian.olap.Util.PropertyList in project mondrian by pentaho.

the class Workbench method checkSchemaFile.

/**
 * Check if schema file is valid by initiating a mondrian connection.
 */
private void checkSchemaFile(File file) {
    try {
        // this connection parses the catalog file which if invalid will
        // throw exception
        PropertyList list = new PropertyList();
        list.put("Provider", "mondrian");
        list.put("Jdbc", jdbcConnectionUrl);
        list.put("Catalog", file.toURI().toURL().toString());
        list.put("JdbcDrivers", jdbcDriverClassName);
        if (jdbcUsername != null && jdbcUsername.length() > 0) {
            list.put("JdbcUser", jdbcUsername);
        }
        if (jdbcPassword != null && jdbcPassword.length() > 0) {
            list.put("JdbcPassword", jdbcPassword);
        }
        DriverManager.getConnection(list, null);
    } catch (Exception ex) {
        LOGGER.error("Exception : Schema file " + file.getAbsolutePath() + " is invalid." + ex.getMessage(), ex);
    } catch (Error err) {
        LOGGER.error("Error : Schema file " + file.getAbsolutePath() + " is invalid." + err.getMessage(), err);
    }
}
Also used : PropertyList(mondrian.olap.Util.PropertyList) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException)

Example 8 with PropertyList

use of mondrian.olap.Util.PropertyList in project mondrian by pentaho.

the class QueryPanel method connectButtonActionPerformed.

private void connectButtonActionPerformed(ActionEvent evt) {
    File sfile = null;
    try {
        String sfname = (String) schemaList.getSelectedItem();
        JInternalFrame sf = lookupFrame(sfname);
        if (sf == null) {
            // this case may arise when a schema file is opened, mdx query
            // is opened and the schema frame is closed
            JOptionPane.showMessageDialog(this, getResourceConverter().getString("queryPanel.schemaNotOpen.alert", "Schema file is not open"), getResourceConverter().getString("common.errorDialog.title", "Error"), JOptionPane.ERROR_MESSAGE);
            return;
        }
        SchemaExplorer se = (SchemaExplorer) sf.getContentPane().getComponent(0);
        if (se.isNewFile()) {
            JOptionPane.showMessageDialog(this, getResourceConverter().getString("queryPanel.saveSchemaFirst.alert", "You must first save the Schema to open a Mondrian connection"), getResourceConverter().getString("common.alertDialog.title", "Alert"), JOptionPane.WARNING_MESSAGE);
            sf.setSelected(true);
            return;
        }
        sfile = se.getSchemaFile();
        PropertyList list = new PropertyList();
        list.put("Provider", "mondrian");
        list.put("Jdbc", se.getJdbcConnectionUrl());
        list.put("Catalog", se.getSchemaFile().toURL().toString());
        final String jdbcUsername = se.getJdbcUsername();
        if (!ValidationUtils.isEmpty(jdbcUsername)) {
            list.put("JdbcUser", jdbcUsername);
        }
        final String jdbcPassword = se.getJdbcPassword();
        if (!ValidationUtils.isEmpty(jdbcPassword)) {
            list.put("JdbcPassword", jdbcPassword);
        }
        Connection con = DriverManager.getConnection(list, null);
        // clear cache before connecting
        con.getCacheControl(null).flushSchemaCache();
        if (con != null) {
            connection = con;
            queryMenuItem.setText(getResourceConverter().getFormattedString("queryPanel.successfulConnection.menuItem", "{0} MDX - {1}", Integer.toString(windowMenuIndex), se.getSchemaFile().getName()));
            Component o = this;
            while (o != null) {
                if (o.getClass() == JInternalFrame.class) {
                    ((JInternalFrame) o).setTitle(getResourceConverter().getFormattedString("queryPanel.successfulConnection.internalFrame.title", "MDX Query - connected to {0}", se.getSchemaFile().getName()));
                    break;
                }
                o = o.getParent();
            }
            JOptionPane.showMessageDialog(this, "Mondrian connection Successful.", getResourceConverter().getString("common.informationDialog.title", "Information"), JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, getResourceConverter().getFormattedString("queryPanel.unsuccessfulConnection.alert", "Mondrian connection could not be done for - {0}", se.getSchemaFile().getName()), getResourceConverter().getString("common.errorDialog.title", "Error"), JOptionPane.ERROR_MESSAGE);
        }
    } catch (Exception ex) {
        LOGGER.error("Exception: " + ex.getMessage(), ex);
        JOptionPane.showMessageDialog(this, getResourceConverter().getFormattedString("queryPanel.unsuccessfulConnection.exception", "Mondrian connection could not be done for - {0}", sfile == null ? getResourceConverter().getString("queryPanel.selectedSchema.alert", "selected Schema") : sfile.getName()), getResourceConverter().getString("common.errorDialog.title", "Error"), JOptionPane.ERROR_MESSAGE);
        resultTextPane.setText(getResourceConverter().getFormattedString("queryPanel.exceptionMessage", "Exception: {0}\n\nSee workbench log for full stacktrace.", ex.getMessage()));
    }
}
Also used : PropertyList(mondrian.olap.Util.PropertyList)

Example 9 with PropertyList

use of mondrian.olap.Util.PropertyList in project pentaho-platform by pentaho.

the class MondrianCatalogHelper method applyDSP.

protected String applyDSP(IPentahoSession ps, String catalogDsInfo, String catalogDefinition) throws Exception {
    PropertyList pl = Util.parseConnectString(catalogDsInfo);
    String dsp = pl.get(RolapConnectionProperties.DynamicSchemaProcessor.name());
    if (dsp != null) {
        if (MondrianCatalogHelper.logger.isDebugEnabled()) {
            // $NON-NLS-1$
            MondrianCatalogHelper.logger.debug("applyDSP: " + dsp);
        }
        DynamicSchemaProcessor dynProc = ClassResolver.INSTANCE.instantiateSafe(dsp);
        pl.put("Locale", getLocale().toString());
        return dynProc.processSchema(catalogDefinition, pl);
    } else {
        return docAtUrlToString(catalogDefinition, ps);
    }
}
Also used : PropertyList(mondrian.olap.Util.PropertyList) LocalizingDynamicSchemaProcessor(mondrian.i18n.LocalizingDynamicSchemaProcessor) DynamicSchemaProcessor(mondrian.spi.DynamicSchemaProcessor)

Example 10 with PropertyList

use of mondrian.olap.Util.PropertyList in project pentaho-platform by pentaho.

the class MondrianCatalogHelper method docAtUrlToString.

protected String docAtUrlToString(final String urlStr, final IPentahoSession pentahoSession) {
    // String relPath = getSolutionRepositoryRelativePath(urlStr, pentahoSession);
    String res = null;
    InputStream in = null;
    try {
        LocalizingDynamicSchemaProcessor schemaProcessor = new LocalizingDynamicSchemaProcessor();
        PropertyList localeInfo = new PropertyList();
        // $NON-NLS-1$
        localeInfo.put("Locale", getLocale().toString());
        FileSystemManager fsManager = VFS.getManager();
        FileObject mondrianDS = fsManager.resolveFile(urlStr);
        in = mondrianDS.getContent().getInputStream();
        res = schemaProcessor.filter(null, localeInfo, in);
    } catch (FileNotFoundException fnfe) {
        throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0007_FILE_NOT_FOUND"), // $NON-NLS-1$
        fnfe);
    } catch (Exception e) {
        throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0006_IO_PROBLEM"), // $NON-NLS-1$
        e);
    } finally {
        IOUtils.closeQuietly(in);
    }
    return res;
}
Also used : LocalizingDynamicSchemaProcessor(mondrian.i18n.LocalizingDynamicSchemaProcessor) PropertyList(mondrian.olap.Util.PropertyList) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) FileObject(org.apache.commons.vfs2.FileObject) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) XOMException(org.eigenbase.xom.XOMException) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileNotFoundException(java.io.FileNotFoundException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) XmlParseException(org.pentaho.platform.api.util.XmlParseException) SAXException(org.xml.sax.SAXException) MondrianException(mondrian.olap.MondrianException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

PropertyList (mondrian.olap.Util.PropertyList)10 SQLException (java.sql.SQLException)2 LocalizingDynamicSchemaProcessor (mondrian.i18n.LocalizingDynamicSchemaProcessor)2 OlapException (org.olap4j.OlapException)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 MondrianException (mondrian.olap.MondrianException)1 MondrianServer (mondrian.olap.MondrianServer)1