Package de.innovationgate.wgpublisher.plugins

Examples of de.innovationgate.wgpublisher.plugins.InvalidPluginException


                        removeContentDB(dbKey);
                        db = null;
                    }
                }           
                catch (Exception e) {
                    throw new InvalidPluginException(plugin, "Error checking existent plugin database " + dbKey, e);
                }
            }

            if (!plugin.isActive()) {
                throw new InvalidPluginException(plugin, "Plugin is deactivated");
            }
            if (!plugin.isValid()) {
                throw new InvalidPluginException(plugin, "Plugin is invalid");
            }

           
            // First connect all mandatory plugins
            try {

                Iterator mandatoryPlugins = plugin.getMandatoryPlugins().values().iterator();
                while (mandatoryPlugins.hasNext()) {
                    WGAPlugin mandatoryPlugin  = (WGAPlugin) mandatoryPlugins.next();
                    connectPlugin(mandatoryPlugin, domainConfigs);
                }
            }
            // A mandatory plugin is invalid. Cancel connect.
            catch (InvalidPluginException e) {
                throw e;
            }
  
            logCategoryInfo("Plugin " + plugin.getInstallationKey(), 2);
           
            // Mandatory db options (for plugins)
            Map<String, String> dbOptions = new HashMap<String, String>();
            dbOptions.put(WGDatabase.COPTION_DBREFERENCE, dbKey.toLowerCase());
            dbOptions.put(WGDatabase.COPTION_READERPROFILECREATION, "true");
            dbOptions.put(WGDatabase.COPTION_USERCACHELATENCY, String.valueOf(_wgaConfiguration.getUserCacheLatencyMinutes()));
           
            // We try to automatically migrate plugin content stores to CS5 format
            dbOptions.put(WGDatabase.COPTION_CONTENT_STORE_VERSION, String.valueOf(WGDatabase.CSVERSION_WGA5));
           
            // Clear the plugin database before connecting if the plugin is updated and should clear the db on update
            if (plugin.getRuntimeContext().isUpdated()) {
                if (plugin.getCsConfig().getPluginConfig() instanceof de.innovationgate.wga.common.beans.csconfig.v3.PluginConfig) {
                    de.innovationgate.wga.common.beans.csconfig.v3.PluginConfig v3Config = (de.innovationgate.wga.common.beans.csconfig.v3.PluginConfig) plugin.getCsConfig().getPluginConfig();
                    if (v3Config.isClearDatabaseOnUpdate()) {
                        getLog().info("Clearing plugin database for installation key " + plugin.getInstallationKey());
                        plugin.getParent().deletePluginDatabase(plugin);
                    }
                }
                plugin.getRuntimeContext().setUpdated(false);
            }
           
            // Connect
            getLog().info("Connecting plugin " + plugin.getPluginID().getUniqueName() + " Version " + plugin.getPluginID().getVersion().toString());
              
            try {
                db = WGFactory.getInstance().openDatabase(null, de.innovationgate.webgate.api.hsql.WGDatabaseImpl.class.getName(), plugin.buildDatabasePath(), null, null, dbOptions);
            }
            catch (Throwable e1) {
                throw new InvalidPluginException(plugin, "Could not connect plugin \"" + plugin.getPluginID().getUniqueName() + "\"", e1);
            }

            if (db == null || !db.isSessionOpen()) {
                throw new InvalidPluginException(plugin, "Could not connect plugin \"" + plugin.getPluginID().getUniqueName() + "\" - Check logged messages above for error details");
            }

            try {
                db.getSessionContext().setTask("Initializing database in WGA");
               
                // Plugin dbs are always CS5 since they are automatically migrated
                //getLog().info("Database of plugin " + plugin.getPluginID().getUniqueName() + " is content store version " + db.getContentStoreVersion());
               
                PluginConfig pc = plugin.getCsConfig().getPluginConfig();
                String auth = pc.getAuthentication();
                db.setTitle(pc.getTitle());
               
               
                // Set mandatory database attributes
                initializeDBAttributes(db, dbKey, dbKey, new HashSet());
               
                // Create authentication
                if (auth != null) {
                    String authImplClass = null;
                    Map<String,String> authOptions = new HashMap<String, String>();
                   
                    // Delegate authentication to the default domain
                    if (auth.equals(PluginConfig.AUTHSOURCE_DEFAULT_DOMAIN)) {
                        authImplClass = WGAAuthModuleFactory.AUTHMODULE_DELEGATE;
                        authOptions.put(DelegatingAuthModule.COPTION_DOMAIN, "default");
                    }
                    // Use some plugin for authentication
                    else {
                        WGAPlugin authPlugin = plugin.getParent().getPluginByUniqueName(auth);
                    if (authPlugin != null) {
                        authImplClass = CSAuthModule.class.getName();
                        authOptions.put(CSAuthModule.COPTION_DBKEY, authPlugin.buildDatabaseKey());
                    }
                    else {
                            getLog().error("Unable to find authentication plugin " + auth);
                        }
                    }
                   
                    if (authImplClass != null) {
                        AuthenticationModule authModule = WGFactory.getAuthModuleFactory().getAuthModule(authImplClass, authOptions, db);
                        db.setAuthenticationModule(authModule);
                    }
                   
                }
               
                // Enforce some plugin settings via db attributes
                db.setAttribute(DBATTRIB_PERSMODE, String.valueOf(pc.getPersonalisationMode()));
                db.setAttribute(DBATTRIB_PERSSTATMODE, String.valueOf(Constants.PERSSTATMODE_SESSION));
                db.setAttribute(DBATTRIB_PLUGIN_FILETIME, new Long(plugin.getFileLastModified()));
                db.setAttribute(DBATTRIB_PLUGIN_ID, plugin.getPluginID());
                db.setAttribute(DBATTRIB_PLUGIN_VERSION, plugin.getPluginID().getVersion());
               
                if (!pc.isUsageAsContentStore()) {
                    db.setAttribute(DBATTRIB_ALLOW_PUBLISHING, "false");
                }
               
                if (!pc.isShowOnStartPage()) {
                    db.setAttribute(DBATTRIB_STARTPAGE, "false");
                }
   
                // Configure design provider
                DesignReference ref = new DesignReference(Constants.DESIGNCOL_PLUGIN, plugin.getInstallationKey(), null);
                db.setDesignProvider(new FileSystemDesignProvider(ref, this, db, plugin.getDesignURL().toString(), Collections.EMPTY_MAP));
                db.setAllowDesignModification(false);
              
                // Determine if ACL is empty
                boolean aclEmpty = false;
                try {
                    if (db.isConnected() && db.hasFeature(WGDatabase.FEATURE_ACL_MANAGEABLE) && db.getACL().getAllEntries().size() == 0) {
                        aclEmpty = true;
                    }
                }
                catch (WGBackendException e1) {
                    getLog().error("Error retrieving ACL state of db '" + db.getDbReference() + "'", e1);
                }
               
                // Process system container
                SystemContainerManager.SystemContainerContext scContext = null;
                try {
                    scContext = _systemContainerManager.addDatabase(db, plugin, aclEmpty);
                }
                catch (Exception e) {
                    this.log.error("Exception processing system file container for plugin '" + plugin.getPluginID().getUniqueName() + "'", e);
                }
                       
                // Build map of publisher options from wga.xml. We only use gobal options here since plugins have no own options in wga.xml
                // and csconfig.xml options are processed via system container
                Map<String, String> publisherOptions = new HashMap<String, String>();
                // publisherOptions.putAll(_globalPublisherOptions); Plugins should not be influenced by global options of the current configuration
                if (scContext != null) {
                    scContext.putPublisherOptions(publisherOptions);
                }
   
                // Publisher options initialisation which is equal for content dbs and plugins
                processPublisherOptions(db, publisherOptions);
               
                // Set plugin homepage. The method chooses either the plugin-specific homepage or the publisher option
                // Must be after publisher option initialisation to be able to react on them
                db.setAttribute(DBATTRIB_HOME_PAGE, plugin.getPluginHomepage());
               
                // check if db is empty before hdb script runs
                boolean isEmptyDB = db.isContentEmpty();
                               
                // Validate default language definition
                if (!isEmptyDB) {
                    db.determineDefaultLanguage();
                }
                                                               
                // System container initialisations
                if (scContext != null) {
                    scContext.performInitialisation(new Boolean(isEmptyDB));
                    if (isEmptyDB) {
                        db.onConnect(new ValidateDefaultLanguageAction());
                    }
                }
               
                // Registering connection
                this.contentdbs.put(db.getDbReference(), db);
                performNewDBOperations(db);
               
                // Mark this database as fully connected
                db.setAttribute(DBATTRIB_FULLY_CONNECTED, "true");
               
                // Initially create field mappings. These can only come from csconfig.xml for plugins
                updateFieldMappings(db, null);
               
                return db;
            }
            catch (Throwable e) {
                try {
                    db.close();
                }
                catch (WGAPIException e2) {
                    // Silent failure of closing an uninitialized plugin bc. the connection failure is more important
                }
                plugin.setValid(false);
                throw new InvalidPluginException(plugin, "Error connecting plugin" ,e);
            }
           
           
           
           
View Full Code Here

TOP

Related Classes of de.innovationgate.wgpublisher.plugins.InvalidPluginException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.