diff --git a/src/main/java/com/revo/deployr/client/RRepositoryFile.java b/src/main/java/com/revo/deployr/client/RRepositoryFile.java index a59c6b5..0da6c8b 100644 --- a/src/main/java/com/revo/deployr/client/RRepositoryFile.java +++ b/src/main/java/com/revo/deployr/client/RRepositoryFile.java @@ -106,5 +106,40 @@ public interface RRepositoryFile { */ public void delete() throws RClientException, RSecurityException; + /** + * Categories of repository-managed file. + */ + public enum Category { + + DATAFILE("data"), + GRAPHICSPLOT("plot"), + OTHER("file"), + PDFFILE("pdf"), + RBINARY("R"), + RSCRIPT("script"), + SHELLSCRIPT("shell"), + TEXTFILE("text"); + + private Category(String name) { + this.name = name; + } + + private final String name; + + public String toString() { + return name; + } + + public static Category fromString(String name) { + Category match = Category.OTHER; + for(Category c : Category.values()) { + if(c.toString().equalsIgnoreCase(name)) { + match = c; + break; + } + } + return match; + } + } } diff --git a/src/main/java/com/revo/deployr/client/about/RRepositoryFileDetails.java b/src/main/java/com/revo/deployr/client/about/RRepositoryFileDetails.java index cd73232..055ab77 100644 --- a/src/main/java/com/revo/deployr/client/about/RRepositoryFileDetails.java +++ b/src/main/java/com/revo/deployr/client/about/RRepositoryFileDetails.java @@ -12,6 +12,8 @@ */ package com.revo.deployr.client.about; +import com.revo.deployr.client.RRepositoryFile; + import java.net.URL; import java.util.Date; import java.util.List; @@ -27,7 +29,7 @@ public RRepositoryFileDetails(String filename, String directory, int size, URL url, String access, String restricted, boolean shared, boolean published, List authors, String inputs, String outputs, - String tags, String category, + String tags, RRepositoryFile.Category category, String md5, Date lastModified) { this.filename = filename; this.directory = directory; @@ -137,7 +139,7 @@ public RRepositoryFileDetails(String filename, String directory, /** * Repository file category. */ - public final String category; + public final RRepositoryFile.Category category; /** * Repository file md5 checksum. diff --git a/src/main/java/com/revo/deployr/client/api/RUserRepositoryDirectoryCalls.java b/src/main/java/com/revo/deployr/client/api/RUserRepositoryDirectoryCalls.java index 0560ff2..4a19c79 100644 --- a/src/main/java/com/revo/deployr/client/api/RUserRepositoryDirectoryCalls.java +++ b/src/main/java/com/revo/deployr/client/api/RUserRepositoryDirectoryCalls.java @@ -59,6 +59,24 @@ public List listDirectories(boolean userfiles, boolean published) throws RClientException, RSecurityException; + /** + * List directories in the user's default repository using filters to + * constrain the files in the response markup. + * If categoryFilter is specified only files matching the Category + * indicated will be included in the response. + * If directoryFilter is specified then only files found in the + * directory indicated will be included in the response. + * If both categoryFilter and directoryFilter are specified then + * only files matching the Category within the directory indicated + * will be included in the response. + * + * @throws RClientException if RClient fails to complete call. + * @throws RSecurityException if DeployR server security conditions not met on call. + */ + public List listDirectories(RRepositoryFile.Category categoryFilter, + String directoryFilter) + throws RClientException, RSecurityException; + /** * List directories in the user's external repository. * @@ -87,6 +105,24 @@ public List listExternalDirectories(boolean userfiles, boolean published) throws RClientException, RSecurityException; + /** + * List directories in the user's external repository using filters to + * constrain the files in the response markup. + * If categoryFilter is specified only files matching the Category + * indicated will be included in the response. + * If directoryFilter is specified then only files found in the + * external directory indicated will be included in the response. + * If both categoryFilter and directoryFilter are specified then + * only files matching the Category within the external directory + * indicated will be included in the response. + * + * @throws RClientException if RClient fails to complete call. + * @throws RSecurityException if DeployR server security conditions not met on call. + */ + public List listExternalDirectories(RRepositoryFile.Category categoryFilter, + String directoryFilter) + throws RClientException, RSecurityException; + /** * Creates a new custom user directory in the default repository. * diff --git a/src/main/java/com/revo/deployr/client/api/RUserRepositoryFileCalls.java b/src/main/java/com/revo/deployr/client/api/RUserRepositoryFileCalls.java index e25be77..08d990a 100644 --- a/src/main/java/com/revo/deployr/client/api/RUserRepositoryFileCalls.java +++ b/src/main/java/com/revo/deployr/client/api/RUserRepositoryFileCalls.java @@ -54,12 +54,31 @@ public List listFiles(boolean archived, throws RClientException, RSecurityException; /** - * List versions of named file in user repository-managed directory. + * List versions of named file in user's default repository. * * @throws RClientException if RClient fails to complete call. * @throws RSecurityException if DeployR server security conditions not met on call. */ - public List listFiles(String filename, String directory) + public List listFiles(String filename, + String directory) + throws RClientException, RSecurityException; + + /** + * List files in the user's default repository using filters to + * constrain the files in the response markup. + * If categoryFilter is specified only files matching the Category + * indicated will be included in the response. + * If directoryFilter is specified then only files found in the + * directory indicated will be included in the response. + * If both categoryFilter and directoryFilter are specified then + * only files matching the Category within the directory indicated + * will be included in the response. + * + * @throws RClientException if RClient fails to complete call. + * @throws RSecurityException if DeployR server security conditions not met on call. + */ + public List listFiles(RRepositoryFile.Category categoryFilter, + String directoryFilter) throws RClientException, RSecurityException; /** @@ -84,6 +103,24 @@ public List listExternalFiles() public List listExternalFiles(boolean shared, boolean published) throws RClientException, RSecurityException; + + /** + * List files in the user's external repository using filters to + * constrain the files in the response markup. + * If categoryFilter is specified only files matching the Category + * indicated will be included in the response. + * If directoryFilter is specified then only files found in the + * external directory indicated will be included in the response. + * If both categoryFilter and directoryFilter are specified then + * only files matching the Category within the external directory + * indicated will be included in the response. + * + * @throws RClientException if RClient fails to complete call. + * @throws RSecurityException if DeployR server security conditions not met on call. + */ + public List listExternalFiles(RRepositoryFile.Category categoryFilter, + String directoryFilter) + throws RClientException, RSecurityException; /** * Fetch latest meta-data on repository-managed file. diff --git a/src/main/java/com/revo/deployr/client/call/repository/RepositoryDirectoryListCall.java b/src/main/java/com/revo/deployr/client/call/repository/RepositoryDirectoryListCall.java index 1158f8f..97bf5ff 100644 --- a/src/main/java/com/revo/deployr/client/call/repository/RepositoryDirectoryListCall.java +++ b/src/main/java/com/revo/deployr/client/call/repository/RepositoryDirectoryListCall.java @@ -33,12 +33,16 @@ public RepositoryDirectoryListCall(boolean userfiles, boolean archived, boolean shared, boolean published, - boolean useExternalRepo) { + boolean useExternalRepo, + String directoryFilter, + String categoryFilter) { httpParams.put("userfiles", Boolean.toString(userfiles)); httpParams.put("archived", Boolean.toString(archived)); httpParams.put("shared", Boolean.toString(shared)); httpParams.put("published", Boolean.toString(published)); httpParams.put("external", Boolean.toString(useExternalRepo)); + httpParams.put("directory", directoryFilter); + httpParams.put("categoryFilter", categoryFilter); httpParams.put("format", "json"); } diff --git a/src/main/java/com/revo/deployr/client/call/repository/RepositoryFileListCall.java b/src/main/java/com/revo/deployr/client/call/repository/RepositoryFileListCall.java index 4cbba84..11a0494 100644 --- a/src/main/java/com/revo/deployr/client/call/repository/RepositoryFileListCall.java +++ b/src/main/java/com/revo/deployr/client/call/repository/RepositoryFileListCall.java @@ -31,13 +31,15 @@ public class RepositoryFileListCall extends AbstractCall public RepositoryFileListCall(boolean archived, boolean shared, boolean published, String filename, String directory, - boolean useExternalRepo) { + boolean useExternalRepo, + String categoryFilter) { httpParams.put("filename", filename); httpParams.put("directory", directory); httpParams.put("archived", Boolean.toString(archived)); httpParams.put("shared", Boolean.toString(shared)); httpParams.put("published", Boolean.toString(published)); httpParams.put("external", Boolean.toString(useExternalRepo)); + httpParams.put("categoryFilter", categoryFilter); httpParams.put("format", "json"); } diff --git a/src/main/java/com/revo/deployr/client/core/impl/RRepositoryFileImpl.java b/src/main/java/com/revo/deployr/client/core/impl/RRepositoryFileImpl.java index 1e8ba5e..0b6cc8f 100644 --- a/src/main/java/com/revo/deployr/client/core/impl/RRepositoryFileImpl.java +++ b/src/main/java/com/revo/deployr/client/core/impl/RRepositoryFileImpl.java @@ -64,7 +64,7 @@ public List versions() RCall rCall = new RepositoryFileListCall(false, false, false, about.filename, about.directory, - false); + false, null); RCoreResult rResult = liveContext.executor.processCall(rCall); List repoFiles = rResult.getRepoFiles(); diff --git a/src/main/java/com/revo/deployr/client/core/impl/RUserImpl.java b/src/main/java/com/revo/deployr/client/core/impl/RUserImpl.java index 2d3e779..d738f9a 100644 --- a/src/main/java/com/revo/deployr/client/core/impl/RUserImpl.java +++ b/src/main/java/com/revo/deployr/client/core/impl/RUserImpl.java @@ -358,6 +358,16 @@ public List listFiles(boolean archived, return listFiles(archived, shared, published, null, null); } + public List listFiles(RRepositoryFile.Category categoryFilter, + String directoryFilter) + throws RClientException, RSecurityException { + + return listRepoFiles(false, false, false, + null, directoryFilter, + false, + categoryFilter); + } + public List listFiles(String filename, String directory) throws RClientException, RSecurityException { @@ -372,7 +382,7 @@ public List listFiles(boolean archived, return listRepoFiles(archived, shared, published, filename, directory, - false); + false, null); } public List listExternalFiles() @@ -387,19 +397,31 @@ public List listExternalFiles(boolean shared, return listRepoFiles(false, shared, published, null, null, - true); + true, null); + } + + public List listExternalFiles(RRepositoryFile.Category categoryFilter, + String directoryFilter) + throws RClientException, RSecurityException { + + return listRepoFiles(false, false, false, + null, directoryFilter, + true, + categoryFilter); } private List listRepoFiles(boolean archived, boolean shared, boolean published, String filename, String directory, - boolean useExternalRepo) + boolean useExternalRepo, + RRepositoryFile.Category categoryFilter) throws RClientException, RSecurityException { RCall rCall = new RepositoryFileListCall(archived, shared, published, filename, directory, - useExternalRepo); + useExternalRepo, + categoryFilter != null ? categoryFilter.toString() : null); RCoreResult rResult = liveContext.executor.processCall(rCall); List repoFiles = rResult.getRepoFiles(); @@ -667,7 +689,20 @@ public List listDirectories(boolean userfiles, boolean published) throws RClientException, RSecurityException { - return listRepoDirectories(userfiles, archived, shared, published, false); + return listRepoDirectories(userfiles, + archived, shared, published, + false, + null, null); + } + + public List listDirectories(RRepositoryFile.Category categoryFilter, + String directoryFilter) + throws RClientException, RSecurityException { + + return listRepoDirectories(false, + false, false, false, + false, + directoryFilter, categoryFilter); } public List listExternalDirectories() @@ -681,21 +716,38 @@ public List listExternalDirectories(boolean userfiles, boolean published) throws RClientException, RSecurityException { - return listRepoDirectories(userfiles, false, shared, published, true); + return listRepoDirectories(userfiles, + false, shared, published, + true, + null, null); + } + + public List listExternalDirectories(RRepositoryFile.Category categoryFilter, + String directoryFilter) + throws RClientException, RSecurityException { + + return listRepoDirectories(false, + false, false, false, + true, + directoryFilter, categoryFilter); } private List listRepoDirectories(boolean userfiles, boolean archived, boolean shared, boolean published, - boolean useExternalRepo) + boolean useExternalRepo, + String directoryFilter, + RRepositoryFile.Category categoryFilter) throws RClientException, RSecurityException { RCall rCall = new RepositoryDirectoryListCall(userfiles, archived, shared, published, - useExternalRepo); + useExternalRepo, + directoryFilter, + categoryFilter != null ? categoryFilter.toString() : null); RCoreResult rResult = liveContext.executor.processCall(rCall); List repoDirectories = rResult.getRepoDirectories(); diff --git a/src/main/java/com/revo/deployr/client/util/REntityUtil.java b/src/main/java/com/revo/deployr/client/util/REntityUtil.java index d90a16b..c7620ea 100644 --- a/src/main/java/com/revo/deployr/client/util/REntityUtil.java +++ b/src/main/java/com/revo/deployr/client/util/REntityUtil.java @@ -87,7 +87,11 @@ public static RRepositoryFileDetails getRepositoryFileDetails(Map repoFile) { String urlString = (String) repoFile.get("url"); String tags = (String) repoFile.get("tags"); - String category = (String) repoFile.get("category"); + RRepositoryFile.Category category = null; + String categoryName = (String) repoFile.get("category"); + if(categoryName != null) { + category = RRepositoryFile.Category.fromString(categoryName); + } String md5 = (String) repoFile.get("md5"); Long lastModified = (Long) repoFile.get("lastModified"); Date lastModifiedDate = null;