use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class TransMetaTest method testCompare.
@Test
public void testCompare() throws Exception {
TransMeta transMeta = new TransMeta("aFile", "aName");
TransMeta transMeta2 = new TransMeta("aFile", "aName");
assertEquals(0, transMeta.compare(transMeta, transMeta2));
transMeta2.setVariable("myVariable", "myValue");
assertEquals(0, transMeta.compare(transMeta, transMeta2));
transMeta2.setFilename(null);
assertEquals(1, transMeta.compare(transMeta, transMeta2));
assertEquals(-1, transMeta.compare(transMeta2, transMeta));
transMeta2.setFilename("aFile");
transMeta2.setName(null);
assertEquals(1, transMeta.compare(transMeta, transMeta2));
assertEquals(-1, transMeta.compare(transMeta2, transMeta));
transMeta2.setFilename("aFile2");
transMeta2.setName("aName");
assertEquals(-1, transMeta.compare(transMeta, transMeta2));
assertEquals(1, transMeta.compare(transMeta2, transMeta));
transMeta2.setFilename("aFile");
transMeta2.setName("aName2");
assertEquals(-1, transMeta.compare(transMeta, transMeta2));
assertEquals(1, transMeta.compare(transMeta2, transMeta));
transMeta.setFilename(null);
transMeta2.setFilename(null);
transMeta2.setName("aName");
assertEquals(0, transMeta.compare(transMeta, transMeta2));
RepositoryDirectoryInterface path1 = mock(RepositoryDirectoryInterface.class);
transMeta.setRepositoryDirectory(path1);
when(path1.getPath()).thenReturn("aPath2");
RepositoryDirectoryInterface path2 = mock(RepositoryDirectoryInterface.class);
when(path2.getPath()).thenReturn("aPath");
transMeta2.setRepositoryDirectory(path2);
assertEquals(1, transMeta.compare(transMeta, transMeta2));
assertEquals(-1, transMeta.compare(transMeta2, transMeta));
when(path1.getPath()).thenReturn("aPath");
assertEquals(0, transMeta.compare(transMeta, transMeta2));
ObjectRevision revision2 = mock(ObjectRevision.class);
transMeta2.setObjectRevision(revision2);
assertEquals(-1, transMeta.compare(transMeta, transMeta2));
assertEquals(1, transMeta.compare(transMeta2, transMeta));
ObjectRevision revision1 = mock(ObjectRevision.class);
transMeta.setObjectRevision(revision1);
when(revision1.getName()).thenReturn("aRevision");
when(revision2.getName()).thenReturn("aRevision");
assertEquals(0, transMeta.compare(transMeta, transMeta2));
when(revision2.getName()).thenReturn("aRevision2");
assertEquals(-1, transMeta.compare(transMeta, transMeta2));
assertEquals(1, transMeta.compare(transMeta2, transMeta));
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface 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.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class JobMetaTest method testEquals_sameNameOtherDir.
@Test
public void testEquals_sameNameOtherDir() {
RepositoryDirectoryInterface otherDirectory = mock(RepositoryDirectoryInterface.class);
when(otherDirectory.getPath()).thenReturn("otherDirectoryPath");
assertFalse(testEquals(JOB_META_NAME, otherDirectory, null, null));
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class RepositoryBrowserController method hasDupeFile.
/**
* Checks if there is a duplicate file in a given directory (i.e. hidden file)
* @param path - Path to directory in which we are saving
* @param name - Name of file to save
* @param fileName - Possible duplicate file name
* @param override - True is user wants override file, false otherwise
* @return - true if a duplicate file is found, false otherwise
*/
private boolean hasDupeFile(String path, String name, String fileName, boolean override) {
try {
RepositoryDirectoryInterface repositoryDirectoryInterface = getRepository().findDirectory(path);
EngineMetaInterface meta = getSpoon().getActiveMeta();
RepositoryObjectType type = "Trans".equals(meta.getFileType()) ? RepositoryObjectType.TRANSFORMATION : RepositoryObjectType.JOB;
if (getRepository().exists(name, repositoryDirectoryInterface, type)) {
return !override || !name.equals(fileName);
}
} catch (Exception e) {
System.out.println(e);
}
return false;
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class RepositoryBrowserController method rename.
public ObjectId rename(String id, String path, String newName, String type, String oldName) throws KettleException {
RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(path);
ObjectId objectId = null;
switch(type) {
case JOB:
if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.JOB)) {
throw new KettleObjectExistsException();
}
if (isJobOpened(id, path, oldName)) {
throw new KettleJobException();
}
renameRecent(id, type, newName);
objectId = getRepository().renameJob(() -> id, repositoryDirectoryInterface, newName);
break;
case TRANSFORMATION:
if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.TRANSFORMATION)) {
throw new KettleObjectExistsException();
}
if (isTransOpened(id, path, oldName)) {
throw new KettleTransException();
}
renameRecent(id, type, newName);
objectId = getRepository().renameTransformation(() -> id, repositoryDirectoryInterface, newName);
break;
case FOLDER:
isFileOpenedInFolder(path);
RepositoryDirectoryInterface parent = findDirectory(path).getParent();
if (parent == null) {
parent = findDirectory(path);
}
RepositoryDirectoryInterface child = parent.findChild(newName);
if (child != null) {
throw new KettleObjectExistsException();
}
if (getRepository() instanceof RepositoryExtended) {
objectId = ((RepositoryExtended) getRepository()).renameRepositoryDirectory(() -> id, null, newName, true);
} else {
objectId = getRepository().renameRepositoryDirectory(() -> id, null, newName);
}
break;
}
return objectId;
}
Aggregations