Package de.innovationgate.webgate.api

Examples of de.innovationgate.webgate.api.WGDatabase


        return newList;
    }

    public WGDocumentCore getDesignObject(int type, String name, String mediaKey) {
        try {
            WGDatabase db = getDesignDB();
           
            if (_lookupVariants) {
                WGDocumentCore core = fetchDesignObject(db, type, name + "." + _slaveDB.getDbReference(), mediaKey);
                if (core != null) {
                    return wrapVariantCore(core);
View Full Code Here


     */
    public List<WGDatabase> getDatabasesForDomain(String domain) {
        Iterator<WGDatabase> dbs = this.contentdbs.values().iterator();
        ArrayList<WGDatabase> domDbs = new ArrayList<WGDatabase>();
        while (dbs.hasNext()) {
            WGDatabase db = dbs.next();
            if (domain.equals(db.getAttribute(WGACore.DBATTRIB_DOMAIN))) {
                domDbs.add(db);
            }
        }
        return domDbs;
    }
View Full Code Here

        throw new WGCreationException("This database uses the design of database '" + _designDBKey + "'");
    }
   
    private boolean registerDesignDB() throws WGUnavailableException, WGAuthorisationException, WGInvalidDatabaseException {
       
           WGDatabase currentDesignDB = (WGDatabase) _core.getContentdbs().get(_designDBKey);
           if (currentDesignDB != null && currentDesignDB != _designDB) {
               _designDB = currentDesignDB;
              
               // Since lazy connections on a design provider DB won't work well, we issue a warning here
               // We also open a session to connect the database and init its potential design provider
View Full Code Here

     */
    public synchronized void databaseUpdate(WGDatabaseEvent event) {
       
        try {
      _failedLookups.clear();
          WGDatabase db = event.getDatabase();
          Comparable currentLastChanged = db.getRevision();
          if (currentLastChanged.compareTo(_designDBLastChanged) > 0) {
              List updateLogs = db.getUpdatedDocumentsSince(_designDBLastChanged);
              updateLogs = filterLogs(updateLogs);
              if (updateLogs.size() == 0) {
                  return;
              }
              WGDesignChangeEvent designEvent = new WGDesignChangeEvent(this, _slaveDB, updateLogs);
View Full Code Here

    public List<WGDatabase> openContentDBs(javax.servlet.http.HttpServletRequest request) {
        ArrayList<WGDatabase> dbs = new ArrayList<WGDatabase>();
        Iterator<String> dbKeys = contentdbs.keySet().iterator();
        while (dbKeys.hasNext()) {
            String dbKey = dbKeys.next();
            WGDatabase db;
            try {
                db = openContentDB(dbKey, request);
                if (db.isSessionOpen()) {
                    dbs.add(db);
                }
            }
            catch (WGException e) {
                // ignore db
View Full Code Here

        ArrayList<WGDatabase> dbs = new ArrayList<WGDatabase>();
        Iterator<String> dbKeys = contentdbs.keySet().iterator();
        while (dbKeys.hasNext()) {
            String dbKey = dbKeys.next();
            try {
                WGDatabase db = openContentDB(dbKey, request);
                if (db.isSessionOpen()) {
                    String dbDomain = (String) db.getAttribute(WGACore.DBATTRIB_DOMAIN);
                    if (dbDomain.equals(domain)) {
                        dbs.add(db);
                    }
                }
            }
View Full Code Here

        if (domainCfg == null) {
            return null;
        }
       
       
        WGDatabase db = this.personalisationdbs.get(domainCfg.getUID());
        if (db == null) {
            return null;
        }

       
        if (!db.isSessionOpen()) {
            db.openSession();
        }

        return db;

    }
View Full Code Here

    // private String DBATTRIB_LOGGER = ATTRIB_BASE + "Logger";

    public void removePersonalisationDB(String domain) {
       
        WGDatabase db = this.personalisationdbs.remove(domain);
        if (db == null) {
            return;
        }
       
        // Notify all managed DB attributes
        Iterator attNames = db.getAttributeNames().iterator();
        while (attNames.hasNext()) {
            Object att = db.getAttribute((String) attNames.next());
            if (att instanceof ManagedDBAttribute) {
                ((ManagedDBAttribute) att).close();
            }

        }
       
        // Close the database
        try {
            db.close();
            this.log.info("Removed personalisation database for domain \"" + domain + "\"");
        }
        catch (WGAPIException e) {
            this.log.error("Unable to remove personalisation database for domain \"" + domain + "\"", e);
        }
View Full Code Here

        return _externalFileServingConfig;
    }

    public synchronized void removeContentDB(String key) {

        WGDatabase db = this.contentdbs.remove(key);
        if (db != null) {

            /*
             * if (db.isSessionOpen()) { db.closeSession(); }
             */

            // Deregister from wgacore objects
            this._systemContainerManager.removeDatabase(db);
            this.deployer.removeLayouts(db);
            this.eventManager.removeDatabaseEvents(key);

            db.removeDatabaseEventListener(eventManager);
            db.removeContentEventListener(eventManager);
            db.removeWorkflowEventListener(eventManager);

            // Notify all managed DB attributes
            Iterator attNames = db.getAttributeNames().iterator();
            while (attNames.hasNext()) {
                Object att = db.getAttribute((String) attNames.next());
                if (att instanceof ManagedDBAttribute) {
                    ((ManagedDBAttribute) att).close();
                }

            }

            // Clear WebTML cache
            try {
                getWebTMLCache().clearForDatabase(key);
            }
            catch (CacheException e1) {
                log.error("Exception clearing WebTML cache for closing db '" + key + "'", e1);
            }

            // Call event
            fireCoreEvent(new WGACoreEvent(WGACoreEvent.TYPE_CS_DISCONNECTED, db, this));
           
            // we might have to remove hdb instance
            WGHierarchicalDatabase.removeInstance(db.getDbReference());
           
            // Close an external personalisation db if there is one
            if (db.hasAttribute(DBATTRIB_EXTERNAL_SELF_PERSONALISATION_DB)) {
                try {
                    WGDatabase persdb = (WGDatabase) db.getAttribute(DBATTRIB_EXTERNAL_SELF_PERSONALISATION_DB);
                    persdb.close();
                }
                catch (WGAPIException e) {
                    log.error("Exception closing external personalisation database for db '" + key + "'", e);
                }
            }
View Full Code Here

        // Mandatory db options
        dbOptions.put(WGDatabase.COPTION_DBREFERENCE, strKey.toLowerCase());
       
        // get the database object
        WGDatabase db = null;
        try {
            if (config.isLazyConnecting()) {
                db = server.prepareDatabase(typeClass, dbOptions);
            }
            else {
                db = server.openDatabase(typeClass, dbOptions);
            }
        }
        catch (Throwable e1) {
          String message = "Could not open database for key " + strKey.toLowerCase();
            log.error(message, e1);
            dbConnectionFailures.put(strKey, e1);
            return null;
        }

        if (db == null || (!config.isLazyConnecting() && !db.isSessionOpen())) {         
            log.error("Could not open database for key " + strKey.toLowerCase() + " - Check logged messages above for error details");
            dbConnectionFailures.put(strKey, "Could not open database for key " + strKey.toLowerCase() + " - Check wga log for details");
            return null;
        }

        if (!config.isLazyConnecting()) {
            db.getSessionContext().setTask("Initializing database in WGA");
            log.info("Mapping " + dbType + " on path \"" + db.getPath() + "\" (" + db.getTypeName() + ") to database key \"" + strKey.toLowerCase() + "\"");
            try {
                if (db.getContentStoreVersion() != WGDatabase.CSVERSION_NO_CONTENTSTORE) {
                    log.info("Database for " + strKey.toLowerCase() + " is a WGA Content Store of version " + db.getContentStoreVersion());
                }
            }
            catch (WGAPIException e) {
                log.error("Exception determining content store version of database " + strKey.toLowerCase(), e);
            }
        }
        else {
            log.info("Preparing " + dbType + " on path \"" + db.getPath() + "\" (" + db.getTypeName() + ") as database for key \"" + strKey.toLowerCase() + "\"");
        }

        if (title != null) {
            db.setTitle(title);
        }

        // Inject the default language if configured, else trigger determination
        if (config instanceof ContentStore) {
            ContentStore csConfig = (ContentStore) config;
            if (!WGUtils.isEmpty(csConfig.getDefaultLanguage())) {
                db.setDefaultLanguage(csConfig.getDefaultLanguage());
            }
            else {
                try {
                    db.determineDefaultLanguage();
                }
                catch (WGAPIException e) {
                    getLog().error("Exception determining default language for " + dbType + " " + db.getDbReference(), e);
                }
            }
        }
       
        // Set mandatory database attributes
        initializeDBAttributes(db, strKey, domainConfig.getName(), firstLevelDBOptions);
       
        // Inject domain authentication module
        if (domainConfig.getAuthModule() != null) {
            try {
                db.setAuthenticationModule(new DomainRedirectionAuthModule(this, domainConfig.getName()));
            }
            catch (WGIllegalArgumentException e) {
                String message = "Exception setting authentication module of " + dbType + " '" + strKey + "'";
                getLog().error(message, e);
                getLog().error("Cancelling connection of " + dbType + " '" + strKey + "' because the configured authentication could not be set");
                dbConnectionFailures.put(strKey, message);
                try {
                    db.close();
                }
                catch (Exception e2) {
                }
                return null;
            }
        }

        // Configure design provider, if neccessary
        if (config instanceof ContentStore) {
          ContentStore csConfig = (ContentStore) config;
          if (csConfig.getDesign() != null) {
            getDesignManager().applyDesign(db, csConfig)
          }
        }
       
        // Determine if ACL is empty
        // If so, eventually add domain default manager
        boolean aclEmpty = false;
        try {
            if (db.isConnected() && db.isSessionOpen() && db.hasFeature(WGDatabase.FEATURE_ACL_MANAGEABLE) && db.getACL().getAllEntries().size() == 0) {
                aclEmpty = true;
            }
        }
        catch (WGBackendException e1) {
            getLog().error("Error retrieving ACL state of " + dbType + " '" + db.getDbReference() + "'", e1);
        }
       
        if (aclEmpty && domainConfig.getDefaultManager() != null) {
            try {
                getLog().info("Adding default manager '" + domainConfig.getDefaultManager() + "' to ACL of '" + strKey + "'");
                db.getACL().createUserEntry(domainConfig.getDefaultManager(), WGDatabase.ACCESSLEVEL_MANAGER);
            }
            catch (WGAPIException e) {
                getLog().error("Exception on adding default manager to ACL of '" + strKey + "'", e);
            }
        }
       
        // Process system container
        SystemContainerManager.SystemContainerContext scContext = null;
        try {
            scContext = _systemContainerManager.addDatabase(db, aclEmpty);
        }
        catch (InvalidCSConfigVersionException e) {
            this.log.error("Unable to process system file container. The design of " + dbType + " '" + db.getDbReference() + "' was developed for a higher WGA version: " + e.getTargetVersion());
        }
        catch (Exception e) {
            this.log.error("Exception processing system file container for " + dbType + " '" + strKey.toLowerCase() + "'", e);
        }
               
        // Merge publisher options from global, server, design, database
        Map<String, String> publisherOptions = new HashMap<String, String>();
        publisherOptions.putAll(_globalPublisherOptions);
        if (scContext != null) {
            scContext.putPublisherOptions(publisherOptions);
        }
        publisherOptions.putAll(config.getPublisherOptions());
       
        // We collect those options that were added on database level in here
        // and add this set as database attribute
        // so we can tell them later from lower priority options
        Set<String> firstLevelPublisherOptions = new HashSet<String>();
        firstLevelPublisherOptions.addAll(config.getPublisherOptions().keySet());
        db.setAttribute(DBATTRIB_FIRSTLEVELPUBLISHEROPTIONS, firstLevelPublisherOptions);

        // Publisher options initialisation, which is equal for content dbs and plugins
        processPublisherOptions(db, publisherOptions);
       
        // check if db is empty before hdb script runs
        boolean isEmptyDB = false;
    try {
      isEmptyDB = (db.isConnected() && db.hasFeature(WGDatabase.FEATURE_FULLCONTENTFEATURES) && db.isContentEmpty());
    } catch (WGAPIException e) {
      this.log.error("Unable to check if database '" + db.getDbReference() + "' is empty.", e);     
    }            

        // Validate default language definition
        if (!isEmptyDB && db.hasFeature(WGDatabase.FEATURE_FULLCONTENTFEATURES)) {
            db.onConnect(new ValidateDefaultLanguageAction());
        }
       
        // Eventually prepare "external self-personalisation"
        if (db.hasFeature(WGDatabase.FEATURE_FULLCONTENTFEATURES) && domainConfig.getPersonalisation() == null && !db.hasFeature(WGDatabase.FEATURE_SELF_PERSONALIZABLE)) {
            try {
                createExternalSelfPersonalisation(db);
            }
            catch (WGAPIException e) {
                this.log.error("Exception creating external personalisation database for db '" + db.getDbReference() + "'. Profiles will not be available.", e);
            }
        }
       
        // Do system container initialisations
        if (scContext != null) {
            scContext.performInitialisation(new Boolean(isEmptyDB));
            // Revalidate the default language if the database was empty before initialisation, might have new definitions now
            if (isEmptyDB) {
                db.onConnect(new ValidateDefaultLanguageAction());
            }
        }
       
        // Mark this database as fully connected
        db.setAttribute(DBATTRIB_FULLY_CONNECTED, "true");

       
        if (_externalFileServingConfig.isEnabled() && db.getBooleanAttribute(DBATTRIB_EXTERNAL_FILE_SERVING_ENABLED, false)) {
            getLog().info("External file serving enabled for database '" + db.getDbReference() + "'.");
        }
       
        return db;
    }
View Full Code Here

TOP

Related Classes of de.innovationgate.webgate.api.WGDatabase

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.