Search in sources :

Example 6 with PentahoEntityResolver

use of org.pentaho.platform.engine.services.solution.PentahoEntityResolver in project pentaho-platform by pentaho.

the class PentahoXmlaServletTest method testMakeContentFinderHandlesXmlaEnablement.

@Test
public void testMakeContentFinderHandlesXmlaEnablement() throws Exception {
    ISecurityHelper securityHelper = mock(ISecurityHelper.class);
    SecurityHelper.setMockInstance(securityHelper);
    when(securityHelper.runAsSystem(any((Callable.class)))).thenReturn(DATASOURCE_XML);
    Document content = XmlDom4JHelper.getDocFromString(new PentahoXmlaServlet().makeContentFinder("fakeurl").getContent(), new PentahoEntityResolver());
    assertEquals(2, content.selectNodes("/DataSources/DataSource/Catalogs/Catalog").size());
    assertNotNull(content.selectNodes("/DataSources/DataSource/Catalogs/Catalog[@name='EnabledCatalog']"));
    assertNotNull(content.selectNodes("/DataSources/DataSource/Catalogs/Catalog[@name='FoodMart']"));
}
Also used : ISecurityHelper(org.pentaho.platform.api.engine.ISecurityHelper) Document(org.dom4j.Document) PentahoEntityResolver(org.pentaho.platform.engine.services.solution.PentahoEntityResolver) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with PentahoEntityResolver

use of org.pentaho.platform.engine.services.solution.PentahoEntityResolver in project pentaho-platform by pentaho.

the class PentahoFlashChartTest method getChartNode.

