use of org.pentaho.platform.api.engine.IApplicationContext in project pentaho-platform by pentaho.
the class JFreeReportHtmlComponent method performExport.
@SuppressWarnings("deprecation")
@Override
protected boolean performExport(final MasterReport report, final OutputStream outputStream) {
try {
String contentHandlerPattern = getInputStringValue(AbstractJFreeReportComponent.REPORTHTML_CONTENTHANDLER);
if (contentHandlerPattern == null) {
final Configuration globalConfig = ClassicEngineBoot.getInstance().getGlobalConfig();
// $NON-NLS-1$
contentHandlerPattern = globalConfig.getConfigProperty("org.pentaho.web.ContentHandler");
}
final IApplicationContext ctx = PentahoSystem.getApplicationContext();
final URLRewriter rewriter;
final ContentLocation dataLocation;
final NameGenerator dataNameGenerator;
if (ctx != null) {
// $NON-NLS-1$
File dataDirectory = new File(ctx.getFileOutputPath("system/tmp/"));
if (dataDirectory.exists() && (dataDirectory.isDirectory() == false)) {
dataDirectory = dataDirectory.getParentFile();
if (dataDirectory.isDirectory() == false) {
throw new ReportProcessingException(Messages.getInstance().getErrorString("JFreeReportDirectoryComponent.ERROR_0001_INVALID_DIR", // $NON-NLS-1$
dataDirectory.getPath()));
}
} else if (dataDirectory.exists() == false) {
dataDirectory.mkdirs();
}
final FileRepository dataRepository = new FileRepository(dataDirectory);
dataLocation = dataRepository.getRoot();
dataNameGenerator = new DefaultNameGenerator(dataLocation);
rewriter = new PentahoURLRewriter(contentHandlerPattern);
} else {
dataLocation = null;
dataNameGenerator = null;
rewriter = new PentahoURLRewriter(contentHandlerPattern);
}
final StreamRepository targetRepository = new StreamRepository(null, outputStream);
final ContentLocation targetRoot = targetRepository.getRoot();
final HtmlOutputProcessor outputProcessor = new StreamHtmlOutputProcessor(report.getConfiguration());
final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
// $NON-NLS-1$//$NON-NLS-2$
printer.setContentWriter(targetRoot, new DefaultNameGenerator(targetRoot, "index", "html"));
printer.setDataWriter(dataLocation, dataNameGenerator);
printer.setUrlRewriter(rewriter);
outputProcessor.setPrinter(printer);
final StreamReportProcessor sp = new StreamReportProcessor(report, outputProcessor);
final int yieldRate = getYieldRate();
if (yieldRate > 0) {
sp.addReportProgressListener(new YieldReportListener(yieldRate));
}
sp.processReport();
sp.close();
outputStream.flush();
close();
return true;
} catch (ReportProcessingException e) {
// $NON-NLS-1$
error(Messages.getInstance().getString("JFreeReportHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e);
return false;
} catch (IOException e) {
// $NON-NLS-1$
error(Messages.getInstance().getString("JFreeReportHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e);
return false;
} catch (ContentIOException e) {
// $NON-NLS-1$
error(Messages.getInstance().getString("JFreeReportHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e);
return false;
}
}
use of org.pentaho.platform.api.engine.IApplicationContext in project pentaho-platform by pentaho.
the class RuntimeContextTest method before.
@Before
public void before() {
mockedRuntimeRepository = mock(IRuntimeRepository.class);
mockedSolutionEngine = mock(ISolutionEngine.class);
mockedPentahoSystem = new MockUp<PentahoSystem>() {
@Mock
public <T> T get(Class<T> type, IPentahoSession session) {
if (type == IRuntimeRepository.class) {
return (T) mockedRuntimeRepository;
} else if (type == ISolutionEngine.class) {
return (T) mockedSolutionEngine;
}
throw new IllegalStateException("Unsupported type: " + type.getSimpleName());
}
@Mock
public void setApplicationContext(final IApplicationContext applicationContext) {
}
@Mock
public IApplicationContext getApplicationContext() {
final String solutionPath = ".";
final String applicationPath = "";
return new StandaloneApplicationContext(solutionPath, applicationPath);
}
};
runtimeCtx = new RuntimeContext("id", mockedSolutionEngine, "solutionName", makeRuntimeData(session), session, null, "processId", urlFactory, makeParameterProviders(session), new ArrayList<String>(), null);
}
use of org.pentaho.platform.api.engine.IApplicationContext in project pentaho-platform by pentaho.
the class BaseTestCase method getOutputStream.
protected OutputStream getOutputStream(String solnPath, String testName, String extension) {
OutputStream outputStream = null;
try {
IApplicationContext appContext = PentahoSystem.getApplicationContext();
// $NON-NLS-1$
String outputPath = solnPath + "/test/tmp";
String tmpDir = appContext.getFileOutputPath(outputPath);
// String tmpDir = PentahoSystem.getApplicationContext().getFileOutputPath(SOLUTION_PATH +"test/tmp");
// //$NON-NLS-1$
File file = new File(tmpDir);
file.mkdirs();
String path = // $NON-NLS-1$
PentahoSystem.getApplicationContext().getFileOutputPath(solnPath + "/test/tmp/" + testName + extension);
outputStream = new FileOutputStream(path);
} catch (FileNotFoundException e) {
// ignored
}
return outputStream;
}
use of org.pentaho.platform.api.engine.IApplicationContext 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.api.engine.IApplicationContext in project data-access by pentaho.
the class SerializeMultiTableServiceIT method testSerialize.
@Test
public void testSerialize() throws Exception {
if (ModelerMessagesHolder.getMessages() == null) {
ModelerMessagesHolder.setMessages(new SpoonModelerMessages());
}
try {
KettleEnvironment.init();
Props.init(Props.TYPE_PROPERTIES_EMPTY);
} catch (Exception e) {
// may already be initialized by another test
}
login("suzy", "", false);
String solutionStorage = AgileHelper.getDatasourceSolutionStorage();
String path = solutionStorage + RepositoryFile.SEPARATOR + "resources" + RepositoryFile.SEPARATOR + "metadata" + // $NON-NLS-1$ //$NON-NLS-2$
RepositoryFile.SEPARATOR;
String olapPath = null;
IApplicationContext appContext = PentahoSystem.getApplicationContext();
if (appContext != null) {
path = PentahoSystem.getApplicationContext().getSolutionPath(path);
olapPath = PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$ //$NON-NLS-2$
"system" + RepositoryFile.SEPARATOR + "olap" + RepositoryFile.SEPARATOR);
}
// $NON-NLS-1$
File olap1 = new File(olapPath + "datasources.xml");
// $NON-NLS-1$
File olap2 = new File(olapPath + "tmp_datasources.xml");
FileUtils.copyFile(olap1, olap2);
DatabaseMeta database = getDatabaseMeta();
MultiTableModelerSource multiTable = new MultiTableModelerSource(database, getSchema(), database.getName(), Arrays.asList("CUSTOMERS", "PRODUCTS", "CUSTOMERNAME", "PRODUCTCODE"));
Domain domain = multiTable.generateDomain();
List<OlapDimension> olapDimensions = new ArrayList<OlapDimension>();
OlapDimension dimension = new OlapDimension();
// $NON-NLS-1$
dimension.setName("test");
dimension.setTimeDimension(false);
olapDimensions.add(dimension);
// $NON-NLS-1$
domain.getLogicalModels().get(0).setProperty("olap_dimensions", olapDimensions);
ModelerService service = new ModelerService();
// $NON-NLS-1$
service.serializeModels(domain, "test_file");
Assert.assertEquals((String) domain.getLogicalModels().get(0).getProperty("MondrianCatalogRef"), "SampleData");
}
Aggregations