Skip to content

Commit

Permalink
Merge branch 'develop' into 9670-5.14-release-notes #9670
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Jul 20, 2023
2 parents 9963fbc + 8f882b7 commit de40651
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 35 deletions.
2 changes: 1 addition & 1 deletion doc/sphinx-guides/source/installation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,7 @@ please find all known feature flags below. Any of these flags can be activated u
- Description
- Default status
* - api-session-auth
- Enables API authentication via session cookie (JSESSIONID). **Caution: Enabling this feature flag exposes the installation to CSRF risks!** We expect this feature flag to be temporary (only used by frontend developers, see `#9063 <https://github.com/IQSS/dataverse/issues/9063>`_) and removed once support for bearer tokens has been implemented (see `#9229 <https://github.com/IQSS/dataverse/issues/9229>`_).
- Enables API authentication via session cookie (JSESSIONID). **Caution: Enabling this feature flag exposes the installation to CSRF risks!** We expect this feature flag to be temporary (only used by frontend developers, see `#9063 <https://github.com/IQSS/dataverse/issues/9063>`_) and for the feature to be removed in the future.
- ``Off``

**Note:** Feature flags can be set via any `supported MicroProfile Config API source`_, e.g. the environment variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import javax.json.JsonArray;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.json.JsonString;
import javax.json.JsonValue;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
Expand Down Expand Up @@ -1917,7 +1918,7 @@ private static void createVarDDI(XMLStreamWriter xmlw, JsonObject dvar, String f
for (Entry<String, JsonValue> sumStat : dvar.getJsonObject("summaryStatistics").entrySet()) {
xmlw.writeStartElement("sumStat");
writeAttribute(xmlw, "type", sumStat.getKey());
xmlw.writeCharacters(sumStat.getValue().toString());
xmlw.writeCharacters(((JsonString)sumStat.getValue()).getString());
xmlw.writeEndElement(); // sumStat
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,12 @@ public static JsonObjectBuilder json(DataFile df, FileMetadata fileMetadata, boo
* InternalExportDataProvider fileDetails.
*/
if (forExportDataProvider) {
builder.add("restricted", df.isRestricted());
builder.add("restricted", df.isRestricted())
.add("fileMetadataId", fileMetadata.getId())
.add("dataTables", df.getDataTables().isEmpty() ? null : JsonPrinter.jsonDT(df.getDataTables()))
.add("varGroups", fileMetadata.getVarGroups().isEmpty()
? JsonPrinter.jsonVarGroup(fileMetadata.getVarGroups())
: null);
}
return builder;
}
Expand Down
48 changes: 16 additions & 32 deletions src/main/webapp/file.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -285,38 +285,22 @@
</ui:fragment>
</div>
<!-- END DATASET CITATION -->
<!-- Metrics -->
<div class="col-sm-3">
<div id="metrics-block" jsf:rendered="#{!(widgetWrapper.widgetView or FilePage.fileMetadata.dataFile.filePackage or FilePage.fileMetadata.datasetVersion.deaccessioned)}">
<div id="metrics-heading">
#{bundle['metrics.file.title']}
<ui:fragment rendered="#{!settingsWrapper.makeDataCountDisplayEnabled}">
<span class="glyphicon glyphicon-question-sign tooltip-icon" data-toggle="tooltip" data-placement="auto top"
data-trigger="hover" data-original-title="#{bundle['metrics.dataset.tip.default']}"></span>
</ui:fragment>
<ui:fragment rendered="#{settingsWrapper.makeDataCountDisplayEnabled}">
<a tabindex="0" role="button" class="glyphicon glyphicon-question-sign tooltip-icon" data-toggle="popover" data-placement="auto top"
data-trigger="focus" data-html="true" data-content="#{bundle['metrics.dataset.tip.makedatacount']}"></a>
</ui:fragment>
</div>
<div id="metrics-body">
<!-- Classic downloads -->
<div class="metrics-count-block" jsf:rendered="#{!settingsWrapper.makeDataCountDisplayEnabled}">
<h:outputFormat value="{0} #{bundle['metrics.downloads']}">
<f:param value="#{guestbookResponseServiceBean.getCountGuestbookResponsesByDataFileId(FilePage.fileId)}"/>
</h:outputFormat>
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['metrics.file.downloads.tip']}"></span>
</div>
<!-- Make Data Count downloads -->
<div class="metrics-count-block" jsf:rendered="#{settingsWrapper.makeDataCountDisplayEnabled}">
<h:outputFormat value="{0} #{bundle['metrics.downloads']}">
<f:param value="#{guestbookResponseServiceBean.getCountGuestbookResponsesByDataFileId(FilePage.fileId)}"/>
</h:outputFormat>
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['metrics.file.downloads.nonmdc.tip']}"></span>
</div>
</div>
<div id="metrics-body">
<!-- Classic downloads -->
<div class="metrics-count-block" jsf:rendered="#{!settingsWrapper.makeDataCountDisplayEnabled}">
<h:outputFormat value="{0} #{bundle['metrics.downloads']}">
<f:param value="#{guestbookResponseServiceBean.getCountGuestbookResponsesByDataFileId(FilePage.fileId)}"/>
</h:outputFormat>
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['metrics.file.downloads.tip']}"></span>
</div>
<!-- Make Data Count downloads -->
<div class="metrics-count-block" jsf:rendered="#{settingsWrapper.makeDataCountDisplayEnabled}">
<h:outputFormat value="{0} #{bundle['metrics.downloads']}">
<f:param value="#{guestbookResponseServiceBean.getCountGuestbookResponsesByDataFileId(FilePage.fileId)}"/>
</h:outputFormat>
<span class="glyphicon glyphicon-question-sign tooltip-icon"
data-toggle="tooltip" data-placement="auto top" data-original-title="#{bundle['metrics.file.downloads.nonmdc.tip']}"></span>
</div>
</div>
</div>
Expand Down
65 changes: 65 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,71 @@ public void testLinkingDatasets() {
*/
}