public static Node getChartNode(String xml) {
    try {
        Document chartDocument = XmlDom4JHelper.getDocFromString(xml, new PentahoEntityResolver());
        Node chartNode = chartDocument.selectSingleNode("chart");
        if (chartNode == null) {
            chartNode = chartDocument.selectSingleNode("chart-attributes");
        }
        return chartNode;
    } catch (XmlParseException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Node(org.dom4j.Node) XmlParseException(org.pentaho.platform.api.util.XmlParseException) Document(org.dom4j.Document) PentahoEntityResolver(org.pentaho.platform.engine.services.solution.PentahoEntityResolver)

Example 8 with PentahoEntityResolver

use of org.pentaho.platform.engine.services.solution.PentahoEntityResolver in project pentaho-platform by pentaho.

the class HibernateUtil method initialize.

protected static boolean initialize() {
    IApplicationContext applicationContext = PentahoSystem.getApplicationContext();
    // Add to entry/exit points list
    HibernateUtil hUtil = new HibernateUtil();
    applicationContext.addEntryPointHandler(hUtil);
    applicationContext.addExitPointHandler(hUtil);
    // Look for some hibernate-specific properties...
    String hibernateConfigurationFile = lookupSetting(// $NON-NLS-1$
    applicationContext, // $NON-NLS-1$
    "hibernateConfigPath", // $NON-NLS-1$
    "settings/config-file", // $NON-NLS-1$
    "hibernate/hibernateConfigPath");
    String hibernateManagedString = lookupSetting(// $NON-NLS-1$
    applicationContext, // $NON-NLS-1$
    "hibernateManaged", // $NON-NLS-1$
    "settings/managed", // $NON-NLS-1$
    "hibernate/hibernateManaged");
    if (hibernateManagedString != null) {
        hibernateManaged = Boolean.parseBoolean(hibernateManagedString);
    }
    try {
        HibernateUtil.configuration = new Configuration();
        HibernateUtil.configuration.setEntityResolver(new PentahoEntityResolver());
        // $NON-NLS-1$
        HibernateUtil.configuration.setListener("load", new HibernateLoadEventListener());
        if (hibernateConfigurationFile != null) {
            String configPath = applicationContext.getSolutionPath(hibernateConfigurationFile);
            File cfgFile = new File(configPath);
            if (cfgFile.exists()) {
                HibernateUtil.configuration.configure(cfgFile);
            } else {
                HibernateUtil.log.error(Messages.getInstance().getErrorString("HIBUTIL.ERROR_0012_CONFIG_NOT_FOUND", // $NON-NLS-1$
                configPath));
                return false;
            }
        } else {
            // Assume defaults which means we hope Hibernate finds a configuration
            // file in a file named hibernate.cfg.xml
            HibernateUtil.log.error(Messages.getInstance().getErrorString(// $NON-NLS-1$
            "HIBUTIL.ERROR_0420_CONFIGURATION_ERROR_NO_HIB_CFG_FILE_SETTING"));
            HibernateUtil.configuration.configure();
        }
        // $NON-NLS-1$
        String dsName = HibernateUtil.configuration.getProperty("connection.datasource");
        if ((dsName != null) && dsName.toUpperCase().endsWith("HIBERNATE")) {
            // $NON-NLS-1$
            // IDBDatasourceService datasourceService =  (IDBDatasourceService) PentahoSystem.getObjectFactory().getObject("IDBDatasourceService",null);     //$NON-NLS-1$
            IDBDatasourceService datasourceService = getDatasourceService();
            // $NON-NLS-1$
            String actualDSName = datasourceService.getDSBoundName("Hibernate");
            // $NON-NLS-1$
            HibernateUtil.configuration.setProperty("hibernate.connection.datasource", actualDSName);
        }
        // $NON-NLS-1$
        HibernateUtil.dialect = HibernateUtil.configuration.getProperty("dialect");
        /*
       * configuration.addResource("org/pentaho/platform/repository/runtime/RuntimeElement.hbm.xml"); //$NON-NLS-1$
       * configuration.addResource("org/pentaho/platform/repository/content/ContentLocation.hbm.xml"); //$NON-NLS-1$
       * configuration.addResource("org/pentaho/platform/repository/content/ContentItem.hbm.xml"); //$NON-NLS-1$
       * configuration.addResource("org/pentaho/platform/repository/content/ContentItemFile.hbm.xml"); //$NON-NLS-1$
       */
        if (!HibernateUtil.hibernateManaged) {
            // $NON-NLS-1$
            HibernateUtil.log.info(Messages.getInstance().getString("HIBUTIL.USER_HIBERNATEUNMANAGED"));
            HibernateUtil.sessionFactory = HibernateUtil.configuration.buildSessionFactory();
        } else {
            HibernateUtil.factoryJndiName = HibernateUtil.configuration.getProperty(Environment.SESSION_FACTORY_NAME);
            if (HibernateUtil.factoryJndiName == null) {
                HibernateUtil.log.error(Messages.getInstance().getErrorString("HIBUTIL.ERROR_0013_NO_SESSION_FACTORY"));
                return false;
            }
            // $NON-NLS-1$
            HibernateUtil.log.info(Messages.getInstance().getString("HIBUTIL.USER_HIBERNATEMANAGED"));
            // Let hibernate Bind it
            HibernateUtil.configuration.buildSessionFactory();
            // to JNDI...
            // BISERVER-2006: Below content is a community contribution see the JIRA case for more info
            // -------- Begin Contribution --------
            // Build the initial context to use when looking up the session
            Properties contextProperties = new Properties();
            if (configuration.getProperty("hibernate.jndi.url") != null) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                contextProperties.put(Context.PROVIDER_URL, configuration.getProperty("hibernate.jndi.url"));
            }
            if (configuration.getProperty("hibernate.jndi.class") != null) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                contextProperties.put(Context.INITIAL_CONTEXT_FACTORY, configuration.getProperty("hibernate.jndi.class"));
            }
            iniCtx = new InitialContext(contextProperties);
        // --------- End Contribution ---------
        }
        Dialect.getDialect(HibernateUtil.configuration.getProperties());
        return true;
    } catch (Throwable ex) {
        // $NON-NLS-1$
        HibernateUtil.log.error(Messages.getInstance().getErrorString("HIBUTIL.ERROR_0006_BUILD_SESSION_FACTORY"), ex);
        throw new ExceptionInInitializerError(ex);
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) Properties(java.util.Properties) PentahoEntityResolver(org.pentaho.platform.engine.services.solution.PentahoEntityResolver) File(java.io.File) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService) InitialContext(javax.naming.InitialContext)

