Search in sources :

Example 31 with LastUsedFile

use of org.pentaho.di.core.LastUsedFile in project pentaho-kettle by pentaho.

the class Spoon method recentRepoFileExists.

/**
 * Returns true if the {@link LastUsedFile} at the given {@code index} within the {@link
 * PropsUI#getLastUsedRepoFiles()} collection exists within the given {@code repo} {@link Repository},
 * and false otherwise.
 *
 * @param repo     the {@link Repository} containing the file
 * @param indexStr the String index of the file within the last used repo file collection
 * @return true if the {@link LastUsedFile} at the given {@code index} within the {@link
 * PropsUI#getLastUsedRepoFiles()} collection exists within the given {@code repo} {@link Repository},
 * and false otherwise
 * @throws KettleException
 */
public boolean recentRepoFileExists(String repo, String indexStr) {
    final LastUsedFile lastUsedFile = getLastUsedRepoFile(repo, indexStr);
    // this should never happen when used on a repo file, but we check just to be safe
    if (lastUsedFile == null) {
        return false;
    }
    // again, should never happen, since the file being selected is a valid repo file in this repo
    if (!lastUsedFile.isSourceRepository() || !rep.getName().equalsIgnoreCase(lastUsedFile.getRepositoryName())) {
        return false;
    }
    try {
        final RepositoryDirectoryInterface rdi = rep.findDirectory(lastUsedFile.getDirectory());
        if (rdi == null) {
            return false;
        }
        final RepositoryObjectType fileType = lastUsedFile.isJob() ? RepositoryObjectType.JOB : RepositoryObjectType.TRANSFORMATION;
        return rep.exists(lastUsedFile.getFilename(), rdi, fileType);
    } catch (final KettleException ke) {
        // log
        return false;
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) LastUsedFile(org.pentaho.di.core.LastUsedFile)

Aggregations

LastUsedFile (org.pentaho.di.core.LastUsedFile)31 Point (org.pentaho.di.core.gui.Point)17 Date (java.util.Date)9 RecentFile (org.pentaho.di.plugins.fileopensave.providers.recents.model.RecentFile)5 Calendar (java.util.Calendar)4 Test (org.junit.Test)4 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)4 PropsUI (org.pentaho.di.ui.core.PropsUI)4 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 IUser (org.pentaho.di.repository.IUser)2 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collections (java.util.Collections)1 List (java.util.List)1 PropertyResourceBundle (java.util.PropertyResourceBundle)1 ResourceBundle (java.util.ResourceBundle)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1