Search in sources :

Example 11 with IApplicationContext

use of org.pentaho.platform.api.engine.IApplicationContext in project data-access by pentaho.

the class DebugModelerService method serializeModels.

public String serializeModels(Domain domain, String name) throws Exception {
    String domainId;
    PentahoSystemHelper.init();
    initKettle();
    try {
        DSWDatasourceServiceImpl datasourceService = new DSWDatasourceServiceImpl();
        ModelerWorkspace model = new ModelerWorkspace(new GwtModelerWorkspaceHelper(), datasourceService.getGeoContext());
        model.setModelName(name);
        model.setDomain(domain);
        String solutionStorage = AgileHelper.getDatasourceSolutionStorage();
        // $NON-NLS-1$  //$NON-NLS-2$
        String metadataLocation = "resources" + RepositoryFile.SEPARATOR + "metadata";
        String path = solutionStorage + RepositoryFile.SEPARATOR + metadataLocation + RepositoryFile.SEPARATOR;
        // $NON-NLS-1$
        domainId = path + name + ".xmi";
        IApplicationContext appContext = PentahoSystem.getApplicationContext();
        if (appContext != null) {
            path = PentahoSystem.getApplicationContext().getSolutionPath(path);
        }
        File pathDir = new File(path);
        if (!pathDir.exists()) {
            pathDir.mkdirs();
        }
        IPentahoSession session = getSession();
        // Keep a reference to the mondrian catalog
        model.getWorkspaceHelper().populateDomain(model);
        LogicalModel lModel = domain.getLogicalModels().get(0);
        String catName = lModel.getName(LocalizedString.DEFAULT_LOCALE);
        // $NON-NLS-1$
        lModel.setProperty("MondrianCatalogRef", catName);
        // Serialize domain to xmi.
        /*
        DISABLED DUE TO USE OF OLD API
      String base = PentahoSystem.getApplicationContext().getSolutionRootPath();
      String parentPath = ActionInfo.buildSolutionPath(solutionStorage, metadataLocation, ""); //$NON-NLS-1$
      int status = repository.publish(base, '/' + parentPath, name + ".xmi", reportXML.getBytes("UTF-8"),
      true); //$NON-NLS-1$ //$NON-NLS-2$
      if (status != ISolutionRepository.FILE_ADD_SUCCESSFUL) {
        throw new RuntimeException("Unable to save to repository. Status: " + status); //$NON-NLS-1$
      }

      // Serialize domain to olap schema.
      lModel = domain.getLogicalModels().get(1);
      MondrianModelExporter exporter = new MondrianModelExporter(lModel, LocalizedString.DEFAULT_LOCALE);
      String mondrianSchema = exporter.createMondrianModelXML();
      Document schemaDoc = DocumentHelper.parseText(mondrianSchema);
      byte[] schemaBytes = schemaDoc.asXML().getBytes("UTF-8"); //$NON-NLS-1$

      status = repository.publish(base, '/' + parentPath, name + ".mondrian.xml", schemaBytes, true); //$NON-NLS-1$  
      if (status != ISolutionRepository.FILE_ADD_SUCCESSFUL) {
        throw new RuntimeException("Unable to save to repository. Status: " + status); //$NON-NLS-1$  
      }

      // Refresh Metadata
      PentahoSystem.publish(session, MetadataPublisher.class.getName());
      */
        // Write this catalog to the default Pentaho DataSource and refresh the cache.
        // $NON-NLS-1$
        File file = new File(path + name + ".mondrian.xml");
        // Need to find a better way to get the connection name instead of using the Id.
        String catConnectStr = "Provider=mondrian;DataSource=\"" + ((SqlPhysicalModel) domain.getPhysicalModels().get(0)).getId() + // $NON-NLS-1$
        "\"";
        String catDef = // $NON-NLS-1$
        "solution:" + solutionStorage + RepositoryFile.SEPARATOR + "resources" + RepositoryFile.SEPARATOR + "metadata" + RepositoryFile.SEPARATOR + file.getName();
        addCatalog(catName, catConnectStr, catDef, session);
    } catch (Exception e) {
        getLogger().error(e);
        throw e;
    }
    return domainId;
}
Also used : GwtModelerWorkspaceHelper(org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper) LogicalModel(org.pentaho.metadata.model.LogicalModel) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException)

Example 12 with IApplicationContext