/**
* This tests the "DDI export" and verifies that variable metadata is included for an unrestricted file.
*/
@Test
public void testUnrestrictedFileExportDdi() throws IOException {

Response createUser = UtilIT.createRandomUser();
createUser.prettyPrint();
String authorUsername = UtilIT.getUsernameFromResponse(createUser);
String authorApiToken = UtilIT.getApiTokenFromResponse(createUser);

Response createDataverse = UtilIT.createRandomDataverse(authorApiToken);
createDataverse.prettyPrint();
createDataverse.then().assertThat()
.statusCode(CREATED.getStatusCode());
String dataverseAlias = UtilIT.getAliasFromResponse(createDataverse);

Response createDataset = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, authorApiToken);
createDataset.prettyPrint();
createDataset.then().assertThat()
.statusCode(CREATED.getStatusCode());

Integer datasetId = UtilIT.getDatasetIdFromResponse(createDataset);
String datasetPid = JsonPath.from(createDataset.asString()).getString("data.persistentId");

Path pathToFile = Paths.get(java.nio.file.Files.createTempDirectory(null) + File.separator + "data.csv");
String contentOfCsv = ""
+ "name,pounds,species\n"
+ "Marshall,40,dog\n"
+ "Tiger,17,cat\n"
+ "Panther,21,cat\n";
java.nio.file.Files.write(pathToFile, contentOfCsv.getBytes());

Response uploadFile = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile.toString(), authorApiToken);
uploadFile.prettyPrint();
uploadFile.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.files[0].label", equalTo("data.csv"));

String fileId = JsonPath.from(uploadFile.body().asString()).getString("data.files[0].dataFile.id");

assertTrue("Failed test if Ingest Lock exceeds max duration " + pathToFile, UtilIT.sleepForLock(datasetId.longValue(), "Ingest", authorApiToken, UtilIT.MAXIMUM_INGEST_LOCK_DURATION));

Response publishDataverse = UtilIT.publishDataverseViaNativeApi(dataverseAlias, authorApiToken);
publishDataverse.then().assertThat().statusCode(OK.getStatusCode());
Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPid, "major", authorApiToken);
publishDataset.then().assertThat().statusCode(OK.getStatusCode());

// We're testing export here, which is at dataset level.
// Guest/public version
Response exportByGuest = UtilIT.exportDataset(datasetPid, "ddi");
exportByGuest.prettyPrint();
exportByGuest.then().assertThat()
.statusCode(OK.getStatusCode())
.body("codeBook.fileDscr.fileTxt.fileName", equalTo("data.tab"))
.body("codeBook.fileDscr.fileTxt.dimensns.caseQnty", equalTo("3"))
.body("codeBook.fileDscr.fileTxt.dimensns.varQnty", equalTo("3"))
.body("codeBook.dataDscr", CoreMatchers.not(equalTo(null)))
.body("codeBook.dataDscr.var[0].@name", equalTo("name"))
.body("codeBook.dataDscr.var[1].@name", equalTo("pounds"))
// This is an example of a summary stat (max) that should be visible.
.body("codeBook.dataDscr.var[1].sumStat.find { it.@type == 'max' }", equalTo("40.0"))
.body("codeBook.dataDscr.var[2].@name", equalTo("species"));
}

/**
* In this test we are restricting a file and testing "export DDI" at the
* dataset level as well as getting the DDI at the file level.
Expand Down

0 comments on commit de40651

Please sign in to comment.