Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5325 no header tab download #5367

Merged
merged 3 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/sphinx-guides/source/api/dataaccess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ subset Column-wise subsetting. You must also supply a comma separated l

---------------------------

``noVarHeader``

(supported for tabular data files only; ignored for all other file types)

============== ===========
Value Description
============== ===========
true|1 Tab-delimited data file, without the variable name header (added to tab. files by default)
============== ===========

---------------------------

``imageThumb``

the following parameter values are supported (for image and pdf files only):
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/api/Access.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,13 @@ public DownloadInstance datafile(@PathParam("fileId") String fileId, @QueryParam
}
for (String key : uriInfo.getQueryParameters().keySet()) {
String value = uriInfo.getQueryParameters().getFirst(key);

logger.fine("is download service supported? key="+key+", value="+value);

if (downloadInstance.checkIfServiceSupportedAndSetConverter(key, value)) {
logger.fine("is download service supported? key="+key+", value="+value);
// this automatically sets the conversion parameters in
// the download instance to key and value;
// TODO: I should probably set these explicitly instead.
logger.fine("yes!");

if (downloadInstance.getConversionParam().equals("subset")) {
String subsetParam = downloadInstance.getConversionParamValue();
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/DownloadInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,22 @@ public Boolean checkIfServiceSupportedAndSetConverter(String serviceArg, String

for (OptionalAccessService dataService : servicesAvailable) {
if (dataService != null) {
// Special case for the subsetting parameter (variables=<LIST>):
if (serviceArg.equals("variables")) {
// Special case for the subsetting parameter (variables=<LIST>):
if ("subset".equals(dataService.getServiceName())) {
conversionParam = "subset";
conversionParamValue = serviceArgValue;
return true;
}
} else if (serviceArg.equals("noVarHeader")) {
// Another special case available for tabular ("subsettable") data files -
// "do not add variable header" flag:
if ("true".equalsIgnoreCase(serviceArgValue) || "1".equalsIgnoreCase(serviceArgValue)) {
if ("subset".equals(dataService.getServiceName())) {
this.conversionParam = serviceArg;
return true;
}
}
} else if ("imageThumb".equals(serviceArg)) {
if ("true".equals(serviceArgValue)) {
this.conversionParam = serviceArg;
Expand Down
19 changes: 15 additions & 4 deletions src/test/java/edu/harvard/iq/dataverse/api/AccessIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public class AccessIT {
public static String tabFile3NameRestrictedConvert;
public static String tabFile4NameUnpublishedConvert;

public static int tabFile1SizeOriginal = 279;
public static int tabFile1SizeConverted = 4;
public static int tabFile1SizeConvertedWithVarHeader = 9;

@BeforeClass
public static void setUp() throws InterruptedException {
RestAssured.baseURI = UtilIT.getRestAssuredBaseUri();
Expand Down Expand Up @@ -150,12 +154,19 @@ public void testDownloadSingleFile() {
//Not logged in non-restricted
Response anonDownloadOriginal = UtilIT.downloadFileOriginal(tabFile1Id);
Response anonDownloadConverted = UtilIT.downloadFile(tabFile1Id);
// ... and download the same tabular data file, but without the variable name header added:
Response anonDownloadTabularNoHeader = UtilIT.downloadTabularFileNoVarHeader(tabFile1Id);
assertEquals(OK.getStatusCode(), anonDownloadOriginal.getStatusCode());
assertEquals(OK.getStatusCode(), anonDownloadConverted.getStatusCode()); //just to ensure next test
assertEquals(OK.getStatusCode(), anonDownloadConverted.getStatusCode());
assertEquals(OK.getStatusCode(), anonDownloadTabularNoHeader.getStatusCode());
int origSizeAnon = anonDownloadOriginal.getBody().asByteArray().length;
int convertSizeAnon = anonDownloadConverted.getBody().asByteArray().length;
System.out.println("origSize: "+origSizeAnon + " | convertSize: " + convertSizeAnon);
assertThat(origSizeAnon, is(not(convertSizeAnon)));
int tabularSizeNoVarHeader = anonDownloadTabularNoHeader.getBody().asByteArray().length;
System.out.println("origSize: "+origSizeAnon + " | convertSize: " + convertSizeAnon + " | convertNoHeaderSize: " + tabularSizeNoVarHeader);

assertEquals(origSizeAnon, tabFile1SizeOriginal);
assertEquals(convertSizeAnon, tabFile1SizeConvertedWithVarHeader);
assertEquals(tabularSizeNoVarHeader, tabFile1SizeConverted);

//Not logged in restricted
Response anonDownloadOriginalRestricted = UtilIT.downloadFileOriginal(tabFile3IdRestricted);
Expand All @@ -178,7 +189,7 @@ public void testDownloadSingleFile() {
int convertSizeAuth = authDownloadConverted.getBody().asByteArray().length;
System.out.println("origSize: "+origSizeAuth + " | convertSize: " + convertSizeAuth);
assertThat(origSizeAuth, is(not(convertSizeAuth)));

//Logged in restricted
Response authDownloadOriginalRestricted = UtilIT.downloadFileOriginal(tabFile3IdRestricted, apiToken);
Response authDownloadConvertedRestricted = UtilIT.downloadFile(tabFile3IdRestricted, apiToken);
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,11 @@ static Response downloadFileOriginal(Integer fileId) {
.get("/api/access/datafile/" + fileId + "?format=original");
}

static Response downloadTabularFileNoVarHeader(Integer fileId) {
return given()
.get("/api/access/datafile/" + fileId + "?noVarHeader=true");
}

static Response downloadFileOriginal(Integer fileId, String apiToken) {
return given()
.get("/api/access/datafile/" + fileId + "?format=original&key=" + apiToken);
Expand Down