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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations