Search in sources :

Example 6 with ImportValidationFeedback

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

the class TransformationHasNoDisabledHopsImportRule method verifyRule.

@Override
public List<ImportValidationFeedback> verifyRule(Object subject) {
    List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>();
    if (!isEnabled()) {
        return feedback;
    }
    if (!(subject instanceof TransMeta)) {
        return feedback;
    }
    TransMeta transMeta = (TransMeta) subject;
    for (int i = 0; i < transMeta.nrTransHops(); i++) {
        TransHopMeta hop = transMeta.getTransHop(i);
        if (!hop.isEnabled()) {
            feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "There is a disabled hop in the transformation."));
        }
    }
    if (feedback.isEmpty()) {
        feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.APPROVAL, "All hops are enabled in this transformation."));
    }
    return feedback;
}
Also used : ImportValidationFeedback(org.pentaho.di.imp.rule.ImportValidationFeedback) ArrayList(java.util.ArrayList) TransMeta(org.pentaho.di.trans.TransMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta)

Example 7 with ImportValidationFeedback

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

the class PurRepositoryExporter method toExport.

private boolean toExport(AbstractMeta meta) {
    boolean shouldExport = true;
    List<ImportValidationFeedback> feedback = importRules.verifyRules(meta);
    List<ImportValidationFeedback> errors = ImportValidationFeedback.getErrors(feedback);
    if (!errors.isEmpty()) {
        shouldExport = false;
        // $NON-NLS-1$
        log.logError(BaseMessages.getString(PKG, "PurRepositoryExporter.ERROR_EXPORT_ITEM", meta.getName()));
        for (ImportValidationFeedback error : errors) {
            // $NON-NLS-1$
            log.logError(BaseMessages.getString(PKG, "PurRepositoryExporter.ERROR_EXPORT_ITEM_RULE", error.toString()));
        }
    }
    return shouldExport;
}
Also used : ImportValidationFeedback(org.pentaho.di.imp.rule.ImportValidationFeedback)

Example 8 with ImportValidationFeedback

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

the class RepositoryExporter method validateObject.

private List<ImportValidationFeedback> validateObject(Object subject, boolean boolFeedback) throws KettleException {
    if (!hasRules) {
        return Collections.emptyList();
    }
    if (!boolFeedback) {
        // this is call from Pan, job Executor or somthing else - we should throw
        // exception if one or more export rules is viloated.
        RepositoryImporter.validateImportedElement(importRules, subject);
    }
    List<ImportValidationFeedback> feedback = importRules.verifyRules(subject);
    List<ImportValidationFeedback> errors = new ArrayList<ImportValidationFeedback>(feedback.size());
    for (ImportValidationFeedback res : feedback) {
        if (res.isError()) {
            errors.add(res);
        }
    }
    return errors;
}
Also used : ImportValidationFeedback(org.pentaho.di.imp.rule.ImportValidationFeedback) ArrayList(java.util.ArrayList)

Example 9 with ImportValidationFeedback

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

the class RepositoryExporter method exportTransformations.

