Search in sources :

Example 56 with RepositoryDirectoryInterface

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));
}
Also used : ObjectRevision(org.pentaho.di.repository.ObjectRevision) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Test(org.junit.Test)

Example 57 with RepositoryDirectoryInterface

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"));
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Repository(org.pentaho.di.repository.Repository) Transformation(org.pentaho.di.engine.api.model.Transformation) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) HashMap(java.util.HashMap) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Test(org.junit.Test)

Example 58 with RepositoryDirectoryInterface

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));
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Test(org.junit.Test)

Example 59 with RepositoryDirectoryInterface

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;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) EngineMetaInterface(org.pentaho.di.core.EngineMetaInterface) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) KettleException(org.pentaho.di.core.exception.KettleException) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Example 60 with RepositoryDirectoryInterface

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;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) ObjectId(org.pentaho.di.repository.ObjectId) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Aggregations

RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)163 KettleException (org.pentaho.di.core.exception.KettleException)68 Test (org.junit.Test)32 TransMeta (org.pentaho.di.trans.TransMeta)30 ObjectId (org.pentaho.di.repository.ObjectId)27 JobMeta (org.pentaho.di.job.JobMeta)23 Repository (org.pentaho.di.repository.Repository)22 ArrayList (java.util.ArrayList)17 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)17 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)15 IOException (java.io.IOException)14 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)13 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)11 RepositoryObject (org.pentaho.di.repository.RepositoryObject)11 FileObject (org.apache.commons.vfs2.FileObject)10 List (java.util.List)8 TreeItem (org.eclipse.swt.widgets.TreeItem)8 KettleFileException (org.pentaho.di.core.exception.KettleFileException)8 Date (java.util.Date)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)7