use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class TransMetaConverterTest method testIncludesSubTransformationsFromRepository.
@Test
public void testIncludesSubTransformationsFromRepository() throws Exception {
TransMeta parentTransMeta = new TransMeta(getClass().getResource("trans-meta-converter-parent.ktr").getPath());
Repository repository = mock(Repository.class);
TransMeta transMeta = new TransMeta();
RepositoryDirectoryInterface repositoryDirectory = new RepositoryDirectory(null, "public");
String directory = getClass().getResource("").toString().replace(File.separator, "/");
when(repository.findDirectory("public")).thenReturn(repositoryDirectory);
when(repository.loadTransformation("trans-meta-converter-sub.ktr", repositoryDirectory, null, true, null)).thenReturn(transMeta);
parentTransMeta.setRepository(repository);
parentTransMeta.setRepositoryDirectory(repositoryDirectory);
parentTransMeta.setVariable("Internal.Entry.Current.Directory", "public");
Transformation transformation = TransMetaConverter.convert(parentTransMeta);
@SuppressWarnings({ "unchecked", "ConstantConditions" }) HashMap<String, Transformation> config = (HashMap<String, Transformation>) transformation.getConfig(TransMetaConverter.SUB_TRANSFORMATIONS_KEY).get();
assertEquals(1, config.size());
assertNotNull(config.get("public/trans-meta-converter-sub.ktr"));
}
use of org.pentaho.di.repository.RepositoryDirectory in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceReferenceSynchronizerTest method before.
@Before
public void before() {
ObjectId transId = new StringObjectId("transId");
when(transMeta.getMetaStore()).thenReturn(externalMetastore);
when(transMeta.getEmbeddedMetaStore()).thenReturn(embeddedMetastore);
when(transMeta.getObjectId()).thenReturn(transId);
when(transMeta.getRepository()).thenReturn(repository);
when(repository.getRepositoryMeta()).thenReturn(repositoryMeta);
when(repositoryMeta.getRepositoryCapabilities()).thenReturn(mock(RepositoryCapabilities.class));
RepositoryDirectoryInterface root = mock(RepositoryDirectoryInterface.class);
RepositoryDirectoryInterface dir = new RepositoryDirectory(root, "location");
when(root.findDirectory(eq("/"))).thenReturn(dir);
try {
when(repository.getTransformationID(eq("location"), eq(dir))).thenReturn(transId);
when(repository.loadRepositoryDirectoryTree()).thenReturn(root);
} catch (KettleException ke) {
// Noop
}
when(context.getPushDownFactories()).thenReturn(Collections.emptyList());
synchronizer = new DataServiceReferenceSynchronizer(context) {
protected <T> MetaStoreFactory<T> getMetastoreFactory(IMetaStore metaStore, Class<T> clazz) {
return externalMetaStoreFactory;
}
protected MetaStoreFactory<DataServiceMeta> getEmbeddedMetaStoreFactory(TransMeta meta) {
return embeddedMetaStoreFactory;
}
};
}
use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class JobExecutorMeta method exportResources.
@Override
public String exportResources(VariableSpace space, Map<String, ResourceDefinition> definitions, ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore) throws KettleException {
try {
// Try to load the transformation from repository or file.
// Modify this recursively too...
//
// NOTE: there is no need to clone this step because the caller is
// responsible for this.
//
// First load the executor job metadata...
//
JobMeta executorJobMeta = loadJobMetaProxy(this, repository, space);
// Also go down into the mapping transformation and export the files
// there. (mapping recursively down)
//
String proposedNewFilename = executorJobMeta.exportResources(executorJobMeta, definitions, resourceNamingInterface, repository, metaStore);
// To get a relative path to it, we inject
// ${Internal.Entry.Current.Directory}
//
String newFilename = "${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}/" + proposedNewFilename;
// Set the correct filename inside the XML.
//
executorJobMeta.setFilename(newFilename);
// exports always reside in the root directory, in case we want to turn
// this into a file repository...
//
executorJobMeta.setRepositoryDirectory(new RepositoryDirectory());
// change it in the job entry
//
fileName = newFilename;
setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
return proposedNewFilename;
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(PKG, "JobExecutorMeta.Exception.UnableToLoadJob", fileName));
}
}
use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class KettleFileRepository method createRepositoryDirectory.
@Override
public RepositoryDirectoryInterface createRepositoryDirectory(RepositoryDirectoryInterface parentDirectory, String directoryPath) throws KettleException {
String folder = calcDirectoryName(parentDirectory);
String newFolder = folder;
if (folder.endsWith("/")) {
newFolder += directoryPath;
} else {
newFolder += "/" + directoryPath;
}
FileObject parent = KettleVFS.getFileObject(newFolder);
try {
parent.createFolder();
} catch (FileSystemException e) {
throw new KettleException("Unable to create folder " + newFolder, e);
}
// Incremental change of the directory structure...
//
RepositoryDirectory newDir = new RepositoryDirectory(parentDirectory, directoryPath);
parentDirectory.addSubdirectory(newDir);
newDir.setObjectId(new StringObjectId(calcObjectId(newDir)));
return newDir;
}
use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class KettleFileRepository method loadRepositoryDirectoryTree.
public RepositoryDirectoryInterface loadRepositoryDirectoryTree(RepositoryDirectoryInterface dir) throws KettleException {
try {
String folderName = calcDirectoryName(dir);
FileObject folder = KettleVFS.getFileObject(folderName);
for (FileObject child : folder.getChildren()) {
if (child.getType().equals(FileType.FOLDER)) {
if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) {
if (!".meta".equals(child.getName().getBaseName())) {
RepositoryDirectory subDir = new RepositoryDirectory(dir, child.getName().getBaseName());
subDir.setObjectId(new StringObjectId(calcObjectId(subDir)));
dir.addSubdirectory(subDir);
loadRepositoryDirectoryTree(subDir);
}
}
}
}
return dir;
} catch (Exception e) {
throw new KettleException("Unable to load the directory tree from this file repository", e);
}
}
Aggregations