Search in sources :

Example 16 with IPentahoSession

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

the class SpringPentahoObjectReference method getObject.

@Override
@SuppressWarnings("unchecked")
public T getObject() {
    IPentahoSession sessionToUse = session != null ? session : PentahoSessionHolder.getSession();
    SpringScopeSessionHolder.SESSION.set(sessionToUse);
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        Object obj = context.getBeanFactory().getBean(name);
        SpringScopeSessionHolder.SESSION.set(null);
        if (obj instanceof IPentahoInitializer) {
            ((IPentahoInitializer) obj).init(sessionToUse);
        }
        return (T) obj;
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassLoader);
    }
}
Also used : IPentahoInitializer(org.pentaho.platform.api.engine.IPentahoInitializer) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 17 with IPentahoSession

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

the class InheritableThreadLocalPentahoSessionHolderStrategy method removeSession.

/**
 * Removes the IPentahoSession for the current thread. It is important that the framework calls this to prevent
 * session bleed- through between requests as threads are re-used by the server.
 */
public void removeSession() {
    IPentahoSession sess = perThreadSession.get();
    if (sess != null) {
        if (logger.isDebugEnabled()) {
            logger.debug(// $NON-NLS-1$
            Messages.getInstance().getString(// $NON-NLS-1$
            "PentahoSessionHolder.DEBUG_REMOVING_SESSION", Thread.currentThread().getName(), String.valueOf(Thread.currentThread().getId())));
        }
        if (logger.isTraceEnabled()) {
            StackTraceElement[] elements = Thread.currentThread().getStackTrace();
            // $NON-NLS-1$
            logger.trace(Messages.getInstance().getString("PentahoSessionHolder.DEBUG_THREAD_STACK_TRACE"));
            for (int i = 0; i < elements.length; i++) {
                logger.trace(elements[i]);
            }
        }
        // If the session is a custom/stand-alone session, we need to remove references
        // to it from other objects which may be holding on to it. We do this to prevent
        // memory leaks. In the future, this should not be necessary since objects
        // should not need to have setSesssion methods, but instead use PentahoSessionHolder.getSession()
        // 
        // Disabled as this is one of the points why the Trusted User Filter stopped working
        /*
      if ( sess instanceof StandaloneSession ) {
        if ( logger.isDebugEnabled() ) {
          logger.debug( Messages.getInstance().getString( "PentahoSessionHolder.DEBUG_DESTROY_STANDALONE_SESSION", //$NON-NLS-1$
              String.valueOf( sess.getId() ), sess.getName(), String.valueOf( Thread.currentThread().getId() ) ) );
        }
        ( (StandaloneSession) sess ).destroy();
      }
      */
        perThreadSession.remove();
    }
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 18 with IPentahoSession

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

the class SessionCachingMetadataDomainRepository method getDomainIds.

@Override
public Set<String> getDomainIds() {
    final IPentahoSession session = PentahoSessionHolder.getSession();
    final String domainKey = generateDomainIdCacheKeyForSession(session);
    Set<String> domainIds;
    if (domainIdsCacheEnabled) {
        domainIds = (Set<String>) cacheManager.getFromRegionCache(CACHE_REGION, domainKey);
        if (domainIds != null) {
            boolean dirtyCache = false;
            for (String domain : domainIds) {
                if (delegate instanceof IAclAwarePentahoMetadataDomainRepositoryImporter && !((IAclAwarePentahoMetadataDomainRepositoryImporter) delegate).hasAccessFor(domain)) {
                    domainIds.remove(domain);
                    removeDomainFromIDCache(domain);
                    dirtyCache = true;
                }
            }
            if (dirtyCache) {
                cacheManager.putInRegionCache(CACHE_REGION, domainKey, new HashSet<String>(domainIds));
            }
            // We've previously cached domainIds available for this session
            return domainIds;
        }
    } else {
        delegate.reloadDomains();
    }
    // Domains are accessible by anyone. What they contain may be different so rely on the lookup to be
    // session-specific.
    domainIds = delegate.getDomainIds();
    if (domainIdsCacheEnabled) {
        cacheManager.putInRegionCache(CACHE_REGION, domainKey, new HashSet<String>(domainIds));
    }
    return domainIds;
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 19 with IPentahoSession

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

the class DefaultPluginManager method reload.

@Override
public final boolean reload() {
    IPentahoSession session = PentahoSessionHolder.getSession();
    boolean anyErrors = false;
    IPluginProvider pluginProvider = PentahoSystem.get(IPluginProvider.class, "IPluginProvider", session);
    List<IPlatformPlugin> providedPlugins = null;
    try {
        synchronized (registeredPlugins) {
            this.unloadPlugins();
        }
        // the plugin may fail to load during getPlugins without an exception thrown if the provider
        // is capable of discovering the plugin fine but there are structural problems with the plugin
        // itself. In this case a warning should be logged by the provider, but, again, no exception
        // is expected.
        providedPlugins = pluginProvider.getPlugins(session);
    } catch (PlatformPluginRegistrationException e1) {
        String msg = // $NON-NLS-1$
        Messages.getInstance().getErrorString("PluginManager.ERROR_0012_PLUGIN_DISCOVERY_FAILED");
        Logger.error(getClass().toString(), msg, e1);
        PluginMessageLogger.add(msg);
        anyErrors = true;
    }
    synchronized (providedPlugins) {
        for (IPlatformPlugin plugin : providedPlugins) {
            try {
                registeredPlugins.put(plugin.getId(), plugin);
                ClassLoader loader = setPluginClassLoader(plugin);
                initializeBeanFactory(plugin, loader);
            } catch (Throwable t) {
                // this has been logged already
                anyErrors = true;
                String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0011_FAILED_TO_REGISTER_PLUGIN", // $NON-NLS-1$
                plugin.getId());
                Logger.error(getClass().toString(), msg, t);
                PluginMessageLogger.add(msg);
            }
        }
        registeredPlugins.clear();
        for (IPlatformPlugin plugin : providedPlugins) {
            try {
                GenericApplicationContext beanFactory = beanFactoryMap.get(plugin.getId());
                if (beanFactory != null) {
                    beanFactory.refresh();
                }
                registerPlugin(plugin);
                registeredPlugins.put(plugin.getId(), plugin);
            } catch (Throwable t) {
                // this has been logged already
                anyErrors = true;
                String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0011_FAILED_TO_REGISTER_PLUGIN", // $NON-NLS-1$
                plugin.getId());
                Logger.error(getClass().toString(), msg, t);
                PluginMessageLogger.add(msg);
            }
        }
    }
    IServiceManager svcManager = PentahoSystem.get(IServiceManager.class, null);
    if (svcManager != null) {
        try {
            svcManager.initServices();
        } catch (ServiceInitializationException e) {
            String msg = Messages.getInstance().getErrorString(// $NON-NLS-1$
            "PluginManager.ERROR_0022_SERVICE_INITIALIZATION_FAILED");
            Logger.error(getClass().toString(), msg, e);
            PluginMessageLogger.add(msg);
        }
    }
    return !anyErrors;
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IPluginProvider(org.pentaho.platform.api.engine.IPluginProvider) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) IServiceManager(org.pentaho.platform.api.engine.IServiceManager) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) ServiceInitializationException(org.pentaho.platform.api.engine.ServiceInitializationException)