use of org.pentaho.platform.api.engine.IApplicationContext in project pentaho-platform by pentaho.

the class SolutionContextListener method contextInitialized.

public void contextInitialized(final ServletContextEvent event) {
    context = event.getServletContext();
    // $NON-NLS-1$
    String encoding = getServerParameter("encoding");
    if (encoding != null) {
        LocaleHelper.setSystemEncoding(encoding);
    }
    // $NON-NLS-1$
    String textDirection = getServerParameter("text-direction");
    if (textDirection != null) {
        LocaleHelper.setTextDirection(textDirection);
    }
    // $NON-NLS-1$
    String localeLanguage = getServerParameter("locale-language");
    // $NON-NLS-1$
    String localeCountry = getServerParameter("locale-country");
    boolean localeSet = false;
    if (!StringUtils.isEmpty(localeLanguage) && !StringUtils.isEmpty(localeCountry)) {
        Locale[] locales = Locale.getAvailableLocales();
        if (locales != null) {
            for (Locale element : locales) {
                if (element.getLanguage().equals(localeLanguage) && element.getCountry().equals(localeCountry)) {
                    LocaleHelper.setLocale(element);
                    localeSet = true;
                    break;
                }
            }
        }
    }
    if (!localeSet) {
        // do this thread in the default locale
        LocaleHelper.setLocale(Locale.getDefault());
    }
    LocaleHelper.setDefaultLocale(LocaleHelper.getLocale());
    // log everything that goes on here
    // $NON-NLS-1$
    logger.info(Messages.getInstance().getString("SolutionContextListener.INFO_INITIALIZING"));
    // $NON-NLS-1$
    logger.info(Messages.getInstance().getString("SolutionContextListener.INFO_SERVLET_CONTEXT", context));
    // $NON-NLS-1$
    SolutionContextListener.contextPath = context.getRealPath("");
    logger.info(// $NON-NLS-1$
    Messages.getInstance().getString("SolutionContextListener.INFO_CONTEXT_PATH", SolutionContextListener.contextPath));
    SolutionContextListener.solutionPath = PentahoHttpSessionHelper.getSolutionPath(context);
    if (StringUtils.isEmpty(SolutionContextListener.solutionPath)) {
        // $NON-NLS-1$
        String errorMsg = Messages.getInstance().getErrorString("SolutionContextListener.ERROR_0001_NO_ROOT_PATH");
        logger.error(errorMsg);
        /*
       * Since we couldn't find solution repository path there is no point in going forward and the user should know
       * that a major config setting was not found. So we are throwing in a RunTimeException with the requisite message.
       */
        throw new RuntimeException(errorMsg);
    }
    logger.info(Messages.getInstance().getString("SolutionContextListener.INFO_ROOT_PATH", // $NON-NLS-1$
    SolutionContextListener.solutionPath));
    // $NON-NLS-1$
    String fullyQualifiedServerUrl = getServerParameter("fully-qualified-server-url");
    if (fullyQualifiedServerUrl == null) {
        // assume this is a demo installation
        // TODO: Create a servlet that's loaded on startup to set this value
        // $NON-NLS-1$
        fullyQualifiedServerUrl = "http://localhost:8080/pentaho/";
    }
    IApplicationContext applicationContext = new WebApplicationContext(SolutionContextListener.solutionPath, fullyQualifiedServerUrl, context.getRealPath(""), // $NON-NLS-1$
    context);
    /*
     * Copy out all the Server.properties from to the application context
     */
    Properties props = new Properties();
    ISystemConfig systemConfig = PentahoSystem.get(ISystemConfig.class);
    if (systemConfig != null) {
        IConfiguration config = systemConfig.getConfiguration("server");
        if (config != null) {
            try {
                props.putAll(config.getProperties());
            } catch (IOException e) {
                logger.error("Could not find/read the server.properties file.");
            }
        }
    }
    /*
     * Copy out all the initParameter values from the servlet context and put them in the application context.
     */
    Enumeration<?> initParmNames = context.getInitParameterNames();
    String initParmName;
    while (initParmNames.hasMoreElements()) {
        initParmName = (String) initParmNames.nextElement();
        props.setProperty(initParmName, getServerParameter(initParmName, true));
    }
    ((WebApplicationContext) applicationContext).setProperties(props);
    setSystemCfgFile(context);
    setObjectFactory(context);
    serverStatusProvider.setStatus(IServerStatusProvider.ServerStatus.STARTING);
    serverStatusProvider.setStatusMessages(new String[] { "Caution, the system is initializing. Do not shut down or restart the system at this time." });
    PeriodicStatusLogger.start();
    boolean initOk = false;
    try {
        initOk = PentahoSystem.init(applicationContext);
    } finally {
        updateStatusMessages(initOk);
        PeriodicStatusLogger.stop();
    }
    this.showInitializationMessage(initOk, fullyQualifiedServerUrl);
}
Also used : Locale(java.util.Locale) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) IOException(java.io.IOException) Properties(java.util.Properties) IConfiguration(org.pentaho.platform.api.engine.IConfiguration)

