use of org.pentaho.di.core.util.CurrentDirectoryResolver in project pentaho-kettle by pentaho.
the class StepWithMappingMeta method loadMappingMeta.
public static synchronized TransMeta loadMappingMeta(StepWithMappingMeta executorMeta, Repository rep, IMetaStore metaStore, VariableSpace space, boolean share) throws KettleException {
TransMeta mappingTransMeta = null;
CurrentDirectoryResolver r = new CurrentDirectoryResolver();
// send parentVariables = null we don't need it here for resolving resolveCurrentDirectory.
// Otherwise we destroy child variables and the option "Inherit all variables from the transformation" is enabled always.
VariableSpace tmpSpace = r.resolveCurrentDirectory(executorMeta.getSpecificationMethod(), null, rep, executorMeta.getParentStepMeta(), executorMeta.getFileName());
switch(executorMeta.getSpecificationMethod()) {
case FILENAME:
String realFilename = tmpSpace.environmentSubstitute(executorMeta.getFileName());
try {
// Don't set internal variables: they belong to the parent thread!
if (rep != null) {
// need to try to load from the repository
realFilename = r.normalizeSlashes(realFilename);
try {
String dirStr = realFilename.substring(0, realFilename.lastIndexOf("/"));
String tmpFilename = realFilename.substring(realFilename.lastIndexOf("/") + 1);
RepositoryDirectoryInterface dir = rep.findDirectory(dirStr);
mappingTransMeta = rep.loadTransformation(tmpFilename, dir, null, true, null);
} catch (KettleException ke) {
// try without extension
if (realFilename.endsWith(Const.STRING_TRANS_DEFAULT_EXT)) {
try {
String tmpFilename = realFilename.substring(realFilename.lastIndexOf("/") + 1, realFilename.indexOf("." + Const.STRING_TRANS_DEFAULT_EXT));
String dirStr = realFilename.substring(0, realFilename.lastIndexOf("/"));
RepositoryDirectoryInterface dir = rep.findDirectory(dirStr);
mappingTransMeta = rep.loadTransformation(tmpFilename, dir, null, true, null);
} catch (KettleException ke2) {
// fall back to try loading from file system (transMeta is going to be null)
}
}
}
}
if (mappingTransMeta == null) {
mappingTransMeta = new TransMeta(realFilename, metaStore, rep, true, tmpSpace, null);
LogChannel.GENERAL.logDetailed("Loading transformation from repository", "Transformation was loaded from XML file [" + realFilename + "]");
}
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(PKG, "StepWithMappingMeta.Exception.UnableToLoadTrans"), e);
}
break;
case REPOSITORY_BY_NAME:
String realTransname = tmpSpace.environmentSubstitute(executorMeta.getTransName());
String realDirectory = tmpSpace.environmentSubstitute(executorMeta.getDirectoryPath());
if (rep != null) {
if (!Utils.isEmpty(realTransname) && !Utils.isEmpty(realDirectory)) {
realDirectory = r.normalizeSlashes(realDirectory);
RepositoryDirectoryInterface repdir = rep.findDirectory(realDirectory);
if (repdir != null) {
try {
// reads the last revision in the repository...
mappingTransMeta = rep.loadTransformation(realTransname, repdir, null, true, null);
// TODO: FIXME: pass in metaStore to repository?
LogChannel.GENERAL.logDetailed("Loading transformation from repository", "Executor transformation [" + realTransname + "] was loaded from the repository");
} catch (Exception e) {
throw new KettleException("Unable to load transformation [" + realTransname + "]", e);
}
}
}
} else {
// rep is null, let's try loading by filename
try {
mappingTransMeta = new TransMeta(realDirectory + "/" + realTransname, metaStore, null, true, tmpSpace, null);
} catch (KettleException ke) {
try {
// add .ktr extension and try again
mappingTransMeta = new TransMeta(realDirectory + "/" + realTransname + "." + Const.STRING_TRANS_DEFAULT_EXT, metaStore, null, true, tmpSpace, null);
} catch (KettleException ke2) {
throw new KettleException(BaseMessages.getString(PKG, "StepWithMappingMeta.Exception.UnableToLoadTrans", realTransname) + realDirectory);
}
}
}
break;
case REPOSITORY_BY_REFERENCE:
// Read the last revision by reference...
mappingTransMeta = rep.loadTransformation(executorMeta.getTransObjectId(), null);
break;
default:
break;
}
if (mappingTransMeta == null) {
// skip warning
return null;
}
// When the child parameter does exist in the parent parameters, overwrite the child parameter by the
// parent parameter.
replaceVariableValues(mappingTransMeta, space);
if (share) {
// All other parent parameters need to get copied into the child parameters (when the 'Inherit all
// variables from the transformation?' option is checked)
addMissingVariables(mappingTransMeta, space);
}
mappingTransMeta.setRepository(rep);
mappingTransMeta.setMetaStore(metaStore);
mappingTransMeta.setFilename(mappingTransMeta.getFilename());
return mappingTransMeta;
}
use of org.pentaho.di.core.util.CurrentDirectoryResolver in project pentaho-kettle by pentaho.
the class JobExecutorMeta method loadJobMeta.
public static final synchronized JobMeta loadJobMeta(JobExecutorMeta executorMeta, Repository rep, IMetaStore metaStore, VariableSpace space) throws KettleException {
JobMeta mappingJobMeta = null;
CurrentDirectoryResolver r = new CurrentDirectoryResolver();
VariableSpace tmpSpace = r.resolveCurrentDirectory(executorMeta.getSpecificationMethod(), space, rep, executorMeta.getParentStepMeta(), executorMeta.getFileName());
switch(executorMeta.getSpecificationMethod()) {
case FILENAME:
String realFilename = tmpSpace.environmentSubstitute(executorMeta.getFileName());
try {
//
if (rep != null) {
realFilename = r.normalizeSlashes(realFilename);
// need to try to load from the repository
try {
String dirStr = realFilename.substring(0, realFilename.lastIndexOf("/"));
String tmpFilename = realFilename.substring(realFilename.lastIndexOf("/") + 1);
RepositoryDirectoryInterface dir = rep.findDirectory(dirStr);
mappingJobMeta = rep.loadJob(tmpFilename, dir, null, null);
} catch (KettleException ke) {
// try without extension
if (realFilename.endsWith(Const.STRING_JOB_DEFAULT_EXT)) {
try {
String tmpFilename = realFilename.substring(realFilename.lastIndexOf("/") + 1, realFilename.indexOf("." + Const.STRING_JOB_DEFAULT_EXT));
String dirStr = realFilename.substring(0, realFilename.lastIndexOf("/"));
RepositoryDirectoryInterface dir = rep.findDirectory(dirStr);
mappingJobMeta = rep.loadJob(tmpFilename, dir, null, null);
} catch (KettleException ke2) {
// fall back to try loading from file system (mappingJobMeta is going to be null)
}
}
}
}
if (mappingJobMeta == null) {
mappingJobMeta = new JobMeta(null, realFilename, rep, metaStore, null);
LogChannel.GENERAL.logDetailed("Loading job from repository", "Job was loaded from XML file [" + realFilename + "]");
}
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(PKG, "JobExecutorMeta.Exception.UnableToLoadJob"), e);
}
break;
case REPOSITORY_BY_NAME:
String realJobname = tmpSpace.environmentSubstitute(executorMeta.getJobName());
String realDirectory = tmpSpace.environmentSubstitute(executorMeta.getDirectoryPath());
if (rep != null) {
if (!Utils.isEmpty(realJobname) && !Utils.isEmpty(realDirectory)) {
realDirectory = r.normalizeSlashes(realDirectory);
RepositoryDirectoryInterface repdir = rep.findDirectory(realDirectory);
if (repdir != null) {
try {
// reads the last revision in the repository...
//
// TODO: FIXME: should we also pass an
mappingJobMeta = rep.loadJob(realJobname, repdir, null, null);
// external MetaStore into the
// repository?
LogChannel.GENERAL.logDetailed("Loading job from repository", "Executor job [" + realJobname + "] was loaded from the repository");
} catch (Exception e) {
throw new KettleException("Unable to load job [" + realJobname + "]", e);
}
}
}
} else {
// rep is null, let's try loading by filename
try {
mappingJobMeta = new JobMeta(null, realDirectory + "/" + realJobname, rep, metaStore, null);
} catch (KettleException ke) {
try {
// add .kjb extension and try again
mappingJobMeta = new JobMeta(null, realDirectory + "/" + realJobname + "." + Const.STRING_JOB_DEFAULT_EXT, rep, metaStore, null);
} catch (KettleException ke2) {
throw new KettleException(BaseMessages.getString(PKG, "JobExecutorMeta.Exception.UnableToLoadJob", realJobname) + realDirectory);
}
}
}
break;
case REPOSITORY_BY_REFERENCE:
// Read the last revision by reference...
mappingJobMeta = rep.loadJob(executorMeta.getJobObjectId(), null);
break;
default:
break;
}
// Pass some important information to the mapping transformation metadata:
// When the child parameter does exist in the parent parameters, overwrite the child parameter by the
// parent parameter.
StepWithMappingMeta.replaceVariableValues(mappingJobMeta, space);
if (executorMeta.getParameters().isInheritingAllVariables()) {
// All other parent parameters need to get copied into the child parameters (when the 'Inherit all
// variables from the transformation?' option is checked)
StepWithMappingMeta.addMissingVariables(mappingJobMeta, space);
}
mappingJobMeta.setRepository(rep);
mappingJobMeta.setMetaStore(metaStore);
mappingJobMeta.setFilename(mappingJobMeta.getFilename());
return mappingJobMeta;
}
use of org.pentaho.di.core.util.CurrentDirectoryResolver in project pentaho-kettle by pentaho.
the class MetaInjectMeta method loadTransformationMeta.
public static final synchronized TransMeta loadTransformationMeta(MetaInjectMeta injectMeta, Repository rep, IMetaStore metaStore, VariableSpace space) throws KettleException {
TransMeta mappingTransMeta = null;
CurrentDirectoryResolver resolver = new CurrentDirectoryResolver();
VariableSpace tmpSpace = resolver.resolveCurrentDirectory(injectMeta.getSpecificationMethod(), space, rep, injectMeta.getParentStepMeta(), injectMeta.getFileName());
switch(injectMeta.getSpecificationMethod()) {
case FILENAME:
String realFilename = tmpSpace.environmentSubstitute(injectMeta.getFileName());
try {
//
if (rep != null) {
// need to try to load from the repository
realFilename = resolver.normalizeSlashes(realFilename);
try {
String dirStr = realFilename.substring(0, realFilename.lastIndexOf("/"));
String tmpFilename = realFilename.substring(realFilename.lastIndexOf("/") + 1);
RepositoryDirectoryInterface dir = rep.findDirectory(dirStr);
mappingTransMeta = rep.loadTransformation(tmpFilename, dir, null, true, null);
} catch (KettleException ke) {
// try without extension
if (realFilename.endsWith(Const.STRING_TRANS_DEFAULT_EXT)) {
try {
String tmpFilename = realFilename.substring(realFilename.lastIndexOf("/") + 1, realFilename.indexOf("." + Const.STRING_TRANS_DEFAULT_EXT));
String dirStr = realFilename.substring(0, realFilename.lastIndexOf("/"));
RepositoryDirectoryInterface dir = rep.findDirectory(dirStr);
mappingTransMeta = rep.loadTransformation(tmpFilename, dir, null, true, null);
} catch (KettleException ke2) {
// fall back to try loading from file system (transMeta is going to be null)
}
}
}
}
if (mappingTransMeta == null) {
mappingTransMeta = new TransMeta(realFilename, metaStore, rep, false, tmpSpace, null);
mappingTransMeta.getLogChannel().logDetailed("Loading Mapping from repository", "Mapping transformation was loaded from XML file [" + realFilename + "]");
}
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(PKG, "MetaInjectMeta.Exception.UnableToLoadTransformationFromFile", realFilename), e);
}
break;
case REPOSITORY_BY_NAME:
String realTransname = tmpSpace.environmentSubstitute(injectMeta.getTransName());
String realDirectory = tmpSpace.environmentSubstitute(injectMeta.getDirectoryPath());
if (rep != null) {
if (!Utils.isEmpty(realTransname) && !Utils.isEmpty(realDirectory) && rep != null) {
RepositoryDirectoryInterface repdir = rep.findDirectory(realDirectory);
if (repdir != null) {
try {
// reads the last revision in the repository...
//
// TODO: FIXME: see if we need to pass external MetaStore references to the repository?
//
mappingTransMeta = rep.loadTransformation(realTransname, repdir, null, true, null);
mappingTransMeta.getLogChannel().logDetailed("Loading Mapping from repository", "Mapping transformation [" + realTransname + "] was loaded from the repository");
} catch (Exception e) {
throw new KettleException("Unable to load transformation [" + realTransname + "]", e);
}
} else {
throw new KettleException(BaseMessages.getString(PKG, "MetaInjectMeta.Exception.UnableToLoadTransformationFromRepository", realTransname, realDirectory));
}
}
} else {
try {
mappingTransMeta = new TransMeta(realDirectory + "/" + realTransname, metaStore, rep, true, tmpSpace, null);
} catch (KettleException ke) {
try {
// add .ktr extension and try again
mappingTransMeta = new TransMeta(realDirectory + "/" + realTransname + "." + Const.STRING_TRANS_DEFAULT_EXT, metaStore, rep, true, tmpSpace, null);
} catch (KettleException ke2) {
throw new KettleException(BaseMessages.getString(PKG, "StepWithMappingMeta.Exception.UnableToLoadTrans", realTransname) + realDirectory);
}
}
}
break;
case REPOSITORY_BY_REFERENCE:
// Read the last revision by reference...
mappingTransMeta = rep.loadTransformation(injectMeta.getTransObjectId(), null);
break;
default:
break;
}
// Pass some important information to the mapping transformation metadata:
//
mappingTransMeta.copyVariablesFrom(space);
mappingTransMeta.setRepository(rep);
mappingTransMeta.setFilename(mappingTransMeta.getFilename());
return mappingTransMeta;
}
use of org.pentaho.di.core.util.CurrentDirectoryResolver in project pentaho-kettle by pentaho.
the class JobEntryJob method getJobMeta.
public JobMeta getJobMeta(Repository rep, IMetaStore metaStore, VariableSpace space) throws KettleException {
JobMeta jobMeta = null;
try {
CurrentDirectoryResolver r = new CurrentDirectoryResolver();
VariableSpace tmpSpace = r.resolveCurrentDirectory(specificationMethod, space, rep, parentJob, getFilename());
switch(specificationMethod) {
case FILENAME:
String realFilename = tmpSpace.environmentSubstitute(getFilename());
if (rep != null) {
// need to try to load from the repository
realFilename = r.normalizeSlashes(realFilename);
try {
String dirStr = realFilename.substring(0, realFilename.lastIndexOf("/"));
String tmpFilename = realFilename.substring(realFilename.lastIndexOf("/") + 1);
RepositoryDirectoryInterface dir = rep.findDirectory(dirStr);
jobMeta = rep.loadJob(tmpFilename, dir, null, null);
} catch (KettleException ke) {
// try without extension
if (realFilename.endsWith(Const.STRING_JOB_DEFAULT_EXT)) {
try {
String tmpFilename = realFilename.substring(realFilename.lastIndexOf("/") + 1, realFilename.indexOf("." + Const.STRING_JOB_DEFAULT_EXT));
String dirStr = realFilename.substring(0, realFilename.lastIndexOf("/"));
RepositoryDirectoryInterface dir = rep.findDirectory(dirStr);
jobMeta = rep.loadJob(tmpFilename, dir, null, null);
} catch (KettleException ke2) {
// fall back to try loading from file system (mappingJobMeta is going to be null)
}
}
}
}
if (jobMeta == null) {
jobMeta = new JobMeta(tmpSpace, realFilename, rep, metaStore, null);
}
break;
case REPOSITORY_BY_NAME:
String realDirectory = tmpSpace.environmentSubstitute(getDirectory());
String realJobName = tmpSpace.environmentSubstitute(getJobName());
if (rep != null) {
realDirectory = r.normalizeSlashes(realDirectory);
RepositoryDirectoryInterface repositoryDirectory = rep.loadRepositoryDirectoryTree().findDirectory(realDirectory);
if (repositoryDirectory == null) {
throw new KettleException("Unable to find repository directory [" + Const.NVL(realDirectory, "") + "]");
}
// reads
jobMeta = rep.loadJob(realJobName, repositoryDirectory, null, null);
} else {
// rep is null, let's try loading by filename
try {
jobMeta = new JobMeta(tmpSpace, realDirectory + "/" + realJobName, rep, metaStore, null);
} catch (KettleException ke) {
try {
// add .kjb extension and try again
jobMeta = new JobMeta(tmpSpace, realDirectory + "/" + realJobName + "." + Const.STRING_JOB_DEFAULT_EXT, rep, metaStore, null);
} catch (KettleException ke2) {
ke2.printStackTrace();
throw new KettleException("Could not execute job specified in a repository since we're not connected to one");
}
}
}
break;
case REPOSITORY_BY_REFERENCE:
if (rep != null) {
// Load the last version...
//
jobMeta = rep.loadJob(jobObjectId, null);
break;
} else {
throw new KettleException("Could not execute job specified in a repository since we're not connected to one");
}
default:
throw new KettleException("The specified object location specification method '" + specificationMethod + "' is not yet supported in this job entry.");
}
if (jobMeta != null) {
jobMeta.setRepository(rep);
jobMeta.setMetaStore(metaStore);
}
return jobMeta;
} catch (Exception e) {
throw new KettleException("Unexpected error during job metadata load", e);
}
}
use of org.pentaho.di.core.util.CurrentDirectoryResolver in project pentaho-kettle by pentaho.
the class JobEntryTrans method getTransMeta.
public TransMeta getTransMeta(Repository rep, IMetaStore metaStore, VariableSpace space) throws KettleException {
try {
TransMeta transMeta = null;
CurrentDirectoryResolver r = new CurrentDirectoryResolver();
VariableSpace tmpSpace = r.resolveCurrentDirectory(specificationMethod, space, rep, parentJob, getFilename());
switch(specificationMethod) {
case FILENAME:
String realFilename = tmpSpace.environmentSubstitute(getFilename());
if (rep != null) {
if (StringUtils.isBlank(realFilename)) {
throw new KettleException(BaseMessages.getString(PKG, "JobTrans.Exception.MissingTransFileName"));
}
realFilename = r.normalizeSlashes(realFilename);
// need to try to load from the repository
try {
String dirStr = realFilename.substring(0, realFilename.lastIndexOf("/"));
String tmpFilename = realFilename.substring(realFilename.lastIndexOf("/") + 1);
RepositoryDirectoryInterface dir = rep.findDirectory(dirStr);
transMeta = rep.loadTransformation(tmpFilename, dir, null, true, null);
} catch (KettleException ke) {
// try without extension
if (realFilename.endsWith(Const.STRING_TRANS_DEFAULT_EXT)) {
try {
String tmpFilename = realFilename.substring(realFilename.lastIndexOf("/") + 1, realFilename.indexOf("." + Const.STRING_TRANS_DEFAULT_EXT));
String dirStr = realFilename.substring(0, realFilename.lastIndexOf("/"));
RepositoryDirectoryInterface dir = rep.findDirectory(dirStr);
transMeta = rep.loadTransformation(tmpFilename, dir, null, true, null);
} catch (KettleException ke2) {
// fall back to try loading from file system (transMeta is going to be null)
}
}
}
}
if (transMeta == null) {
logBasic("Loading transformation from XML file [" + realFilename + "]");
transMeta = new TransMeta(realFilename, metaStore, null, true, null, null);
}
break;
case REPOSITORY_BY_NAME:
String transname = tmpSpace.environmentSubstitute(getTransname());
String realDirectory = tmpSpace.environmentSubstitute(getDirectory());
logBasic(BaseMessages.getString(PKG, "JobTrans.Log.LoadingTransRepDirec", transname, realDirectory));
if (rep != null) {
//
// It only makes sense to try to load from the repository when the
// repository is also filled in.
//
// It reads last the last revision from the repository.
//
realDirectory = r.normalizeSlashes(realDirectory);
RepositoryDirectoryInterface repositoryDirectory = rep.findDirectory(realDirectory);
transMeta = rep.loadTransformation(transname, repositoryDirectory, null, true, null);
} else {
// rep is null, let's try loading by filename
try {
transMeta = new TransMeta(realDirectory + "/" + transname, metaStore, null, true, this, null);
} catch (KettleException ke) {
try {
// add .ktr extension and try again
transMeta = new TransMeta(realDirectory + "/" + transname + "." + Const.STRING_TRANS_DEFAULT_EXT, metaStore, null, true, this, null);
} catch (KettleException ke2) {
throw new KettleException(BaseMessages.getString(PKG, "JobTrans.Exception.NoRepDefined"), ke2);
}
}
}
break;
case REPOSITORY_BY_REFERENCE:
if (transObjectId == null) {
throw new KettleException(BaseMessages.getString(PKG, "JobTrans.Exception.ReferencedTransformationIdIsNull"));
}
if (rep != null) {
// Load the last revision
//
transMeta = rep.loadTransformation(transObjectId, null);
}
break;
default:
throw new KettleException("The specified object location specification method '" + specificationMethod + "' is not yet supported in this job entry.");
}
if (transMeta != null) {
// set Internal.Entry.Current.Directory again because it was changed
transMeta.setInternalKettleVariables();
// When the child parameter does exist in the parent parameters, overwrite the child parameter by the
// parent parameter.
StepWithMappingMeta.replaceVariableValues(transMeta, space);
if (isPassingAllParameters()) {
// All other parent parameters need to get copied into the child parameters (when the 'Inherit all
// variables from the transformation?' option is checked)
StepWithMappingMeta.addMissingVariables(transMeta, space);
}
// Pass repository and metastore references
//
transMeta.setRepository(rep);
transMeta.setMetaStore(metaStore);
}
return transMeta;
} catch (final KettleException ke) {
// if we get a KettleException, simply re-throw it
throw ke;
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(PKG, "JobTrans.Exception.MetaDataLoad"), e);
}
}
Aggregations