Search in sources :

Example 6 with IApplicationContext

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;
    }
}
Also used : FileRepository(org.pentaho.reporting.libraries.repository.file.FileRepository) Configuration(org.pentaho.reporting.libraries.base.config.Configuration) DefaultNameGenerator(org.pentaho.reporting.libraries.repository.DefaultNameGenerator) NameGenerator(org.pentaho.reporting.libraries.repository.NameGenerator) DefaultNameGenerator(org.pentaho.reporting.libraries.repository.DefaultNameGenerator) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException) IOException(java.io.IOException) PentahoURLRewriter(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoURLRewriter) StreamHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor) HtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlOutputProcessor) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException) URLRewriter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.URLRewriter) PentahoURLRewriter(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoURLRewriter) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) YieldReportListener(org.pentaho.reporting.engine.classic.core.layout.output.YieldReportListener) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) ContentLocation(org.pentaho.reporting.libraries.repository.ContentLocation) StreamHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor) StreamReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.StreamReportProcessor) File(java.io.File) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) HtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlPrinter) StreamRepository(org.pentaho.reporting.libraries.repository.stream.StreamRepository)

Example 7 with IApplicationContext

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);
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) Matchers.anyString(org.mockito.Matchers.anyString) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Mock(mockit.Mock) IRuntimeRepository(org.pentaho.platform.api.repository.IRuntimeRepository) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) Before(org.junit.Before)

Example 8 with IApplicationContext

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;
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) File(java.io.File)

Example 9 with IApplicationContext

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);
    }
}
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 10 with IApplicationContext

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");
}
Also used : MultiTableModelerSource(org.pentaho.agilebi.modeler.util.MultiTableModelerSource) SpoonModelerMessages(org.pentaho.agilebi.modeler.util.SpoonModelerMessages) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) Domain(org.pentaho.metadata.model.Domain) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) OlapDimension(org.pentaho.metadata.model.olap.OlapDimension) ModelerService(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ModelerService) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) DataAccessException(org.springframework.dao.DataAccessException) DuplicateDatasourceException(org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException) NonExistingDatasourceException(org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException) Test(org.junit.Test)

Aggregations

IApplicationContext (org.pentaho.platform.api.engine.IApplicationContext)20 File (java.io.File)9 IOException (java.io.IOException)5 Before (org.junit.Before)5 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)5 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 Matchers.anyString (org.mockito.Matchers.anyString)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 OutputStream (java.io.OutputStream)2 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)2 StandaloneApplicationContext (org.pentaho.platform.engine.core.system.StandaloneApplicationContext)2 PentahoEntityResolver (org.pentaho.platform.engine.services.solution.PentahoEntityResolver)2 PentahoURLRewriter (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoURLRewriter)2 ReportProcessingException (org.pentaho.reporting.engine.classic.core.ReportProcessingException)2 YieldReportListener (org.pentaho.reporting.engine.classic.core.layout.output.YieldReportListener)2 StreamReportProcessor (org.pentaho.reporting.engine.classic.core.modules.output.table.base.StreamReportProcessor)2 AllItemsHtmlPrinter (org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter)2 HtmlOutputProcessor (org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlOutputProcessor)2