Search in sources :

Example 6 with RepositoryFile

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

the class RepositoryBrowserController method getRecentFiles.

public List<RepositoryFile> getRecentFiles() {
    if (spoonSupplier.get().rep == null) {
        return Collections.emptyList();
    }
    PropsUI props = PropsUI.getInstance();
    List<RepositoryFile> repositoryFiles = new ArrayList<>();
    IUser userInfo = spoonSupplier.get().rep.getUserInfo();
    String repoAndUser = spoonSupplier.get().rep.getName() + ":" + (userInfo != null ? userInfo.getLogin() : "");
    List<LastUsedFile> lastUsedFiles = props.getLastUsedRepoFiles().getOrDefault(repoAndUser, Collections.emptyList());
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -30);
    Date dateBefore = calendar.getTime();
    for (int i = 0; i < lastUsedFiles.size(); i++) {
        LastUsedFile lastUsedFile = lastUsedFiles.get(i);
        if (lastUsedFile.getLastOpened().before(dateBefore)) {
            continue;
        }
        if (lastUsedFile.getRepositoryName() != null && lastUsedFile.getRepositoryName().equals(Spoon.getInstance().rep.getName())) {
            RepositoryFile repositoryFile = new RepositoryFile();
            final String index = String.valueOf(i);
            repositoryFile.setObjectId(index);
            repositoryFile.setType(lastUsedFile.isTransformation() ? TRANSFORMATION : JOB);
            repositoryFile.setName(lastUsedFile.getFilename());
            repositoryFile.setPath(lastUsedFile.getDirectory());
            repositoryFile.setDate(lastUsedFile.getLastOpened());
            repositoryFile.setRepository(lastUsedFile.getRepositoryName());
            repositoryFile.setUsername(lastUsedFile.getUsername());
            repositoryFiles.add(repositoryFile);
        }
    }
    return repositoryFiles;
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) IUser(org.pentaho.di.repository.IUser) RepositoryFile(org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile) LastUsedFile(org.pentaho.di.core.LastUsedFile) Date(java.util.Date) PropsUI(org.pentaho.di.ui.core.PropsUI)

Example 7 with RepositoryFile

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

the class RepositoryBrowserController method search.

public List<org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryObject> search(String path, String filter) {
    RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(path);
    List<org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryObject> repositoryObjects = new ArrayList<>();
    List<RepositoryObjectInterface> repositoryObjects1 = ((RepositoryExtended) getRepository()).getChildren(repositoryDirectoryInterface.getObjectId().getId(), filter);
    for (RepositoryObjectInterface repositoryObject : repositoryObjects1) {
        if (repositoryObject instanceof RepositoryDirectoryInterface) {
            RepositoryDirectory repositoryDirectory = new RepositoryDirectory();
            repositoryDirectory.setPath(path + "/" + repositoryObject.getName());
            repositoryDirectory.setName(repositoryObject.getName());
            repositoryDirectory.setObjectId(repositoryObject.getObjectId().getId());
            repositoryObjects.add(repositoryDirectory);
        } else {
            RepositoryFile repositoryFile = new RepositoryFile();
            repositoryFile.setPath(path + "/" + repositoryObject.getName());
            repositoryFile.setName(repositoryObject.getName());
            repositoryFile.setType(((RepositoryObject) repositoryObject).getObjectType() == RepositoryObjectType.TRANSFORMATION ? TRANSFORMATION : JOB);
            repositoryFile.setObjectId(repositoryObject.getObjectId().getId());
            repositoryObjects.add(repositoryFile);
        }
    }
    return repositoryObjects;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryDirectory) RepositoryObject(org.pentaho.di.repository.RepositoryObject) ArrayList(java.util.ArrayList) RepositoryObjectInterface(org.pentaho.di.repository.RepositoryObjectInterface) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) RepositoryFile(org.pentaho.di.plugins.fileopensave.providers.repository.model.RepositoryFile)

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