use of org.pentaho.di.repository.RepositoryObject in project pentaho-kettle by pentaho.
the class KettleFileRepository method getObjectInformation.
@Override
public RepositoryObject getObjectInformation(ObjectId objectId, RepositoryObjectType objectType) throws KettleException {
try {
String filename = calcDirectoryName(null);
if (objectId.getId().startsWith("/")) {
filename += objectId.getId().substring(1);
} else {
filename += objectId.getId();
}
FileObject fileObject = KettleVFS.getFileObject(filename);
if (!fileObject.exists()) {
return null;
}
FileName fname = fileObject.getName();
String name = fname.getBaseName();
if (!Utils.isEmpty(fname.getExtension()) && name.length() > fname.getExtension().length()) {
name = name.substring(0, name.length() - fname.getExtension().length() - 1);
}
String filePath = fileObject.getParent().getName().getPath();
final FileObject baseDirObject = KettleVFS.getFileObject(repositoryMeta.getBaseDirectory());
final int baseDirObjectPathLength = baseDirObject.getName().getPath().length();
final String dirPath = baseDirObjectPathLength <= filePath.length() ? filePath.substring(baseDirObjectPathLength) : "/";
RepositoryDirectoryInterface directory = loadRepositoryDirectoryTree().findDirectory(dirPath);
Date lastModified = new Date(fileObject.getContent().getLastModifiedTime());
return new RepositoryObject(objectId, name, directory, "-", lastModified, objectType, "", false);
} catch (Exception e) {
throw new KettleException("Unable to get object information for object with id=" + objectId, e);
}
}
use of org.pentaho.di.repository.RepositoryObject in project pentaho-kettle by pentaho.
the class KettleDatabaseRepository method getObjectInformation.
public RepositoryObject getObjectInformation(ObjectId objectId, RepositoryObjectType objectType) throws KettleException {
try {
String name, description, modifiedUser;
Date modifiedDate;
RepositoryDirectoryInterface directory;
long dirId;
switch(objectType) {
case TRANSFORMATION:
{
RowMetaAndData row = transDelegate.getTransformation(objectId);
name = row.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_NAME, null);
description = row.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_DESCRIPTION, null);
modifiedUser = row.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_USER, "-");
modifiedDate = row.getDate(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_DATE, null);
dirId = row.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DIRECTORY, 0);
break;
}
case JOB:
{
RowMetaAndData row = jobDelegate.getJob(objectId);
name = row.getString(KettleDatabaseRepository.FIELD_JOB_NAME, null);
description = row.getString(KettleDatabaseRepository.FIELD_JOB_DESCRIPTION, null);
modifiedUser = row.getString(KettleDatabaseRepository.FIELD_JOB_MODIFIED_USER, "-");
modifiedDate = row.getDate(KettleDatabaseRepository.FIELD_JOB_MODIFIED_DATE, null);
dirId = row.getInteger(KettleDatabaseRepository.FIELD_JOB_ID_DIRECTORY, 0);
break;
}
// PDI-15871 Return available information for DATABASE
case DATABASE:
{
RowMetaAndData row = databaseDelegate.getDatabase(objectId);
name = row.getString(KettleDatabaseRepository.FIELD_DATABASE_NAME, null);
return new RepositoryObject(objectId, name, null, null, null, objectType, null, false);
}
default:
throw new KettleException("Object type " + objectType.getTypeDescription() + " was specified. Only information from transformations, jobs and databases can be retrieved at this time.");
}
boolean isDeleted = (name == null);
directory = loadRepositoryDirectoryTree().findDirectory(new LongObjectId(dirId));
return new RepositoryObject(objectId, name, directory, modifiedUser, modifiedDate, objectType, description, isDeleted);
} catch (Exception e) {
throw new KettleException("Unable to get object information for object with id=" + objectId, e);
}
}
use of org.pentaho.di.repository.RepositoryObject in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConnectionDelegate method getRepositoryObjects.
/**
* @param id_directory
* @return A list of RepositoryObjects
*
* @throws KettleException
*/
public synchronized List<RepositoryElementMetaInterface> getRepositoryObjects(String tableName, RepositoryObjectType objectType, ObjectId id_directory) throws KettleException {
try {
String idField;
if (RepositoryObjectType.TRANSFORMATION.equals(objectType)) {
idField = KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_TRANSFORMATION;
} else {
idField = KettleDatabaseRepository.FIELD_JOB_ID_JOB;
}
if (id_directory == null) {
// root!
id_directory = new LongObjectId(0L);
}
RepositoryDirectoryInterface repositoryDirectory = repository.directoryDelegate.loadPathToRoot(id_directory);
// RepositoryDirectoryInterface repositoryDirectory =
// repository.loadRepositoryDirectoryTree().findDirectory(id_directory);
String sql = "SELECT " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_NAME) + ", " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_USER) + ", " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_DATE) + ", " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_DESCRIPTION) + ", " + quote(idField) + " " + "FROM " + tableName + " " + "WHERE " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DIRECTORY) + " = ? ";
RowMetaAndData directoryIdRow = getParameterMetaData(id_directory);
return callRead(new Callable<List<RepositoryElementMetaInterface>>() {
@Override
public List<RepositoryElementMetaInterface> call() throws Exception {
List<RepositoryElementMetaInterface> repositoryObjects = new ArrayList<RepositoryElementMetaInterface>();
ResultSet rs = database.openQuery(sql, directoryIdRow.getRowMeta(), directoryIdRow.getData());
if (rs != null) {
List<Object[]> rows = database.getRows(rs, -1, null);
if (rs != null) {
database.closeQuery(rs);
}
RowMetaInterface rowMeta = database.getReturnRowMeta();
for (Object[] r : rows) {
ObjectId id = new LongObjectId(rowMeta.getInteger(r, 4));
repositoryObjects.add(new RepositoryObject(id, rowMeta.getString(r, 0), repositoryDirectory, rowMeta.getString(r, 1), rowMeta.getDate(r, 2), objectType, rowMeta.getString(r, 3), false));
}
}
return repositoryObjects;
}
});
} catch (Exception e) {
throw new KettleException("Unable to get list of repository objects", e);
}
}
use of org.pentaho.di.repository.RepositoryObject in project pentaho-kettle by pentaho.
the class KettleDatabaseRepository_GetObjectInformation_Test method getObjectInformation_GetDatabaseInformation.
@Test
public void getObjectInformation_GetDatabaseInformation() throws Exception {
KettleDatabaseRepositoryDatabaseDelegate databaseDelegate = spy(new KettleDatabaseRepositoryDatabaseDelegate(repository));
repository.databaseDelegate = databaseDelegate;
RowMeta meta = createMetaForDatabase();
Object[] values = new Object[meta.size()];
values[Arrays.asList(meta.getFieldNames()).indexOf(KettleDatabaseRepositoryBase.FIELD_DATABASE_NAME)] = EXISTING_ID;
doReturn(new RowMetaAndData(meta, values)).when(databaseDelegate).getDatabase(new StringObjectId(EXISTING_ID));
RepositoryObject actual = repository.getObjectInformation(new StringObjectId(EXISTING_ID), RepositoryObjectType.DATABASE);
assertEquals(new StringObjectId(EXISTING_ID), actual.getObjectId());
assertEquals(EXISTING_ID, actual.getName());
assertEquals(RepositoryObjectType.DATABASE, actual.getObjectType());
}
use of org.pentaho.di.repository.RepositoryObject in project pentaho-kettle by pentaho.
the class KettleDatabaseRepository_GetObjectInformation_Test method assertIsDeletedSet_ForAbsentObject.
private void assertIsDeletedSet_ForAbsentObject(KettleDatabaseRepositoryTransDelegate transDelegate, KettleDatabaseRepositoryJobDelegate jobDelegate, RepositoryObjectType objectType) throws Exception {
repository.transDelegate = transDelegate;
repository.jobDelegate = jobDelegate;
when(directoryInterface.findDirectory(any(ObjectId.class))).thenReturn(null);
RepositoryObject object = repository.getObjectInformation(new StringObjectId(ABSENT_ID), objectType);
assertTrue(object.isDeleted());
}
Aggregations