Search in sources :

Example 1 with ImportValidationFeedback

use of org.pentaho.di.imp.rule.ImportValidationFeedback in project pentaho-kettle by pentaho.

the class ExportFeedback method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    String message = null;
    if (this.isSimpleString) {
        message = BaseMessages.getString(PKG, "ExportFeedback.Message.Simple", sdf.format(this.getTime()), this.getItemName());
        sb.append(message);
        sb.append(Const.CR);
        return sb.toString();
    }
    message = BaseMessages.getString(PKG, "ExportFeedback.Message.Main", sdf.format(this.getTime()), this.getStatus().getStatus(), this.getItemName(), this.getItemPath());
    sb.append(message);
    sb.append(Const.CR);
    // that the reason why are you read this comments.
    if (getStatus().equals(ExportFeedback.Status.REJECTED)) {
        List<ImportValidationFeedback> fList = this.getResult();
        for (ImportValidationFeedback res : fList) {
            message = BaseMessages.getString(PKG, "ExportFeedback.Message.RuleViolated", res.getComment());
            sb.append(message);
            sb.append(Const.CR);
        }
    }
    return sb.toString();
}
Also used : ImportValidationFeedback(org.pentaho.di.imp.rule.ImportValidationFeedback)

Example 2 with ImportValidationFeedback

use of org.pentaho.di.imp.rule.ImportValidationFeedback in project pentaho-kettle by pentaho.

the class RepositoryImporter method validateImportedElement.

/**
 * Validates the repository element that is about to get imported against the list of import rules.
 *
 * @param importRules
 *          import rules to validate against.
 * @param subject
 * @throws KettleException
 */
public static void validateImportedElement(ImportRules importRules, Object subject) throws KettleException {
    List<ImportValidationFeedback> feedback = importRules.verifyRules(subject);
    List<ImportValidationFeedback> errors = ImportValidationFeedback.getErrors(feedback);
    if (!errors.isEmpty()) {
        StringBuilder message = new StringBuilder(BaseMessages.getString(PKG, "RepositoryImporter.ValidationFailed.Message", subject.toString()));
        message.append(Const.CR);
        for (ImportValidationFeedback error : errors) {
            message.append(" - ");
            message.append(error.toString());
            message.append(Const.CR);
        }
        throw new KettleException(message.toString());
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ImportValidationFeedback(org.pentaho.di.imp.rule.ImportValidationFeedback)

Example 3 with ImportValidationFeedback

use of org.pentaho.di.imp.rule.ImportValidationFeedback in project pentaho-kettle by pentaho.

the class DatabaseConfigurationImportRule method verifyRule.

@Override
public List<ImportValidationFeedback> verifyRule(Object subject) {
    List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>();
    if (!isEnabled()) {
        return feedback;
    }
    if (databaseMeta == null) {
        feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "This rule contains no database to validate against."));
        return feedback;
    }
    DatabaseMeta verify = null;
    if (subject instanceof HasDatabasesInterface) {
        HasDatabasesInterface dbs = (HasDatabasesInterface) subject;
        verify = dbs.findDatabase(databaseMeta.getName());
    } else if (subject instanceof DatabaseMeta) {
        // 
        if (databaseMeta.getName().equals(((DatabaseMeta) subject).getName())) {
            verify = (DatabaseMeta) subject;
        }
    }
    if (verify == null) {
        return feedback;
    }
    // 
    if (!Utils.isEmpty(databaseMeta.getDatabaseName())) {
        if (!databaseMeta.getDatabaseName().equals(verify.getDatabaseName())) {
            feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The name of the database is not set to the expected value '" + databaseMeta.getDatabaseName() + "'."));
        }
    }
    // 
    if (!Utils.isEmpty(databaseMeta.getHostname())) {
        if (!databaseMeta.getHostname().equals(verify.getHostname())) {
            feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The host name of the database is not set to the expected value '" + databaseMeta.getHostname() + "'."));
        }
    }
    // 
    if (!Utils.isEmpty(databaseMeta.getDatabasePortNumberString())) {
        if (!databaseMeta.getDatabasePortNumberString().equals(verify.getDatabasePortNumberString())) {
            feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The database port of the database is not set to the expected value '" + databaseMeta.getDatabasePortNumberString() + "'."));
        }
    }
    // 
    if (!Utils.isEmpty(databaseMeta.getUsername())) {
        if (!databaseMeta.getUsername().equals(verify.getUsername())) {
            feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The username of the database is not set to the expected value '" + databaseMeta.getUsername() + "'."));
        }
    }
    // 
    if (!Utils.isEmpty(databaseMeta.getPassword())) {
        if (!databaseMeta.getPassword().equals(verify.getPassword())) {
            feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The password of the database is not set to the expected value."));
        }
    }
    if (feedback.isEmpty()) {
        feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.APPROVAL, "The database connection was found and verified."));
    }
    return feedback;
}
Also used : ImportValidationFeedback(org.pentaho.di.imp.rule.ImportValidationFeedback) ArrayList(java.util.ArrayList) HasDatabasesInterface(org.pentaho.di.trans.HasDatabasesInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 4 with ImportValidationFeedback

use of org.pentaho.di.imp.rule.ImportValidationFeedback in project pentaho-kettle by pentaho.

the class JobHasDescriptionImportRule method verifyRule.

@Override
public List<ImportValidationFeedback> verifyRule(Object subject) {
    List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>();
    if (!isEnabled()) {
        return feedback;
    }
    if (!(subject instanceof JobMeta)) {
        return feedback;
    }
    JobMeta transMeta = (JobMeta) subject;
    String description = transMeta.getDescription();
    if (description != null && description.length() > minLength) {
        feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.APPROVAL, "A description is present"));
    } else {
        feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "A description is not present or too short"));
    }
    return feedback;
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) ImportValidationFeedback(org.pentaho.di.imp.rule.ImportValidationFeedback) ArrayList(java.util.ArrayList)