Example 13 with IApplicationContext

use of org.pentaho.platform.api.engine.IApplicationContext in project pentaho-platform by pentaho.

the class DIServerConfigTest method setup.

@Before
public void setup() throws Exception {
    IApplicationContext mockAppContext = mock(IApplicationContext.class);
    when(mockAppContext.getFullyQualifiedServerURL()).thenReturn(SERVER_URL);
    PentahoSystem.setApplicationContext(mockAppContext);
    IPentahoSession pentahoSession = mock(IPentahoSession.class);
    when(pentahoSession.getName()).thenReturn(MOCK_USER);
    PentahoSessionHolder.setSession(pentahoSession);
    baseConfig = new SlaveServerConfig();
    pluginRegistry = mock(PluginRegistry.class);
    purRepositoryMeta = mock(RepositoryMeta.class);
    purRepository = mock(Repository.class);
    purMetaStore = mock(IMetaStore.class);
    when(pluginRegistry.loadClass(RepositoryPluginType.class, DIServerConfig.PUR_REPOSITORY_PLUGIN_ID, Repository.class)).thenReturn(purRepository);
    when(pluginRegistry.loadClass(RepositoryPluginType.class, DIServerConfig.PUR_REPOSITORY_PLUGIN_ID, RepositoryMeta.class)).thenReturn(purRepositoryMeta);
    when(purRepository.getMetaStore()).thenReturn(purMetaStore);
    when(purMetaStore.getName()).thenReturn("Mock MetaStore");
    logChannel = mock(LogChannel.class);
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) Repository(org.pentaho.di.repository.Repository) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) LogChannel(org.pentaho.di.core.logging.LogChannel) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) SlaveServerConfig(org.pentaho.di.www.SlaveServerConfig) IMetaStore(org.pentaho.metastore.api.IMetaStore) Before(org.junit.Before)

Example 14 with IApplicationContext

use of org.pentaho.platform.api.engine.IApplicationContext in project pentaho-platform by pentaho.

the class SolutionPropertiesFileConfigurationTest method testGetSolutionPath_fromAppContext.

@Test
public void testGetSolutionPath_fromAppContext() throws Exception {
    IApplicationContext appContext = mock(IApplicationContext.class);
    when(appContext.getSolutionPath("system")).thenReturn(f.getParent());
    PentahoSystem.setApplicationContext(appContext);
    String solutionPath = SolutionPropertiesFileConfiguration.getSolutionPath();
    assertEquals(f.getParent(), solutionPath);
}
Also used : IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) Test(org.junit.Test)

Example 15 with IApplicationContext

use of org.pentaho.platform.api.engine.IApplicationContext in project pentaho-platform by pentaho.

the class MessageFormatterTest method before.

@Before
public void before() {
    mockedRuntimeRepository = mock(IRuntimeRepository.class);
    mockedSolutionEngine = mock(ISolutionEngine.class);
    mockedPentahoSystem = new MockUp<PentahoSystem>() {

        @Mock
        public IApplicationContext getApplicationContext() {
            final String solutionPath = ".";
            final String applicationPath = "";
            return new StandaloneApplicationContext(solutionPath, applicationPath);
        }
    };
    runtimeCtx = spy(new RuntimeContext("id", mockedSolutionEngine, "solutionName", makeRuntimeData(session), session, null, "processId", urlFactory, makeParameterProviders(session), new ArrayList<String>(), null));
}
Also used : IRuntimeRepository(org.pentaho.platform.api.repository.IRuntimeRepository) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) RuntimeContext(org.pentaho.platform.engine.services.runtime.RuntimeContext) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) Mock(mockit.Mock) Before(org.junit.Before)

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