Skip to content

Commit

Permalink
RW-593: Added repository list filters API support.
Browse files Browse the repository at this point in the history
Added new methods on the following interfaces to support the filtering of files returned on the response when listing files or files within directories:

- RUserRepositoryFilesCalls
- RUserRepositoryDirectoryCalls

This new filter support is available when listing files in the default repository and files in the external repository.
  • Loading branch information
david-russell committed Jan 22, 2015
1 parent 39fc594 commit 655a87b
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 16 deletions.
35 changes: 35 additions & 0 deletions src/main/java/com/revo/deployr/client/RRepositoryFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +29,7 @@ public RRepositoryFileDetails(String filename, String directory,
int size, URL url, String access,
String restricted, boolean shared, boolean published,
List<String> authors, String inputs, String outputs,
String tags, String category,
String tags, RRepositoryFile.Category category,
String md5, Date lastModified) {
this.filename = filename;
this.directory = directory;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ public List<RRepositoryDirectory> 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<RRepositoryDirectory> listDirectories(RRepositoryFile.Category categoryFilter,
String directoryFilter)
throws RClientException, RSecurityException;

/**
* List directories in the user's external repository.
*
Expand Down Expand Up @@ -87,6 +105,24 @@ public List<RRepositoryDirectory> 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<RRepositoryDirectory> listExternalDirectories(RRepositoryFile.Category categoryFilter,
String directoryFilter)
throws RClientException, RSecurityException;

/**
* Creates a new custom user directory in the default repository.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,31 @@ public List<RRepositoryFile> 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<RRepositoryFile> listFiles(String filename, String directory)
public List<RRepositoryFile> 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<RRepositoryFile> listFiles(RRepositoryFile.Category categoryFilter,
String directoryFilter)
throws RClientException, RSecurityException;

/**
Expand All @@ -84,6 +103,24 @@ public List<RRepositoryFile> listExternalFiles()
public List<RRepositoryFile> 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<RRepositoryFile> listExternalFiles(RRepositoryFile.Category categoryFilter,
String directoryFilter)
throws RClientException, RSecurityException;

/**
* Fetch latest meta-data on repository-managed file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public List<RRepositoryFile> versions()
RCall rCall = new RepositoryFileListCall(false, false, false,
about.filename,
about.directory,
false);
false, null);
RCoreResult rResult = liveContext.executor.processCall(rCall);

List<Map> repoFiles = rResult.getRepoFiles();
Expand Down
68 changes: 60 additions & 8 deletions src/main/java/com/revo/deployr/client/core/impl/RUserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,16 @@ public List<RRepositoryFile> listFiles(boolean archived,
return listFiles(archived, shared, published, null, null);
}

public List<RRepositoryFile> listFiles(RRepositoryFile.Category categoryFilter,
String directoryFilter)
throws RClientException, RSecurityException {

return listRepoFiles(false, false, false,
null, directoryFilter,
false,
categoryFilter);
}

public List<RRepositoryFile> listFiles(String filename,
String directory)
throws RClientException, RSecurityException {
Expand All @@ -372,7 +382,7 @@ public List<RRepositoryFile> listFiles(boolean archived,
return listRepoFiles(archived,
shared, published,
filename, directory,
false);
false, null);
}

public List<RRepositoryFile> listExternalFiles()
Expand All @@ -387,19 +397,31 @@ public List<RRepositoryFile> listExternalFiles(boolean shared,
return listRepoFiles(false,
shared, published,
null, null,
true);
true, null);
}

public List<RRepositoryFile> listExternalFiles(RRepositoryFile.Category categoryFilter,
String directoryFilter)
throws RClientException, RSecurityException {

return listRepoFiles(false, false, false,
null, directoryFilter,
true,
categoryFilter);
}

private List<RRepositoryFile> 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<Map> repoFiles = rResult.getRepoFiles();
Expand Down Expand Up @@ -667,7 +689,20 @@ public List<RRepositoryDirectory> 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<RRepositoryDirectory> listDirectories(RRepositoryFile.Category categoryFilter,
String directoryFilter)
throws RClientException, RSecurityException {

return listRepoDirectories(false,
false, false, false,
false,
directoryFilter, categoryFilter);
}

public List<RRepositoryDirectory> listExternalDirectories()
Expand All @@ -681,21 +716,38 @@ public List<RRepositoryDirectory> 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<RRepositoryDirectory> listExternalDirectories(RRepositoryFile.Category categoryFilter,
String directoryFilter)
throws RClientException, RSecurityException {

return listRepoDirectories(false,
false, false, false,
true,
directoryFilter, categoryFilter);
}

private List<RRepositoryDirectory> 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<Map> repoDirectories = rResult.getRepoDirectories();
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/revo/deployr/client/util/REntityUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 655a87b

Please sign in to comment.