Search in sources :

Example 61 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)

Example 62 with RepositoryDirectory

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

the class JobExecutorMeta 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 executor job metadata...
        // 
        JobMeta executorJobMeta = loadJobMetaProxy(this, repository, space);
        // Also go down into the mapping transformation and export the files
        // there. (mapping recursively down)
        // 
        String proposedNewFilename = executorJobMeta.exportResources(executorJobMeta, 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.
        // 
        executorJobMeta.setFilename(newFilename);
        // exports always reside in the root directory, in case we want to turn
        // this into a file repository...
        // 
        executorJobMeta.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, "JobExecutorMeta.Exception.UnableToLoadJob", fileName));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException)

Aggregations

RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)62 KettleException (org.pentaho.di.core.exception.KettleException)23 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)18 Test (org.junit.Test)17 TransMeta (org.pentaho.di.trans.TransMeta)14 LongObjectId (org.pentaho.di.repository.LongObjectId)10 Repository (org.pentaho.di.repository.Repository)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 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)8 ArrayList (java.util.ArrayList)7 JobMeta (org.pentaho.di.job.JobMeta)7 StringObjectId (org.pentaho.di.repository.StringObjectId)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)6 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)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 FileObject (org.apache.commons.vfs2.FileObject)4