Search in sources :

Example 11 with StringObjectId

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

the class KettleFileRepository method saveRepositoryDirectory.

@Override
public void saveRepositoryDirectory(RepositoryDirectoryInterface dir) throws KettleException {
    try {
        String filename = calcDirectoryName(dir);
        ObjectId objectId = new StringObjectId(calcRelativeElementDirectory(dir));
        FileObject fileObject = KettleVFS.getFileObject(filename);
        // also create parents
        fileObject.createFolder();
        dir.setObjectId(objectId);
        log.logDetailed("New id of directory = " + dir.getObjectId());
    } catch (Exception e) {
        throw new KettleException("Unable to save directory [" + dir + "] in the repository", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) FileObject(org.apache.commons.vfs2.FileObject) StringObjectId(org.pentaho.di.repository.StringObjectId) 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 12 with StringObjectId

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

the class KettleFileRepository method renameObject.

private ObjectId renameObject(ObjectId id, RepositoryDirectoryInterface newDirectory, String newName, String extension) throws KettleException {
    try {
        // In case of a root object, the ID is the same as the relative filename...
        // 
        FileObject fileObject = KettleVFS.getFileObject(calcDirectoryName(null) + id.getId());
        // Same name, different folder?
        if (Utils.isEmpty(newName)) {
            newName = calcObjectName(id);
        }
        // The new filename can be anywhere so we re-calculate a new ID...
        // 
        String newFilename = calcDirectoryName(newDirectory) + newName + extension;
        FileObject newObject = KettleVFS.getFileObject(newFilename);
        fileObject.moveTo(newObject);
        return new StringObjectId(calcObjectId(newDirectory, newName, extension));
    } catch (Exception e) {
        throw new KettleException("Unable to rename object with ID [" + id + "] to [" + newName + "]", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) FileObject(org.apache.commons.vfs2.FileObject) StringObjectId(org.pentaho.di.repository.StringObjectId) 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 13 with StringObjectId

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

the class KettleFileRepository method getJobObjects.

@Override
public List<RepositoryElementMetaInterface> getJobObjects(ObjectId id_directory, boolean includeDeleted) throws KettleException {
    try {
        List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();
        RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree();
        RepositoryDirectoryInterface directory = tree.findDirectory(id_directory);
        String folderName = calcDirectoryName(directory);
        FileObject folder = KettleVFS.getFileObject(folderName);
        for (FileObject child : folder.getChildren()) {
            if (child.getType().equals(FileType.FILE)) {
                if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) {
                    String name = child.getName().getBaseName();
                    if (name.endsWith(EXT_JOB)) {
                        String jobName = name.substring(0, name.length() - 4);
                        ObjectId id = new StringObjectId(calcObjectId(directory, jobName, EXT_JOB));
                        Date date = new Date(child.getContent().getLastModifiedTime());
                        list.add(new RepositoryObject(id, jobName, directory, "-", date, RepositoryObjectType.JOB, "", false));
                    }
                }
            }
        }
        return list;
    } catch (Exception e) {
        throw new KettleException("Unable to get list of jobs in folder with id : " + id_directory, e);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObject(org.pentaho.di.repository.RepositoryObject) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ArrayList(java.util.ArrayList) FileObject(org.apache.commons.vfs2.FileObject) StringObjectId(org.pentaho.di.repository.StringObjectId) 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) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 14 with StringObjectId

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

the class KettleFileRepository method save.

public void save(RepositoryElementInterface repositoryElement, String versionComment, ProgressMonitorListener monitor, ObjectId parentId, boolean used) throws KettleException {
    try {
        if (!(repositoryElement instanceof XMLInterface) && !(repositoryElement instanceof SharedObjectInterface)) {
            throw new KettleException("Class [" + repositoryElement.getClass().getName() + "] needs to implement the XML Interface in order to save it to disk");
        }
        if (!Utils.isEmpty(versionComment)) {
            insertLogEntry("Save repository element : " + repositoryElement.toString() + " : " + versionComment);
        }
        ObjectId objectId = new StringObjectId(calcObjectId(repositoryElement));
        FileObject fileObject = getFileObject(repositoryElement);
        String xml = ((XMLInterface) repositoryElement).getXML();
        OutputStream os = KettleVFS.getOutputStream(fileObject, false);
        os.write(xml.getBytes(Const.XML_ENCODING));
        os.close();
        if (repositoryElement instanceof ChangedFlagInterface) {
            ((ChangedFlagInterface) repositoryElement).clearChanged();
        }
        // 
        if (repositoryElement.getObjectId() != null && !repositoryElement.getObjectId().equals(objectId)) {
            delObject(repositoryElement.getObjectId());
        }
        repositoryElement.setObjectId(objectId);
        // 
        if (repositoryElement instanceof TransMeta) {
            ((TransMeta) repositoryElement).saveMetaStoreObjects(this, metaStore);
        }
        if (repositoryElement instanceof JobMeta) {
            ((JobMeta) repositoryElement).saveMetaStoreObjects(this, metaStore);
        }
    } catch (Exception e) {
        throw new KettleException("Unable to save repository element [" + repositoryElement + "] to XML file : " + calcFilename(repositoryElement), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ChangedFlagInterface(org.pentaho.di.core.changed.ChangedFlagInterface) OutputStream(java.io.OutputStream) TransMeta(org.pentaho.di.trans.TransMeta) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) FileObject(org.apache.commons.vfs2.FileObject) XMLInterface(org.pentaho.di.core.xml.XMLInterface) StringObjectId(org.pentaho.di.repository.StringObjectId) 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 15 with StringObjectId

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

the class KettleFileRepository method loadRepositoryDirectoryTree.

@Override
public RepositoryDirectoryInterface loadRepositoryDirectoryTree() throws KettleException {
    RepositoryDirectory root = new RepositoryDirectory();
    root.setObjectId(new StringObjectId("/"));
    return loadRepositoryDirectoryTree(root);
}
Also used : RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) StringObjectId(org.pentaho.di.repository.StringObjectId)

Aggregations

StringObjectId (org.pentaho.di.repository.StringObjectId)123 KettleException (org.pentaho.di.core.exception.KettleException)49 ObjectId (org.pentaho.di.repository.ObjectId)38 Test (org.junit.Test)34 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)25 KettleFileException (org.pentaho.di.core.exception.KettleFileException)21 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)18 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)18 ArrayList (java.util.ArrayList)16 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)15 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)14 RepositoryObject (org.pentaho.di.repository.RepositoryObject)14 TransMeta (org.pentaho.di.trans.TransMeta)14 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)13 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)13 UnifiedRepositoryCreateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException)13 UnifiedRepositoryUpdateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException)13 Repository (org.pentaho.di.repository.Repository)11 IOException (java.io.IOException)10 FileObject (org.apache.commons.vfs2.FileObject)10