Search in sources :

Example 1 with KettleRepositoryNotSupportedException

use of org.pentaho.di.core.exception.KettleRepositoryNotSupportedException in project pentaho-kettle by pentaho.

the class RepositoriesMeta method parseRepositoriesDoc.

protected void parseRepositoriesDoc(Document doc) throws Exception {
    // Get the <repositories> node:
    Node repsnode = XMLHandler.getSubNode(doc, "repositories");
    // Handle connections
    int nrconn = XMLHandler.countNodes(repsnode, "connection");
    if (log.isDebug()) {
        log.logDebug(BaseMessages.getString(PKG, "RepositoryMeta.Log.ConnectionNumber", nrconn));
    }
    for (int i = 0; i < nrconn; i++) {
        if (log.isDebug()) {
            log.logDebug(BaseMessages.getString(PKG, "RepositoryMeta.Log.LookingConnection", i));
        }
        Node dbnode = XMLHandler.getSubNodeByNr(repsnode, "connection", i);
        DatabaseMeta dbcon = null;
        try {
            dbcon = new DatabaseMeta(dbnode);
            addDatabase(dbcon);
            if (log.isDebug()) {
                log.logDebug(BaseMessages.getString(PKG, "RepositoryMeta.Log.ReadConnection", dbcon.getName()));
            }
        } catch (Exception kpe) {
            log.logError(BaseMessages.getString(PKG, "RepositoryMeta.Error.CreatingDatabaseMeta", dbcon.getName()));
        }
    }
    // Handle repositories...
    int nrreps = XMLHandler.countNodes(repsnode, RepositoryMeta.XML_TAG);
    if (log.isDebug()) {
        log.logDebug(BaseMessages.getString(PKG, "RepositoryMeta.Log.RepositoryNumber", nrreps));
    }
    StringBuilder unableToReadIds = new StringBuilder();
    KettleException kettleException = null;
    for (int i = 0; i < nrreps; i++) {
        Node repnode = XMLHandler.getSubNodeByNr(repsnode, RepositoryMeta.XML_TAG, i);
        if (log.isDebug()) {
            log.logDebug(BaseMessages.getString(PKG, "RepositoryMeta.Log.LookingRepository", i));
        }
        String id = XMLHandler.getTagValue(repnode, "id");
        if (Utils.isEmpty(id)) {
            // Backward compatibility : if the id is not defined, it's the database repository!
            // 
            id = KettleDatabaseRepositoryMeta.REPOSITORY_TYPE_ID;
        }
        try {
            RepositoryMeta repositoryMeta = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, id, RepositoryMeta.class);
            if (repositoryMeta != null) {
                repositoryMeta.loadXML(repnode, databases);
                // repositories dialog
                if (repositoryMeta.getDescription() == null || repositoryMeta.getDescription().equals("")) {
                    repositoryMeta.setDescription(repositoryMeta.getName());
                }
                addRepository(repositoryMeta);
                if (log.isDebug()) {
                    log.logDebug(BaseMessages.getString(PKG, "RepositoryMeta.Log.ReadRepository", repositoryMeta.getName()));
                }
            } else {
                unableToReadIds.append(id);
                unableToReadIds.append(",");
                if (log.isDebug()) {
                    log.logDebug(BaseMessages.getString(PKG, "RepositoryMeta.Error.ReadRepositoryId", id));
                }
            }
        } catch (KettleException ex) {
            // Get to the root cause
            Throwable cause = ex;
            kettleException = ex;
            while (cause.getCause() != null) {
                cause = cause.getCause();
            }
            if (cause instanceof KettleRepositoryNotSupportedException) {
                // If the root cause is a KettleRepositoryNotSupportedException, do not fail
                if (log.isDebug()) {
                    log.logDebug(BaseMessages.getString(PKG, "RepositoryMeta.Error.UnrecognizedRepositoryType", id));
                }
            }
        }
    }
    if (unableToReadIds != null && unableToReadIds.length() > 0) {
        errorMessage = BaseMessages.getString(PKG, "RepositoryMeta.Error.ReadRepositoryIdNotAvailable", unableToReadIds.substring(0, unableToReadIds.lastIndexOf(",")));
    }
    if (kettleException != null) {
        throw kettleException;
    }
}
Also used : KettleDatabaseRepositoryMeta(org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta) KettleException(org.pentaho.di.core.exception.KettleException) Node(org.w3c.dom.Node) KettleRepositoryNotSupportedException(org.pentaho.di.core.exception.KettleRepositoryNotSupportedException) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleException(org.pentaho.di.core.exception.KettleException) FileNotFoundException(java.io.FileNotFoundException) KettleRepositoryNotSupportedException(org.pentaho.di.core.exception.KettleRepositoryNotSupportedException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleRepositoryNotSupportedException (org.pentaho.di.core.exception.KettleRepositoryNotSupportedException)1 KettleDatabaseRepositoryMeta (org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta)1 Node (org.w3c.dom.Node)1