Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/release-notes/12468-prov-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This release resolves two older issues about provenance files and improves the related documentation.

When uploading a wrong provenance JSON, the user was still able to click on the preview button which caused an exception.
From now on, this button will not be available. Also, the error message about the wrong JSON now includes information about what the error actually is.

The user guide and the GUI now explicitly state that Dataverse only accepts the PROV-JSON format.
2 changes: 1 addition & 1 deletion doc/sphinx-guides/source/user/dataset-management.rst
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ A **Provenance File** is the preferred way of submitting provenance information

Once you upload a provenance file, the Dataverse installation will need some additional information in order to accurately connect it to your data file. Once provenance file upload finishes, an input box labeled "Connect entity" will appear under the file. Provenance files contain a list of "entities", which include your data file as well as any objects associated with it (e.g. a chart, a spellchecker, etc.). You will need to tell the Dataverse installation which entity within the provenance file represents your data file. You may type the name of the entity into the box, or click the arrow next to the box and select the entity from a list of all entities in the provenance file.
Comment thread
pdurbin marked this conversation as resolved.

For more information on entities and the contents of provenance files, see `the W3C PROV Model Primer <https://www.w3.org/TR/prov-primer/#intuitive-overview-of-prov>`_.
For more information on entities and the contents of provenance files, see `the W3C PROV Model Primer <https://www.w3.org/TR/prov-primer/#intuitive-overview-of-prov>`_. The uploaded file must be in JSON format as described in `the PROV-JSON specification <https://www.w3.org/submissions/2013/SUBM-prov-json-20130424/>`_.

Once you've uploaded your Provenance File and connected the proper entity, you can hit the Preview button to view the raw JSON of the Provenance File. This can help you confirm that you've uploaded the right file. Be sure to double-check it, because the Provenance File will made *permanent* once it's finalized. At that point you will not be able to *replace*, *remove*, or otherwise *edit* the Provenance File. This ensures that the Provenance File maintains a stable, immutable record of the data file's history. This finalization of the Provenance File happens at different points depending on the status of your data file. If this is a brand new data file that has never been published before, then its associated Provenance File will be made permanent once you publish the dataset. If this data file *has* been published in a previous version of your dataset, then its associated Provenance File will be made permanent as soon as you upload the Provenance File and click "Save Changes" on the warning popup.

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/api/Prov.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@
return error(FORBIDDEN, BundleUtil.getStringFromBundle("api.prov.error.jsonUpdateNotAllowed"));
}

if(!provUtil.isProvValid(body)) {
return error(BAD_REQUEST, BundleUtil.getStringFromBundle("file.editProvenanceDialog.invalidSchemaError"));
var schemaErrorMessages = provUtil.isProvValid(body);
if(!schemaErrorMessages.isEmpty()) {
return error(BAD_REQUEST, BundleUtil.getStringFromBundle("file.editProvenanceDialog.invalidSchemaError") + schemaErrorMessages.get());

Check warning

Code scanning / CodeQL

Information exposure through an error message Medium

Error information
can be exposed to an external user.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exposed information is just error messages about a file uploaded by the user. Besides, only an authenticated user can call this endpoint.

}

/*Add when we actually integrate provCpl*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Set;
import java.util.logging.Logger;
import jakarta.json.JsonObject;
import java.util.Optional;
import org.everit.json.schema.Schema;
import org.everit.json.schema.ValidationException;
import org.everit.json.schema.loader.SchemaLoader;
Expand Down Expand Up @@ -114,18 +115,18 @@ public String getPrettyJsonString(JsonObject jsonObject) {
return gson.toJson(je);
}

public boolean isProvValid(String jsonInput) {
public Optional<String> isProvValid(String jsonInput) {
try {
schema.validate(new JSONObject(jsonInput)); // throws a ValidationException if this object is invalid
} catch (ValidationException vx) {
logger.info("Prov schema error : " + vx); //without classLoader is blows up in actual deployment
return false;
return Optional.of(vx.getAllMessages().toString());
} catch (Exception ex) {
logger.info("Prov file error : " + ex);
return false;
return Optional.of(ex.getMessage());
}

return true;
return Optional.empty();
}

//Pulled from https://www.w3.org/Submission/2013/SUBM-prov-json-20130424/schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@ public void handleFileUpload(FileUploadEvent event) throws IOException {
provJsonState = IOUtils.toString(jsonUploadedTempFile.getInputStream());


if(!provUtil.isProvValid(provJsonState)) { //if uploaded prov-json does not comply with schema
provUtil.isProvValid(provJsonState).ifPresentOrElse(message -> { //if uploaded prov-json does not comply with schema
Logger.getLogger(ProvPopupFragmentBean.class.getName())
.log(Level.INFO, BundleUtil.getStringFromBundle("file.editProvenanceDialog.invalidSchemaError"));
provJsonState = null;
removeJsonAndRelatedData();
JH.addMessage(FacesMessage.SEVERITY_ERROR, BundleUtil.getStringFromBundle("file.editProvenanceDialog.invalidSchemaError"));
}

else {
JH.addMessage(FacesMessage.SEVERITY_ERROR, BundleUtil.getStringFromBundle("file.editProvenanceDialog.invalidSchemaError"), "Reason: " + message);
}, () -> {
try {
generateProvJsonParsedEntities();

Expand All @@ -116,7 +115,7 @@ public void handleFileUpload(FileUploadEvent event) throws IOException {
removeJsonAndRelatedData();
JH.addMessage(FacesMessage.SEVERITY_ERROR, BundleUtil.getStringFromBundle("file.editProvenanceDialog.noEntitiesError"));
}
}
});

}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2538,9 +2538,9 @@ file.editProvenanceDialog.tip=Provenance is a record of the origin of your data
file.editProvenanceDialog.uploadSuccess=Upload complete
file.editProvenanceDialog.uploadError=An error occurred during upload and parsing of your provenance file.
file.editProvenanceDialog.noEntitiesError=The uploaded provenance file does not contain any entities that can be related to your Data File.
file.editProvenanceDialog.invalidSchemaError=The uploaded provenance file does not comply with the W3C Provenance standard.
file.editProvenanceDialog.invalidSchemaError=The uploaded provenance file does not comply with the PROV-JSON specification.
file.editProvenanceDialog.bundleFile=Provenance File
file.editProvenanceDialog.bundleFile.instructions=File must be JSON format and follow the <a href="https://www.w3.org/Submission/2013/SUBM-prov-json-20130424/" target="_blank">W3C standard</a>.
file.editProvenanceDialog.bundleFile.instructions=File must be in JSON format and follow the <a href="https://www.w3.org/Submission/2013/SUBM-prov-json-20130424/" target="_blank">PROV-JSON specification</a>.
file.editProvenanceDialog.bundleFile.alreadyPublished=This Provenance File has been published and cannot be replaced or removed.
file.editProvenanceDialog.bundleEntity=Data File Entity
file.editProvenanceDialog.bundleEntity.placeholder=Connect entity...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testProvValidator() {
" }\n" +
"}";

assertTrue(provUtilBean.isProvValid(validJsonString));
assertTrue(provUtilBean.isProvValid(validJsonString).isEmpty());

//This string has the "entity" section misnamed to "entitddd"
String invalidJsonString = "{\n" +
Expand Down Expand Up @@ -102,7 +102,7 @@ public void testProvValidator() {
" }\n" +
"}";

assertFalse(provUtilBean.isProvValid(invalidJsonString));
assertFalse(provUtilBean.isProvValid(invalidJsonString).isEmpty());

}

Expand Down
Loading