use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class UIEEJobTest method testRename.
@Test
public void testRename() throws Exception {
final String newName = "newName";
RepositoryDirectory repDir = mock(RepositoryDirectory.class);
uiJob.renameJob(mockObjectId, repDir, newName);
verify(mockRevisionService, times(1)).getRevisions(mockObjectId);
}
use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class Spoon method getDefaultSaveLocation.
public RepositoryDirectoryInterface getDefaultSaveLocation(RepositoryElementInterface repositoryElement) {
try {
if (getRepository() != defaultSaveLocationRepository) {
// The repository has changed, reset the defaultSaveLocation
defaultSaveLocation = null;
defaultSaveLocationRepository = null;
}
if (defaultSaveLocation == null) {
if (getRepository() != null) {
defaultSaveLocation = getRepository().getDefaultSaveDirectory(repositoryElement);
defaultSaveLocationRepository = getRepository();
} else {
defaultSaveLocation = new RepositoryDirectory();
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return defaultSaveLocation;
}
use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class MetaInject method writeInjectedKtrToRepo.
/**
* Writes the generated meta injection transformation to the repository. It is assumed that the repository
* exists (user is connected).
* @param targetFilePath the repo path to which to save the generated injection ktr
* @throws KettleException
*/
private void writeInjectedKtrToRepo(final String targetFilePath) throws KettleException {
// clone the transMeta associated with the data, this is the generated meta injection transformation
final TransMeta generatedTrans = (TransMeta) data.transMeta.clone();
// the targetFilePath holds the absolute repo path that is the requested destination of this generated
// transformation, extract the file name (no extension) and the containing directory and adjust the generated
// transformation properties accordingly
List<String> targetPath = new ArrayList(Arrays.asList(Const.splitPath(targetFilePath, RepositoryDirectory.DIRECTORY_SEPARATOR)));
final String fileName = targetPath.get(targetPath.size() - 1).replace(".ktr", "");
generatedTrans.setName(fileName);
// remove the last targetPath element, so we're left with the target directory path
targetPath.remove(targetPath.size() - 1);
if (targetPath.size() > 0) {
final String dirPath = String.join(RepositoryDirectory.DIRECTORY_SEPARATOR, targetPath);
RepositoryDirectoryInterface directory = getRepository().findDirectory(dirPath);
// if the directory does not exist, try to create it
if (directory == null) {
directory = getRepository().createRepositoryDirectory(new RepositoryDirectory(null, "/"), dirPath);
}
generatedTrans.setRepositoryDirectory(directory);
} else {
// if the directory is null, set it to the directory of the cloned template ktr
if (log.isDebug()) {
log.logDebug("The target injection ktr file path provided by the user is not a valid fully qualified " + "repository path - will store the generated ktr in the same directory as the template ktr: ", data.transMeta.getRepositoryDirectory());
}
generatedTrans.setRepositoryDirectory(data.transMeta.getRepositoryDirectory());
}
// set the objectId, in case the injected transformation already exists in the repo, so that is is updated in
// the repository - the objectId will remain null, if the transformation is begin generated for the first time,
// in which a new ktr will be created in the repo
generatedTrans.setObjectId(getRepository().getTransformationID(fileName, generatedTrans.getRepositoryDirectory()));
getRepository().save(generatedTrans, null, null, true);
}
use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class MetaInjectTest method testWriteInjectedKtrToRepoSameDir.
@Test
public void testWriteInjectedKtrToRepoSameDir() throws Exception {
RepositoryDirectory rootDir = PowerMockito.spy(new RepositoryDirectory(null, "/"));
RepositoryDirectory adminDir = PowerMockito.spy(new RepositoryDirectory(new RepositoryDirectory(new RepositoryDirectory(null, "/"), "home"), "admin"));
TransMeta cloneMeta = PowerMockito.spy((TransMeta) data.transMeta.clone());
PowerMockito.doReturn(cloneMeta).when(data.transMeta).clone();
PowerMockito.doReturn(adminDir).when(repository).createRepositoryDirectory(rootDir, "home/admin");
PowerMockito.doReturn(adminDir).when(data.transMeta).getRepositoryDirectory();
PowerMockito.whenNew(RepositoryDirectory.class).withArguments(null, "/").thenReturn(rootDir);
metaInject.setRepository(repository);
Whitebox.<String>invokeMethod(metaInject, "writeInjectedKtrToRepo", "/home/admin/injected_trans.ktr");
verify(repository, times(1)).findDirectory("home/admin");
verify(repository, times(1)).createRepositoryDirectory(rootDir, "home/admin");
verify(cloneMeta, times(1)).setRepositoryDirectory(adminDir);
verify(cloneMeta, times(1)).setObjectId(any(ObjectId.class));
verify(repository, times(1)).save(cloneMeta, null, null, true);
}
use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.
the class PurRepository method getPdiObjects.
protected List<RepositoryElementMetaInterface> getPdiObjects(ObjectId dirId, List<RepositoryObjectType> objectTypes, boolean includeDeleted) throws KettleException {
try {
// RepositoryDirectoryInterface repDir = getRootDir().findDirectory( dirId );
RepositoryFile dirFile = pur.getFileById(dirId.getId());
RepositoryDirectory repDir = new RepositoryDirectory();
repDir.setObjectId(dirId);
repDir.setName(dirFile.getName());
List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();
List<RepositoryFile> nonDeletedChildren = getAllFilesOfType(dirId, objectTypes);
for (RepositoryFile file : nonDeletedChildren) {
RepositoryLock lock = unifiedRepositoryLockService.getLock(file);
RepositoryObjectType objectType = getObjectType(file.getName());
list.add(new EERepositoryObject(file, repDir, null, objectType, null, lock, false));
}
if (includeDeleted) {
String dirPath = null;
if (dirId != null) {
// derive path using id
dirPath = pur.getFileById(dirId.getId()).getPath();
}
List<RepositoryFile> deletedChildren = getAllDeletedFilesOfType(dirPath, objectTypes);
for (RepositoryFile file : deletedChildren) {
RepositoryLock lock = unifiedRepositoryLockService.getLock(file);
RepositoryObjectType objectType = getObjectType(file.getName());
list.add(new EERepositoryObject(file, repDir, null, objectType, null, lock, true));
}
}
return list;
} catch (Exception e) {
throw new KettleException("Unable to get list of objects from directory [" + dirId + "]", e);
}
}
Aggregations