Search in sources :

Example 26 with RepositoryObject

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);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObject(org.pentaho.di.repository.RepositoryObject) FileName(org.apache.commons.vfs2.FileName) FileObject(org.apache.commons.vfs2.FileObject) Date(java.util.Date) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException)

Example 27 with RepositoryObject

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);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RepositoryObject(org.pentaho.di.repository.RepositoryObject) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId) Date(java.util.Date) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) KettleDependencyException(org.pentaho.di.core.exception.KettleDependencyException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) IOException(java.io.IOException)

Example 28 with RepositoryObject

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);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObject(org.pentaho.di.repository.RepositoryObject) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) RepositoryObject(org.pentaho.di.repository.RepositoryObject) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 29 with RepositoryObject

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());
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RepositoryObject(org.pentaho.di.repository.RepositoryObject) RowMeta(org.pentaho.di.core.row.RowMeta) KettleDatabaseRepositoryDatabaseDelegate(org.pentaho.di.repository.kdr.delegates.KettleDatabaseRepositoryDatabaseDelegate) RepositoryObject(org.pentaho.di.repository.RepositoryObject) StringObjectId(org.pentaho.di.repository.StringObjectId) Test(org.junit.Test)

Example 30 with RepositoryObject

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());
}
Also used : RepositoryObject(org.pentaho.di.repository.RepositoryObject) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId)

Aggregations

RepositoryObject (org.pentaho.di.repository.RepositoryObject)46 KettleException (org.pentaho.di.core.exception.KettleException)31 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)15 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)11 StringObjectId (org.pentaho.di.repository.StringObjectId)9 ObjectId (org.pentaho.di.repository.ObjectId)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 Test (org.junit.Test)6 KettleFileException (org.pentaho.di.core.exception.KettleFileException)5 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)5 IOException (java.io.IOException)4 FileSystemException (org.apache.commons.vfs2.FileSystemException)4 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)4 FileDialogOperation (org.pentaho.di.ui.core.FileDialogOperation)4 FileObject (org.apache.commons.vfs2.FileObject)3 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 RepositoryObjectInterface (org.pentaho.di.repository.RepositoryObjectInterface)3 Serializable (java.io.Serializable)2 List (java.util.List)2