Skip to content

Commit

Permalink
add @id along side identifier at file level #4371
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Nov 6, 2018
1 parent fcae94e commit 0e0b55d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.harvard.iq.dataverse.util.json.NullSafeJsonBuilder;
import edu.harvard.iq.dataverse.workflows.WorkflowComment;
import java.io.Serializable;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -1545,6 +1546,7 @@ public String getJsonLd() {
JsonObjectBuilder job = Json.createObjectBuilder();
job.add("@context", "http://schema.org");
job.add("@type", "Dataset");
// Note that whenever you use "@id" you should also use "identifier" and vice versa.
job.add("@id", this.getDataset().getPersistentURL());
job.add("identifier", this.getDataset().getPersistentURL());
job.add("name", this.getTitle());
Expand Down Expand Up @@ -1767,12 +1769,18 @@ public String getJsonLd() {
String dataverseSiteUrl = SystemConfig.getDataverseSiteUrlStatic();
for (FileMetadata fileMetadata : fileMetadatasSorted) {
JsonObjectBuilder fileObject = NullSafeJsonBuilder.jsonObjectBuilder();
String filePidUrlAsString = null;
URL filePidUrl = fileMetadata.getDataFile().getGlobalId().toURL();
if (filePidUrl != null) {
filePidUrlAsString = filePidUrl.toString();
}
fileObject.add("@type", "DataDownload");
fileObject.add("name", fileMetadata.getLabel());
fileObject.add("fileFormat", fileMetadata.getDataFile().getContentType());
fileObject.add("contentSize", fileMetadata.getDataFile().getFilesize());
fileObject.add("description", fileMetadata.getDescription());
fileObject.add("identifier", fileMetadata.getDataFile().getGlobalId().toURL().toString());
fileObject.add("@id", filePidUrlAsString);
fileObject.add("identifier", filePidUrlAsString);
String hideFilesBoolean = System.getProperty(SystemConfig.FILES_HIDE_SCHEMA_DOT_ORG_DOWNLOAD_URLS);
if (hideFilesBoolean != null && hideFilesBoolean.equals("true")) {
// no-op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ public void testExportDataset() throws Exception {
assertEquals("text/plain", json2.getJsonArray("distribution").getJsonObject(0).getString("fileFormat"));
assertEquals(1234, json2.getJsonArray("distribution").getJsonObject(0).getInt("contentSize"));
assertEquals("README file.", json2.getJsonArray("distribution").getJsonObject(0).getString("description"));
assertEquals("https://doi.org/10.5072/FK2/7V5MPI", json2.getJsonArray("distribution").getJsonObject(0).getString("@id"));
assertEquals("https://doi.org/10.5072/FK2/7V5MPI", json2.getJsonArray("distribution").getJsonObject(0).getString("identifier"));
assertEquals("https://librascholar.org/api/access/datafile/42", json2.getJsonArray("distribution").getJsonObject(0).getString("contentUrl"));
assertEquals(1, json2.getJsonArray("distribution").size());
Expand Down

0 comments on commit 0e0b55d

Please sign in to comment.