Search in sources :

Example 1 with RepositoryFile

use of org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile in project pentaho-kettle by pentaho.

the class RepositoryFileProvider method loadDirectoryTree.

public RepositoryTree loadDirectoryTree() {
    if (getRepository() != null) {
        try {
            if (getRepository() instanceof RepositoryExtended) {
                rootDirectory = ((RepositoryExtended) getRepository()).loadRepositoryDirectoryTree(false);
            } else {
                rootDirectory = getRepository().loadRepositoryDirectoryTree();
            }
            RepositoryTree repositoryTree = new RepositoryTree(null);
            RepositoryDirectory repositoryDirectory = RepositoryDirectory.build(null, rootDirectory);
            populateFolders(repositoryDirectory, rootDirectory);
            boolean isPentahoRepository = getRepository().getRepositoryMeta().getId().equals(PENTAHO_ENTERPRISE_REPOSITORY);
            if (!isPentahoRepository) {
                populateFiles(repositoryDirectory, rootDirectory, FILTER);
            }
            for (RepositoryFile child : repositoryDirectory.getChildren()) {
                repositoryTree.addChild(child);
            }
            return repositoryTree;
        } catch (Exception e) {
            return null;
        }
    }
    return null;
}
Also used : RepositoryDirectory(org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryDirectory) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) RepositoryTree(org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryTree) RepositoryFile(org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile) KettleException(org.pentaho.di.core.exception.KettleException) InvalidFileTypeException(org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileTypeException) FileException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) KettleJobException(org.pentaho.di.core.exception.KettleJobException) InvalidFileOperationException(org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileOperationException) FileExistsException(org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException)

Example 2 with RepositoryFile

use of org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile in project pentaho-kettle by pentaho.

the class RepositoryFileProvider method doRename.

// TODO: Make this actually work
public RepositoryFile doRename(RepositoryFile file, String newName) throws KettleException {
    RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(file.getParent());
    ObjectId objectId = null;
    switch(file.getType()) {
        case JOB:
            if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.JOB)) {
                throw new KettleObjectExistsException();
            }
            if (isJobOpened(file.getObjectId(), file.getParent(), file.getName())) {
                throw new KettleJobException();
            }
            objectId = getRepository().renameJob(file::getObjectId, repositoryDirectoryInterface, newName);
            break;
        case TRANSFORMATION:
            if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.TRANSFORMATION)) {
                throw new KettleObjectExistsException();
            }
            if (isTransOpened(file.getObjectId(), file.getParent(), file.getName())) {
                throw new KettleJobException();
            }
            objectId = getRepository().renameTransformation(file::getObjectId, repositoryDirectoryInterface, newName);
            break;
        case FOLDER:
            isFileOpenedInFolder(file.getPath());
            RepositoryDirectoryInterface parent = findDirectory(file.getPath()).getParent();
            if (parent == null) {
                parent = findDirectory(file.getPath());
            }
            RepositoryDirectoryInterface child = parent.findChild(newName);
            if (child != null) {
                throw new KettleObjectExistsException();
            }
            if (getRepository() instanceof RepositoryExtended) {
                objectId = ((RepositoryExtended) getRepository()).renameRepositoryDirectory(file::getObjectId, null, newName, true);
            } else {
                objectId = getRepository().renameRepositoryDirectory(file::getObjectId, null, newName);
            }
            break;
    }
    RepositoryFile repositoryFile = new RepositoryFile();
    return repositoryFile;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) RepositoryFile(org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Example 3 with RepositoryFile

use of org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile in project pentaho-kettle by pentaho.

the class RepositoryFileProvider method populateFiles.

private void populateFiles(RepositoryDirectory repositoryDirectory, RepositoryDirectoryInterface repositoryDirectoryInterface, String filter) throws KettleException {
    if (getRepository() instanceof RepositoryExtended && !repositoryDirectory.getPath().equals("/")) {
        populateFilesLazy(repositoryDirectory, filter);
    } else {
        Date latestDate = null;
        for (RepositoryObjectInterface repositoryObject : getRepositoryElements(repositoryDirectoryInterface)) {
            org.pentaho.di.repository.RepositoryObject ro = (org.pentaho.di.repository.RepositoryObject) repositoryObject;
            String extension = ro.getObjectType().getExtension();
            if (!Util.isFiltered(extension, filter)) {
                RepositoryFile repositoryFile = RepositoryFile.build(ro);
                repositoryDirectory.addChild(repositoryFile);
            }
            if (latestDate == null || ro.getModifiedDate().after(latestDate)) {
                latestDate = ro.getModifiedDate();
            }
        }
        repositoryDirectory.setDate(latestDate);
    }
}
Also used : RepositoryObject(org.pentaho.di.repository.RepositoryObject) RepositoryObject(org.pentaho.di.repository.RepositoryObject) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) RepositoryFile(org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile) RepositoryObjectInterface(org.pentaho.di.repository.RepositoryObjectInterface) Date(java.util.Date)

