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']"));
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations