import org.pentaho.di.job.JobMeta; //导入方法依赖的package包/类
private boolean importJob(Node jobnode, RepositoryImportFeedbackInterface feedback) throws KettleException {
// Load the job from the XML node.
//
JobMeta jobMeta = new JobMeta(jobnode, rep, false, SpoonFactory.getInstance());
replaceSharedObjects(jobMeta);
feedback.setLabel(BaseMessages.getString(PKG, "RepositoryImporter.ImportJob.Label", Integer.toString(jobNumber), jobMeta.getName()));
validateImportedElement(importRules, jobMeta);
// What's the directory path?
String directoryPath = Const.NVL(XMLHandler.getTagValue(jobnode, "directory"), Const.FILE_SEPARATOR);
if (jobDirOverride != null) {
directoryPath = jobDirOverride;
}
if (directoryPath.startsWith("/")) {
// remove the leading root, we don't need it.
directoryPath = directoryPath.substring(1);
}
// If we have a set of source directories to limit ourselves to, consider this.
//
if (limitDirs.size()>0 && Const.indexOfString(directoryPath, limitDirs)<0) {
// Not in the limiting set of source directories, skip the import of this transformation...
//
feedback.addLog(BaseMessages.getString(PKG, "RepositoryImporter.SkippedJobNotPartOfLimitingDirectories.Log", jobMeta.getName()));
return true;
}
RepositoryDirectoryInterface targetDirectory = getTargetDirectory(directoryPath, jobDirOverride, feedback);
// OK, we loaded the job from XML and all went well...
// See if the job already exists!
ObjectId existintId = rep.getJobId(jobMeta.getName(), targetDirectory);
if (existintId != null && askOverwrite) {
overwrite = feedback.jobOverwritePrompt(jobMeta);
askOverwrite = feedback.isAskingOverwriteConfirmation();
} else {
updateDisplay();
}
if (existintId == null || overwrite) {
jobMeta.setRepositoryDirectory(targetDirectory);
jobMeta.setObjectId(existintId);
patchJobEntries(jobMeta);
try {
// Keep info on who & when this transformation was created...
if (jobMeta.getCreatedUser() == null || jobMeta.getCreatedUser().equals("-")) {
jobMeta.setCreatedDate(new Date());
if (rep.getUserInfo() != null) {
jobMeta.setCreatedUser(rep.getUserInfo().getLogin());
} else {
jobMeta.setCreatedUser(null);
}
}
rep.save(jobMeta, versionComment, null, overwrite);
if (jobMeta.hasRepositoryReferences()) {
referencingObjects.add(new RepositoryObject(jobMeta.getObjectId(), jobMeta.getName(), jobMeta.getRepositoryDirectory(), null, null, RepositoryObjectType.JOB, null, false));
}
feedback.addLog(BaseMessages.getString(PKG, "RepositoryImporter.JobSaved.Log", Integer.toString(jobNumber), jobMeta.getName()));
} catch(Exception e) {
feedback.addLog(BaseMessages.getString(PKG, "RepositoryImporter.ErrorSavingJob.Log", Integer.toString(jobNumber), jobMeta.getName(), Const.getStackTracker(e)));
if (!feedback.askContinueOnErrorQuestion(
BaseMessages.getString(PKG, "RepositoryImporter.DoYouWantToContinue.Title"),
BaseMessages.getString(PKG, "RepositoryImporter.DoYouWantToContinue.Message"))) {
return false;
}
}
} else {
feedback.addLog(BaseMessages.getString(PKG, "RepositoryImporter.SkippedExistingJob.Log", jobMeta.getName()));
}
return true;
}