Search in sources :

Example 1 with MultiTenantCallback

use of com.qcadoo.tenant.api.MultiTenantCallback in project qcadoo by qcadoo.

the class DefaultModuleFactoryAccessor method multiTenantDisable.

@Override
public void multiTenantDisable(final int tenantId, final Plugin plugin) {
    List<ModuleFactory<?>> factories = new ArrayList<ModuleFactory<?>>(moduleFactoryRegistry.values());
    Collections.reverse(factories);
    for (ModuleFactory<?> moduleFactory : factories) {
        List<Module> modules = ((InternalPlugin) plugin).getModules(moduleFactory);
        Collections.reverse(modules);
        for (final Module module : modules) {
            MultiTenantUtil.doInMultiTenantContext(tenantId, new MultiTenantCallback() {

                @Override
                public void invoke() {
                    module.multiTenantDisable();
                }
            });
        }
    }
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) MultiTenantCallback(com.qcadoo.tenant.api.MultiTenantCallback) ModuleFactory(com.qcadoo.plugin.api.ModuleFactory) ArrayList(java.util.ArrayList) Module(com.qcadoo.plugin.api.Module)

Example 2 with MultiTenantCallback

use of com.qcadoo.tenant.api.MultiTenantCallback in project qcadoo by qcadoo.

the class DefaultModuleFactoryAccessor method init.

@Override
public void init(final List<Plugin> pluginsToInitialize) {
    for (ModuleFactory<?> moduleFactory : moduleFactoryRegistry.values()) {
        moduleFactory.preInit();
        for (Plugin plugin : pluginsToInitialize) {
            for (Module module : ((InternalPlugin) plugin).getModules(moduleFactory)) {
                module.init();
            }
        }
        moduleFactory.postInit();
    }
    List<ModuleFactory<?>> factories = new ArrayList<ModuleFactory<?>>(moduleFactoryRegistry.values());
    List<Plugin> plugins = new ArrayList<Plugin>(pluginsToInitialize);
    for (ModuleFactory<?> moduleFactory : factories) {
        for (final Plugin plugin : plugins) {
            List<Module> modules = ((InternalPlugin) plugin).getModules(moduleFactory);
            for (final Module module : modules) {
                if (plugin.hasState(PluginState.ENABLED)) {
                    module.enableOnStartup();
                    MultiTenantUtil.doInMultiTenantContext(new MultiTenantCallback() {

                        @Override
                        public void invoke() {
                            module.multiTenantEnableOnStartup();
                        }
                    });
                }
            }
        }
    }
    Collections.reverse(factories);
    Collections.reverse(plugins);
    for (ModuleFactory<?> moduleFactory : factories) {
        for (final Plugin plugin : plugins) {
            List<Module> modules = ((InternalPlugin) plugin).getModules(moduleFactory);
            Collections.reverse(modules);
            for (final Module module : modules) {
                if (!plugin.hasState(PluginState.ENABLED) && !plugin.hasState(PluginState.ENABLING)) {
                    module.disableOnStartup();
                    MultiTenantUtil.doInMultiTenantContext(new MultiTenantCallback() {

                        @Override
                        public void invoke() {
                            module.multiTenantDisableOnStartup();
                        }
                    });
                }
            }
        }
    }
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) MultiTenantCallback(com.qcadoo.tenant.api.MultiTenantCallback) ModuleFactory(com.qcadoo.plugin.api.ModuleFactory) ArrayList(java.util.ArrayList) Module(com.qcadoo.plugin.api.Module) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin)

Aggregations

Module (com.qcadoo.plugin.api.Module)2 ModuleFactory (com.qcadoo.plugin.api.ModuleFactory)2 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)2 MultiTenantCallback (com.qcadoo.tenant.api.MultiTenantCallback)2 ArrayList (java.util.ArrayList)2 Plugin (com.qcadoo.plugin.api.Plugin)1