Example 4 with RepositoryFile

use of org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile in project pentaho-kettle by pentaho.

the class RepositoryFileProvider method populateFilesLazy.

public void populateFilesLazy(RepositoryDirectory repositoryDirectory, String filter) {
    RepositoryRequest repositoryRequest = new RepositoryRequest();
    repositoryRequest.setPath(repositoryDirectory.getPath());
    repositoryRequest.setDepth(1);
    repositoryRequest.setShowHidden(true);
    repositoryRequest.setTypes(RepositoryRequest.FILES_TYPE_FILTER.FILES);
    repositoryRequest.setChildNodeFilter(filter);
    RepositoryFileTree tree = getRepository().getUnderlyingRepository().getTree(repositoryRequest);
    for (RepositoryFileTree repositoryFileTree : tree.getChildren()) {
        org.pentaho.platform.api.repository2.unified.RepositoryFile repositoryFile = repositoryFileTree.getFile();
        RepositoryFile repositoryFile1 = RepositoryFile.build(repositoryDirectory.getPath(), repositoryFile, isAdmin());
        repositoryDirectory.addChild(repositoryFile1);
    }
}
Also used : RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) RepositoryFile(org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree)

Example 5 with RepositoryFile

use of org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile in project pentaho-kettle by pentaho.

the class RepositoryFileProvider method copy.

@Override
public RepositoryFile copy(RepositoryFile file, String toPath, boolean overwrite) throws FileException {
    RepositoryElementInterface repositoryElementInterface = getObject(file.getObjectId(), file.getType());
    if (repositoryElementInterface != null) {
        repositoryElementInterface.setName(Util.getName(toPath));
        repositoryElementInterface.setObjectId(null);
        try {
            getRepository().save(repositoryElementInterface, null, null);
        } catch (KettleException e) {
        }
    } else {
        throw new InvalidFileOperationException();
    }
    RepositoryFile repositoryFile = new RepositoryFile();
    return repositoryFile;
}
Also used : RepositoryElementInterface(org.pentaho.di.repository.RepositoryElementInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryFile(org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile) InvalidFileOperationException(org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileOperationException)

Aggregations

RepositoryFile (org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile)7 RepositoryExtended (org.pentaho.di.repository.RepositoryExtended)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 KettleException (org.pentaho.di.core.exception.KettleException)2 KettleJobException (org.pentaho.di.core.exception.KettleJobException)2 KettleObjectExistsException (org.pentaho.di.core.exception.KettleObjectExistsException)2 InvalidFileOperationException (org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileOperationException)2 RepositoryDirectory (org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryDirectory)2 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)2 RepositoryObject (org.pentaho.di.repository.RepositoryObject)2 RepositoryObjectInterface (org.pentaho.di.repository.RepositoryObjectInterface)2 Calendar (java.util.Calendar)1 LastUsedFile (org.pentaho.di.core.LastUsedFile)1 KettleTransException (org.pentaho.di.core.exception.KettleTransException)1 FileException (org.pentaho.di.plugins.fileopensave.api.providers.exception.FileException)1 FileExistsException (org.pentaho.di.plugins.fileopensave.api.providers.exception.FileExistsException)1 InvalidFileTypeException (org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileTypeException)1 RepositoryTree (org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryTree)1 IUser (org.pentaho.di.repository.IUser)1