Search in sources :

Example 51 with ObjectId

use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.

the class RepositoryFileProvider method doRename.

// TODO: Make this actually work
public RepositoryFile doRename(RepositoryFile file, String newName) throws KettleException {
    RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(file.getParent());
    ObjectId objectId = null;
    switch(file.getType()) {
        case JOB:
            if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.JOB)) {
                throw new KettleObjectExistsException();
            }
            if (isJobOpened(file.getObjectId(), file.getParent(), file.getName())) {
                throw new KettleJobException();
            }
            objectId = getRepository().renameJob(file::getObjectId, repositoryDirectoryInterface, newName);
            break;
        case TRANSFORMATION:
            if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.TRANSFORMATION)) {
                throw new KettleObjectExistsException();
            }
            if (isTransOpened(file.getObjectId(), file.getParent(), file.getName())) {
                throw new KettleJobException();
            }
            objectId = getRepository().renameTransformation(file::getObjectId, repositoryDirectoryInterface, newName);
            break;
        case FOLDER:
            isFileOpenedInFolder(file.getPath());
            RepositoryDirectoryInterface parent = findDirectory(file.getPath()).getParent();
            if (parent == null) {
                parent = findDirectory(file.getPath());
            }
            RepositoryDirectoryInterface child = parent.findChild(newName);
            if (child != null) {
                throw new KettleObjectExistsException();
            }
            if (getRepository() instanceof RepositoryExtended) {
                objectId = ((RepositoryExtended) getRepository()).renameRepositoryDirectory(file::getObjectId, null, newName, true);
            } else {
                objectId = getRepository().renameRepositoryDirectory(file::getObjectId, null, newName);
            }
            break;
    }
    RepositoryFile repositoryFile = new RepositoryFile();
    return repositoryFile;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) RepositoryFile(org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Example 52 with ObjectId

use of org.pentaho.di.repository.ObjectId 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)

Example 53 with ObjectId

use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.

the class KettleFileRepository_DatabaseNames_Test method getDatabaseId_InsensitiveMatch.

@Test
public void getDatabaseId_InsensitiveMatch() throws Exception {
    final String name = "databaseWithCamelCase";
    final String lookupName = name.toLowerCase();
    assertNotSame(lookupName, name);
    DatabaseMeta db = saveDatabase(name);
    ObjectId id = repository.getDatabaseID(lookupName);
    assertEquals(db.getObjectId(), id);
}
Also used : ObjectId(org.pentaho.di.repository.ObjectId) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 54 with ObjectId

use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.

the class KettleFileRepository_DatabaseNames_Test method getDatabaseId_ExactMatch.

@Test
public void getDatabaseId_ExactMatch() throws Exception {
    final String name = UUID.randomUUID().toString();
    DatabaseMeta db = saveDatabase(name);
    ObjectId id = repository.getDatabaseID(name);
    assertEquals(db.getObjectId(), id);
}
Also used : ObjectId(org.pentaho.di.repository.ObjectId) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 55 with ObjectId

use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryTest method testInsertTransformationSlave.

@Test
public void testInsertTransformationSlave() throws KettleException {
    ArgumentCaptor<String> argumentTableName = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<RowMetaAndData> argumentTableData = ArgumentCaptor.forClass(RowMetaAndData.class);
    doNothing().when(repo.connectionDelegate).insertTableRow(argumentTableName.capture(), argumentTableData.capture());
    doReturn(new LongObjectId(789)).when(repo.connectionDelegate).getNextTransformationSlaveID();
    ObjectId result = repo.insertTransformationSlave(new LongObjectId(456), new LongObjectId(123));
    RowMetaAndData insertRecord = argumentTableData.getValue();
    assertEquals(KettleDatabaseRepository.TABLE_R_TRANS_SLAVE, argumentTableName.getValue());
    assertEquals(3, insertRecord.size());
    assertEquals(ValueMetaInterface.TYPE_INTEGER, insertRecord.getValueMeta(0).getType());
    assertEquals(KettleDatabaseRepository.FIELD_TRANS_SLAVE_ID_TRANS_SLAVE, insertRecord.getValueMeta(0).getName());
    assertEquals(Long.valueOf(789), insertRecord.getInteger(0));
    assertEquals(ValueMetaInterface.TYPE_INTEGER, insertRecord.getValueMeta(1).getType());
    assertEquals(KettleDatabaseRepository.FIELD_TRANS_SLAVE_ID_TRANSFORMATION, insertRecord.getValueMeta(1).getName());
    assertEquals(Long.valueOf(456), insertRecord.getInteger(1));
    assertEquals(ValueMetaInterface.TYPE_INTEGER, insertRecord.getValueMeta(2).getType());
    assertEquals(KettleDatabaseRepository.FIELD_TRANS_SLAVE_ID_SLAVE, insertRecord.getValueMeta(2).getName());
    assertEquals(Long.valueOf(123), insertRecord.getInteger(2));
    assertEquals(new LongObjectId(789), result);
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) Matchers.anyString(org.mockito.Matchers.anyString) LongObjectId(org.pentaho.di.repository.LongObjectId) Test(org.junit.Test)

Aggregations

ObjectId (org.pentaho.di.repository.ObjectId)233 KettleException (org.pentaho.di.core.exception.KettleException)94 LongObjectId (org.pentaho.di.repository.LongObjectId)76 StringObjectId (org.pentaho.di.repository.StringObjectId)76 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)49 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)38 Test (org.junit.Test)37 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)37 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)34 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)33 ArrayList (java.util.ArrayList)30 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)29 MessageBox (org.eclipse.swt.widgets.MessageBox)26 Repository (org.pentaho.di.repository.Repository)18 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)18 SlaveServer (org.pentaho.di.cluster.SlaveServer)15 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)14 PartitionSchema (org.pentaho.di.partition.PartitionSchema)14 Matchers.anyString (org.mockito.Matchers.anyString)13 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)13