Example 5 with ImportValidationFeedback

use of org.pentaho.di.imp.rule.ImportValidationFeedback in project pentaho-kettle by pentaho.

the class JobHasJobLogConfiguredImportRule method verifyRule.

@Override
public List<ImportValidationFeedback> verifyRule(Object subject) {
    List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>();
    if (!isEnabled()) {
        return feedback;
    }
    if (!(subject instanceof JobMeta)) {
        return feedback;
    }
    JobMeta jobMeta = (JobMeta) subject;
    JobLogTable jobLogTable = jobMeta.getJobLogTable();
    if (!jobLogTable.isDefined()) {
        feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The logging table is not defined"));
    } else {
        if (!Utils.isEmpty(schemaName)) {
            if (schemaName.equals(jobLogTable.getSchemaName())) {
                feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.APPROVAL, "The schema name is set to: " + schemaName));
            } else {
                feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The schema name is not set to: " + schemaName));
            }
        }
        if (!Utils.isEmpty(tableName)) {
            if (tableName.equals(jobLogTable.getTableName())) {
                feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.APPROVAL, "The table name is set to: " + tableName));
            } else {
                feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The table name is not set to: " + tableName));
            }
        }
        if (!Utils.isEmpty(connectionName)) {
            if (connectionName.equals(jobLogTable.getDatabaseMeta().getName())) {
                feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.APPROVAL, "The database connection used for logging is: " + connectionName));
            } else {
                feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The database connection used for logging is not: " + connectionName));
            }
        }
        if (feedback.isEmpty()) {
            feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.APPROVAL, "The logging table is correctly defined"));
        }
    }
    return feedback;
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobLogTable(org.pentaho.di.core.logging.JobLogTable) ImportValidationFeedback(org.pentaho.di.imp.rule.ImportValidationFeedback) ArrayList(java.util.ArrayList)

Aggregations

ImportValidationFeedback (org.pentaho.di.imp.rule.ImportValidationFeedback)15 ArrayList (java.util.ArrayList)10 JobMeta (org.pentaho.di.job.JobMeta)5 TransMeta (org.pentaho.di.trans.TransMeta)5 KettleException (org.pentaho.di.core.exception.KettleException)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 JobLogTable (org.pentaho.di.core.logging.JobLogTable)1 TransLogTable (org.pentaho.di.core.logging.TransLogTable)1 JobHopMeta (org.pentaho.di.job.JobHopMeta)1 HasDatabasesInterface (org.pentaho.di.trans.HasDatabasesInterface)1 TransHopMeta (org.pentaho.di.trans.TransHopMeta)1