Search in sources :

Example 6 with ISystemConfig

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

the class StandaloneSpringPentahoObjectFactoryTest method testFallbackPenBean.

/**
 * Test <pen:bean> fallback behavior when no object is published matching the request. It should fall-back to
 * PentahoSystem.get() behavior where beans matching the simple-name of the queried class are returned.
 *
 * @throws Exception
 */
public void testFallbackPenBean() throws Exception {
    PentahoSystem.shutdown();
    ISystemConfig config = mock(ISystemConfig.class);
    when(config.getProperty("system.dampening-timeout")).thenReturn("3000");
    PentahoSystem.registerObject(config);
    StandaloneSession session = new StandaloneSession();
    PentahoSessionHolder.setSession(session);
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
    PentahoSystem.registerObjectFactory(factory);
    // fallback
    SimpleObjectHolder integerHolder = PentahoSystem.get(SimpleObjectHolder.class, "SimpleIntegerHolder", session);
    // to
    // simpleName
    assertNotNull(integerHolder);
    assertEquals(123, (int) integerHolder.getVal());
    // fallback
    SimpleObjectHolder stringHolder = PentahoSystem.get(SimpleObjectHolder.class, "SimpleStringHolder", session);
    // to
    // simpleName
    assertNotNull(stringHolder);
    assertEquals("testing_fallback_by_interface", stringHolder.getVal().toString());
    // checks
    SimpleObjectHolder integerHolder2 = PentahoSystem.get(SimpleObjectHolder.class, "SimpleIntegerHolder2", session);
    // ID
    assertNotNull(integerHolder2);
    assertEquals(456, (int) integerHolder2.getVal());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 7 with ISystemConfig

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

the class SolutionContextListener method getServerParameter.

private String getServerParameter(String paramName, boolean suppressWarning) {
    String result = context.getInitParameter(paramName);
    if (result == null) {
        ISystemConfig config = PentahoSystem.get(ISystemConfig.class);
        result = config.getProperty("server." + paramName);
    } else {
        if (!suppressWarning) {
            logger.warn(Messages.getInstance().getString("SolutionContextListener.WARN_WEB_XML_PARAM_DEPRECATED", paramName, // $NON-NLS-1$
            result));
        }
    }
    return result;
}
Also used : ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig)

Example 8 with ISystemConfig

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

the class RequestParameterAuthenticationFilterTest method beforeTest.

@Before
public void beforeTest() throws KettleException, IOException {
    KettleClientEnvironment.init();
    filter = new RequestParameterAuthenticationFilter();
    authManagerMock = mock(AuthenticationManager.class);
    filter.setAuthenticationManager(authManagerMock);
    final Properties properties = new Properties();
    properties.setProperty("requestParameterAuthenticationEnabled", "true");
    IConfiguration config = mock(IConfiguration.class);
    ISystemConfig mockISystemConfig = mock(ISystemConfig.class);
    mockISystemConfig.registerConfiguration(config);
    filter.setSystemConfig(mockISystemConfig);
    doReturn(config).when(mockISystemConfig).getConfiguration("security");
    doReturn(properties).when(config).getProperties();
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) Properties(java.util.Properties) IConfiguration(org.pentaho.platform.api.engine.IConfiguration) RequestParameterAuthenticationFilter(org.pentaho.platform.web.http.security.RequestParameterAuthenticationFilter) Before(org.junit.Before)

Example 9 with ISystemConfig

use of org.pentaho.platform.api.engine.ISystemConfig 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 10 with ISystemConfig

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

the class SqlMetadataQueryExecTest method testDriverClassesToForceMetaIOE.

@Test
public void testDriverClassesToForceMetaIOE() throws IOException {
    ISystemConfig sysConfig = mock(ISystemConfig.class);
    IConfiguration config = mock(IConfiguration.class);
    when(sysConfig.getConfiguration(SqlMetadataQueryExec.CONFIG_ID)).thenReturn(config);
    when(config.getProperties()).thenThrow(new IOException());
    SqlMetadataQueryExec sqlMetadataQueryExec = new SqlMetadataQueryExec(sysConfig);
    assertEquals(0, sqlMetadataQueryExec.driverClassesToForceMeta.size());
}
Also used : ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) IOException(java.io.IOException) IConfiguration(org.pentaho.platform.api.engine.IConfiguration) Test(org.junit.Test)

Aggregations

ISystemConfig (org.pentaho.platform.api.engine.ISystemConfig)17 IConfiguration (org.pentaho.platform.api.engine.IConfiguration)10 Properties (java.util.Properties)8 Test (org.junit.Test)7 IOException (java.io.IOException)3 Matchers.anyString (org.mockito.Matchers.anyString)3 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)3 Map (java.util.Map)2 Before (org.junit.Before)2 IPentahoObjectReference (org.pentaho.platform.api.engine.IPentahoObjectReference)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)2 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Locale (java.util.Locale)1 Node (org.dom4j.Node)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 IApplicationContext (org.pentaho.platform.api.engine.IApplicationContext)1 ISystemSettings (org.pentaho.platform.api.engine.ISystemSettings)1