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;
}
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;
}
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;
}
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();
}
}
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();
}
}
Aggregations