Example 20 with IPentahoSession

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

the class PentahoSystemPluginManager method registerContentGenerators.

private void registerContentGenerators(IPlatformPlugin plugin, ClassLoader loader, final GenericApplicationContext beanFactory) throws PlatformPluginRegistrationException {
    // register the content generators
    for (final IContentGeneratorInfo cgInfo : plugin.getContentGenerators()) {
        // define the bean in the factory
        BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(cgInfo.getClassname()).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
        // register bean with alias of content generator id (old way)
        beanFactory.registerBeanDefinition(cgInfo.getId(), beanDef);
        // register bean with alias of type (with default perspective) as well (new way)
        beanFactory.registerAlias(cgInfo.getId(), cgInfo.getType());
        PluginMessageLogger.add(Messages.getInstance().getString("PluginManager.USER_CONTENT_GENERATOR_REGISTERED", cgInfo.getId(), plugin.getId()));
        final HashMap<String, Object> attributes = new HashMap<String, Object>();
        attributes.put(PLUGIN_ID, plugin.getId());
        attributes.put(CONTENT_TYPE, cgInfo.getType());
        final IPentahoObjectRegistration referenceHandle = PentahoSystem.registerReference(new PrototypePentahoObjectReference.Builder<IContentGenerator>(IContentGenerator.class).creator(new IObjectCreator<IContentGenerator>() {

            @Override
            public IContentGenerator create(IPentahoSession session) {
                return (IContentGenerator) beanFactory.getBean(cgInfo.getId());
            }
        }).attributes(attributes).build(), IContentGenerator.class);
        registerReference(plugin.getId(), referenceHandle);
    }
    // The remaining operations require a beanFactory
    if (beanFactory == null) {
        return;
    }
    String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory.getBeanFactory(), IContentGenerator.class);
    ArrayList<String> ids = new ArrayList<String>();
    for (String beanName : names) {
        ids.add(beanName);
        Collections.addAll(ids, beanFactory.getAliases(beanName));
    }
    for (final String beanName : ids) {
        final HashMap<String, Object> attributes = new HashMap<String, Object>();
        attributes.put(PLUGIN_ID, plugin.getId());
        attributes.put(CONTENT_TYPE, beanName);
        final IPentahoObjectRegistration referenceHandle = PentahoSystem.registerReference(new PrototypePentahoObjectReference.Builder<IContentGenerator>(IContentGenerator.class).creator(new IObjectCreator<IContentGenerator>() {

            @Override
            public IContentGenerator create(IPentahoSession session) {
                return (IContentGenerator) beanFactory.getBean(beanName);
            }
        }).attributes(attributes).build(), IContentGenerator.class);
        registerReference(plugin.getId(), referenceHandle);
    }
}
Also used : IContentGeneratorInfo(org.pentaho.platform.api.engine.IContentGeneratorInfo) IObjectCreator(org.pentaho.platform.api.engine.IObjectCreator) HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) ArrayList(java.util.ArrayList) PluginBeanDefinition(org.pentaho.platform.api.engine.PluginBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) IContentGenerator(org.pentaho.platform.api.engine.IContentGenerator) IPentahoObjectRegistration(org.pentaho.platform.api.engine.IPentahoObjectRegistration)

Aggregations

IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)231 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)76 Test (org.junit.Test)70 Matchers.anyString (org.mockito.Matchers.anyString)40 ArrayList (java.util.ArrayList)32 ITenant (org.pentaho.platform.api.mt.ITenant)22 IOException (java.io.IOException)20 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)18 File (java.io.File)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)16 Before (org.junit.Before)14 OutputStream (java.io.OutputStream)13 HashMap (java.util.HashMap)13 InputStream (java.io.InputStream)12 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)12 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)12 Domain (org.pentaho.metadata.model.Domain)11 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)11 List (java.util.List)10 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)10