Example 9 with PentahoEntityResolver

use of org.pentaho.platform.engine.services.solution.PentahoEntityResolver 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);
}
Also used : JavaScriptResultSet(org.pentaho.platform.plugin.services.connections.javascript.JavaScriptResultSet) Node(org.dom4j.Node) ArrayList(java.util.ArrayList) MemoryMetaData(org.pentaho.commons.connection.memory.MemoryMetaData) Document(org.dom4j.Document) PentahoEntityResolver(org.pentaho.platform.engine.services.solution.PentahoEntityResolver) Test(org.junit.Test)

Example 10 with PentahoEntityResolver

use of org.pentaho.platform.engine.services.solution.PentahoEntityResolver in project pentaho-platform by pentaho.

the class MondrianCatalogHelper method writeDataSources.

@Deprecated
protected void writeDataSources(DataSources dataSources) {
    File dataSourcesFile;
    try {
        // dataSourcesConfigResource.getFile();
        dataSourcesFile = new File(new URL(dataSourcesConfig).getFile());
    } catch (IOException e) {
        throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0005_RESOURCE_NOT_AVAILABLE"), e, // $NON-NLS-1$
        Reason.GENERAL);
    }
    Writer sxml;
    try {
        sxml = new FileWriter(dataSourcesFile);
    } catch (IOException e) {
        throw new MondrianCatalogServiceException(e);
    }
    StringWriter sw = new StringWriter();
    XMLOutput pxml = new XMLOutput(sw);
    // $NON-NLS-1$
    pxml.print("<?xml version=\"1.0\"?>\n");
    dataSources.displayXML(pxml, 0);
    Document doc = null;
    try {
        doc = XmlDom4JHelper.getDocFromString(sw.toString(), new PentahoEntityResolver());
    } catch (XmlParseException e) {
        throw new MondrianCatalogServiceException(e);
    }
    // pretty print
    try {
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setEncoding(doc.getXMLEncoding());
        XMLWriter writer = new XMLWriter(sxml, format);
        writer.write(doc);
        writer.close();
    // CleanXmlHelper.saveDomToWriter(doc, sxml);
    } catch (IOException e) {
        throw new MondrianCatalogServiceException(e);
    }
    IOUtils.closeQuietly(sxml);
}
Also used : FileWriter(java.io.FileWriter) XMLOutput(org.eigenbase.xom.XMLOutput) OutputFormat(org.dom4j.io.OutputFormat) IOException(java.io.IOException) XmlParseException(org.pentaho.platform.api.util.XmlParseException) Document(org.dom4j.Document) PentahoEntityResolver(org.pentaho.platform.engine.services.solution.PentahoEntityResolver) XMLWriter(org.dom4j.io.XMLWriter) URL(java.net.URL) StringWriter(java.io.StringWriter) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) Writer(java.io.Writer) XMLWriter(org.dom4j.io.XMLWriter) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter)

Aggregations

PentahoEntityResolver (org.pentaho.platform.engine.services.solution.PentahoEntityResolver)12 Document (org.dom4j.Document)10 Node (org.dom4j.Node)7 XmlParseException (org.pentaho.platform.api.util.XmlParseException)6 List (java.util.List)5 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 Element (org.dom4j.Element)2 Test (org.junit.Test)2 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)2 IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)2 IApplicationContext (org.pentaho.platform.api.engine.IApplicationContext)2 BufferedWriter (java.io.BufferedWriter)1