Skip to content

Commit

Permalink
have dataset page get cached JSON-LD, if available IQSS#3700
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Nov 29, 2017
1 parent 84224bd commit 3cc02d0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
11 changes: 10 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import edu.harvard.iq.dataverse.engine.command.impl.RestrictFileCommand;
import edu.harvard.iq.dataverse.engine.command.impl.ReturnDatasetToAuthorCommand;
import edu.harvard.iq.dataverse.engine.command.impl.SubmitDatasetForReviewCommand;
import edu.harvard.iq.dataverse.export.SchemaDotOrgExporter;
import java.util.Collections;

import javax.faces.event.AjaxBehaviorEvent;
Expand Down Expand Up @@ -4068,7 +4069,15 @@ public boolean isThisLatestReleasedVersion() {

public String getJsonLd() {
if (isThisLatestReleasedVersion()) {
return workingVersion.getJsonLd();
ExportService instance = ExportService.getInstance(settingsService);
String jsonLd = instance.getExportAsString(dataset, SchemaDotOrgExporter.NAME);
if (jsonLd != null) {
logger.fine("Returning cached schema.org JSON-LD.");
return jsonLd;
} else {
logger.fine("No cached schema.org JSON-LD available. Going to the database.");
return workingVersion.getJsonLd();
}
}
return "";
}
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/edu/harvard/iq/dataverse/DatasetVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -1211,12 +1211,8 @@ public String getPublicationDateAsString() {
return r;
}

// TODO: Make this more performant by writing the output to the database or a file?
// Agree - now that this has grown into a somewhat complex chunk of formatted
// metadata - and not just a couple of values inserted into the page html -
// it feels like it would make more sense to treat it as another supported
// export format, that can be produced once and cached.
// The problem with that is that the export subsystem assumes there is only
// TODO: Consider moving this comment into the Exporter code.
// The export subsystem assumes there is only
// one metadata export in a given format per dataset (it uses the current
// released (published) version. This JSON fragment is generated for a
// specific released version - and we can have multiple released versions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class SchemaDotOrgExporter implements Exporter {

private static final Logger logger = Logger.getLogger(SchemaDotOrgExporter.class.getCanonicalName());

public static final String NAME = "schema.org";

@Override
public void exportDataset(DatasetVersion version, JsonObject json, OutputStream outputStream) throws ExportException {
String jsonLdAsString = version.getJsonLd();
Expand All @@ -37,7 +39,7 @@ public void exportDataset(DatasetVersion version, JsonObject json, OutputStream

@Override
public String getProviderName() {
return "schema.org";
return NAME;
}

@Override
Expand Down

0 comments on commit 3cc02d0

Please sign in to comment.