Search in sources :

Example 31 with RepositoryDirectory

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

the class KettleDatabaseRepository method getUserHomeDirectory.

public RepositoryDirectory getUserHomeDirectory() throws KettleException {
    RepositoryDirectory root = new RepositoryDirectory();
    root.setObjectId(new LongObjectId(0L));
    directoryDelegate.loadRepositoryDirectory(root, root.getObjectId());
    return root;
}
Also used : RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 32 with RepositoryDirectory

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

the class KettleDatabaseRepository method loadRepositoryDirectoryTree.

// Directory stuff
public RepositoryDirectoryInterface loadRepositoryDirectoryTree() throws KettleException {
    RepositoryDirectory root = new RepositoryDirectory();
    root.setObjectId(new LongObjectId(0L));
    return directoryDelegate.loadRepositoryDirectoryTree(root);
}
Also used : RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 33 with RepositoryDirectory

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

the class StepWithMappingMeta method exportResources.

@Override
public String exportResources(VariableSpace space, Map<String, ResourceDefinition> definitions, ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore) throws KettleException {
    try {
        // Try to load the transformation from repository or file.
        // Modify this recursively too...
        // 
        // NOTE: there is no need to clone this step because the caller is
        // responsible for this.
        // 
        // First load the mapping transformation...
        // 
        TransMeta mappingTransMeta = loadMappingMeta(this, repository, metaStore, space);
        // Also go down into the mapping transformation and export the files
        // there. (mapping recursively down)
        // 
        String proposedNewFilename = mappingTransMeta.exportResources(mappingTransMeta, definitions, resourceNamingInterface, repository, metaStore);
        // To get a relative path to it, we inject
        // ${Internal.Entry.Current.Directory}
        // 
        String newFilename = "${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}/" + proposedNewFilename;
        // Set the correct filename inside the XML.
        // 
        mappingTransMeta.setFilename(newFilename);
        // exports always reside in the root directory, in case we want to turn
        // this into a file repository...
        // 
        mappingTransMeta.setRepositoryDirectory(new RepositoryDirectory());
        // change it in the job entry
        // 
        fileName = newFilename;
        setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
        return proposedNewFilename;
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(PKG, "StepWithMappingMeta.Exception.UnableToLoadTrans", fileName));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) KettleException(org.pentaho.di.core.exception.KettleException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException)

Example 34 with RepositoryDirectory

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

the class KettleDatabaseRepositoryDirectoryDelegate method loadRepositoryDirectoryTree.

public RepositoryDirectoryInterface loadRepositoryDirectoryTree(RepositoryDirectoryInterface root) throws KettleException {
    try {
        synchronized (repository) {
            root.clear();
            ObjectId[] subids = repository.getSubDirectoryIDs(root.getObjectId());
            for (int i = 0; i < subids.length; i++) {
                RepositoryDirectory subdir = new RepositoryDirectory();
                loadRepositoryDirectory(subdir, subids[i]);
                root.addSubdirectory(subdir);
            }
        }
        return root;
    } catch (Exception e) {
        throw new KettleException("An error occured loading the directory tree from the repository", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) KettleException(org.pentaho.di.core.exception.KettleException)

Example 35 with RepositoryDirectory

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

the class KettleDatabaseRepositoryDirectoryDelegate method renameDirectory.

/**
 * Move / rename a directory in the repository
 *
 * @param id_directory
 *          Id of the directory to be moved/renamed
 * @param id_directory_parent
 *          Id of the new parent directory (null if the parent does not change)
 * @param newName
 *          New name for this directory (null if the name does not change)
 * @throws KettleException
 */
public synchronized void renameDirectory(ObjectId id_directory, ObjectId id_directory_parent, String newName) throws KettleException {
    if (id_directory.equals(id_directory_parent)) {
        // Make sure the directory cannot become its own parent
        throw new KettleException("Failed to copy directory into itself");
    } else {
        // Make sure the directory does not become a descendant of itself
        RepositoryDirectory rd = new RepositoryDirectory();
        loadRepositoryDirectory(rd, id_directory);
        if (rd.findDirectory(id_directory_parent) != null) {
            // The parent directory is a child of this directory. Do not proceed
            throw new KettleException("Directory cannot become a child to itself");
        } else {
            // Check for duplication
            RepositoryDirectory newParent = new RepositoryDirectory();
            loadRepositoryDirectory(newParent, id_directory_parent);
            RepositoryDirectory child = newParent.findChild(newName == null ? rd.getName() : newName);
            if (child != null) {
                throw new KettleException("Destination directory already contains a diectory with requested name");
            }
        }
    }
    if (id_directory_parent != null || newName != null) {
        RowMetaAndData r = new RowMetaAndData();
        String sql = "UPDATE " + quoteTable(KettleDatabaseRepository.TABLE_R_DIRECTORY) + " SET ";
        boolean additionalParameter = false;
        if (newName != null) {
            additionalParameter = true;
            sql += quote(KettleDatabaseRepository.FIELD_DIRECTORY_DIRECTORY_NAME) + " = ?";
            r.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DIRECTORY_DIRECTORY_NAME), newName);
        }
        if (id_directory_parent != null) {
            // Add a parameter separator if the first parm was added
            if (additionalParameter) {
                sql += ", ";
            }
            sql += quote(KettleDatabaseRepository.FIELD_DIRECTORY_ID_DIRECTORY_PARENT) + " = ?";
            r.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DIRECTORY_ID_DIRECTORY_PARENT), id_directory_parent);
        }
        sql += " WHERE " + quote(KettleDatabaseRepository.FIELD_DIRECTORY_ID_DIRECTORY) + " = ? ";
        r.addValue(new ValueMetaInteger("id_directory"), Long.valueOf(id_directory.toString()));
        repository.connectionDelegate.getDatabase().execStatement(sql, r.getRowMeta(), r.getData());
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Aggregations

RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)57 KettleException (org.pentaho.di.core.exception.KettleException)23 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)15 Test (org.junit.Test)14 TransMeta (org.pentaho.di.trans.TransMeta)11 LongObjectId (org.pentaho.di.repository.LongObjectId)10 ObjectId (org.pentaho.di.repository.ObjectId)9 KettleFileException (org.pentaho.di.core.exception.KettleFileException)8 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)8 Repository (org.pentaho.di.repository.Repository)8 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)8 ArrayList (java.util.ArrayList)7 StringObjectId (org.pentaho.di.repository.StringObjectId)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)6 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)6 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)6 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)6 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 JobMeta (org.pentaho.di.job.JobMeta)5 TreeItem (org.eclipse.swt.widgets.TreeItem)4