private void exportTransformations(ProgressMonitorDecorator monitor, RepositoryDirectoryInterface dirTree, ExportWriter writer, boolean feedback) throws KettleException {
    try {
        writer.openTrans();
        monitor.subTask(BaseMessages.getString(PKG, "Repository.Exporter.Monitor.StartTransExport"));
        // Loop over all the directory id's
        ObjectId[] dirids = dirTree.getDirectoryIDs();
        log.logDebug(BaseMessages.getString(PKG, "Repository.Exporter.Log.DirectoryGoing", dirids.length, dirTree.getPath()));
        for (int d = 0; d < dirids.length; d++) {
            if (monitor.isCanceled()) {
                cancelMonitorAction(writer);
                break;
            }
            RepositoryDirectoryInterface repdir = dirTree.findDirectory(dirids[d]);
            String[] trans = repository.getTransformationNames(dirids[d], false);
            log.logDebug(BaseMessages.getString(PKG, "Repository.Exporter.Log.FindTrans", trans.length, repdir.getName()));
            String dirPath = repdir.getPath();
            for (int i = 0; i < trans.length; i++) {
                if (monitor.isCanceled()) {
                    break;
                }
                log.logDebug(BaseMessages.getString(PKG, "Repository.Exporter.Log.LoadingTransformation", dirPath, trans[i]));
                monitor.subTask(BaseMessages.getString(PKG, "Repository.Exporter.Monitor.ExportTransformation", trans[i]));
                // reads last //
                TransMeta transMeta = repository.loadTransformation(trans[i], repdir, null, true, null);
                // version
                transMeta.setRepository(repository);
                convertFromFileRepository(transMeta);
                List<ImportValidationFeedback> errors = this.validateObject(transMeta, feedback);
                if (errors.isEmpty()) {
                    writer.writeTrans(transMeta.getXML() + Const.CR);
                } else {
                    log.logError(BaseMessages.getString(PKG, "Repository.Exporter.Log.TransRuleViolation", trans[i], repdir));
                    this.rulesViolation = true;
                    monitor.registerRuleViolation();
                    writer.registerRuleViolation();
                }
                // do we need any feedback on this action?
                if (feedback) {
                    ExportFeedback fb = new ExportFeedback();
                    fb.setType(ExportFeedback.Type.TRANSFORMATION);
                    fb.setItemName(transMeta.getName());
                    fb.setItemPath(dirPath);
                    ExportFeedback.Status status = errors.isEmpty() ? ExportFeedback.Status.EXPORTED : ExportFeedback.Status.REJECTED;
                    fb.setStatus(status);
                    fb.setResult(errors);
                    this.feedbackList.add(fb);
                }
            }
        }
    } catch (Exception e) {
        throw new KettleException("Error while exporting repository transformations", e);
    } finally {
        writer.closeTrans();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TransMeta(org.pentaho.di.trans.TransMeta) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) KettleException(org.pentaho.di.core.exception.KettleException) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ImportValidationFeedback(org.pentaho.di.imp.rule.ImportValidationFeedback)

Example 10 with ImportValidationFeedback

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

the class RepositoryExporter method exportJobs.

private void exportJobs(ProgressMonitorDecorator monitor, RepositoryDirectoryInterface dirTree, ExportWriter writer, boolean feedback) throws KettleException {
    try {
        monitor.subTask(BaseMessages.getString(PKG, "Repository.Exporter.Monitor.StartJobsExport"));
        writer.openJob();
        // Loop over all the directory id's
        ObjectId[] dirids = dirTree.getDirectoryIDs();
        log.logDebug(BaseMessages.getString(PKG, "Repository.Exporter.Log.DirectoryGoing", dirids.length, dirTree.getPath()));
        for (int d = 0; d < dirids.length; d++) {
            if (monitor.isCanceled()) {
                cancelMonitorAction(writer);
                break;
            }
            RepositoryDirectoryInterface repdir = dirTree.findDirectory(dirids[d]);
            String[] jobs = repository.getJobNames(dirids[d], false);
            log.logDebug(BaseMessages.getString(PKG, "Repository.Exporter.Log.FindJobs", jobs.length, repdir.getName()));
            String dirPath = repdir.getPath();
            for (int i = 0; i < jobs.length; i++) {
                if (monitor.isCanceled()) {
                    break;
                }
                monitor.subTask(BaseMessages.getString(PKG, "Repository.Exporter.Monitor.ExportingJob", jobs[i]));
                log.logDebug(BaseMessages.getString(PKG, "Repository.Exporter.Log.LoadingJob", dirPath, jobs[i]));
                // reads last version
                JobMeta jobMeta = repository.loadJob(jobs[i], repdir, null, null);
                // Pass the repository along in order for us to do correct exports to XML of object references
                jobMeta.setRepository(repository);
                // Check file repository export
                convertFromFileRepository(jobMeta);
                List<ImportValidationFeedback> errors = this.validateObject(jobMeta, feedback);
                if (errors.isEmpty()) {
                    writer.writeJob(jobMeta.getXML() + Const.CR);
                } else {
                    log.logError(BaseMessages.getString(PKG, "Repository.Exporter.Log.JobRuleViolation", jobs[i], repdir));
                    this.rulesViolation = true;
                    monitor.registerRuleViolation();
                    writer.registerRuleViolation();
                }
                // do we need any feedback on this action?
                if (feedback) {
                    ExportFeedback fb = new ExportFeedback();
                    fb.setType(ExportFeedback.Type.JOB);
                    fb.setItemName(jobMeta.getName());
                    fb.setItemPath(dirPath);
                    ExportFeedback.Status status = errors.isEmpty() ? ExportFeedback.Status.EXPORTED : ExportFeedback.Status.REJECTED;
                    fb.setStatus(status);
                    fb.setResult(errors);
                    this.feedbackList.add(fb);
                }
            }
        }
    } catch (Exception e) {
        throw new KettleException("Error while exporting repository jobs", e);
    } finally {
        writer.closeJob();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) KettleException(org.pentaho.di.core.exception.KettleException) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ImportValidationFeedback(org.pentaho.di.imp.rule.ImportValidationFeedback)

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