Skip to content

Commit

Permalink
Merge pull request #5157 from IQSS/5154-prov-validator-tweaks
Browse files Browse the repository at this point in the history
5154 prov validator tweaks
  • Loading branch information
kcondon authored Oct 10, 2018
2 parents bae6d89 + b42df4e commit 8c01a38
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Prov.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public Response addProvJson(String body, @PathParam("id") String idSupplied, @Qu

@DELETE
@Path("{id}/prov-json")
//MAD: SHOULD NOT WORK ON PUBLISHED
public Response deleteProvJson(String body, @PathParam("id") String idSupplied) {
if(!systemConfig.isProvCollectionEnabled()) {
return error(FORBIDDEN, BundleUtil.getStringFromBundle("api.prov.error.provDisabled"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,139 @@ public boolean isProvValid(String jsonInput) {
//Pulled from https://www.w3.org/Submission/2013/SUBM-prov-json-20130424/schema
//Not the prettiest way of accessing the schema, but loading the .json file as an external resource
//turned out to be very painful, especially when also trying to exercise it via unit tests
//
//To solve https://github.com/IQSS/dataverse/issues/5154 , the provenance schema
//here was updated to include the "core schema" values being downloaded by the "id" tag.
//If this schema needs to be updated (as of 2018, it hadn't been since 2013) this will need
//to be done manually again or we'll need to pull both files and store them on disk.
//The later option was not done previously because we couldn't get the same files to be
//referenced by the code and our junit tests.
private static final String provSchema =
"{\n" +
" \"id\": \"http://provenance.ecs.soton.ac.uk/prov-json/schema#\",\n" +
" \"id\": \"\",\n" +
" \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n" +
" \"description\": \"Schema for a PROV-JSON document\",\n" +
" \"type\": \"object\",\n" +
" \"additionalProperties\": false,\n" +
" \"dependencies\": {\n" +
" \"exclusiveMaximum\": [ \"maximum\" ],\n" +
" \"exclusiveMinimum\": [ \"minimum\" ]\n" +
" },"+
" \"default\": {},\n" +
" \"properties\": {\n" +
" \"id\": {\n" +
" \"type\": \"string\"\n" +
" },\n" +
" \"$schema\": {\n" +
" \"type\": \"string\"\n" +
" },\n" +
" \"title\": {\n" +
" \"type\": \"string\"\n" +
" },\n" +
" \"description\": {\n" +
" \"type\": \"string\"\n" +
" },\n" +
" \"default\": {},\n" +
" \"multipleOf\": {\n" +
" \"type\": \"number\",\n" +
" \"minimum\": 0,\n" +
" \"exclusiveMinimum\": true\n" +
" },\n" +
" \"maximum\": {\n" +
" \"type\": \"number\"\n" +
" },\n" +
" \"exclusiveMaximum\": {\n" +
" \"type\": \"boolean\",\n" +
" \"default\": false\n" +
" },\n" +
" \"minimum\": {\n" +
" \"type\": \"number\"\n" +
" },\n" +
" \"exclusiveMinimum\": {\n" +
" \"type\": \"boolean\",\n" +
" \"default\": false\n" +
" },\n" +
" \"maxLength\": { \"$ref\": \"#/definitions/positiveInteger\" },\n" +
" \"minLength\": { \"$ref\": \"#/definitions/positiveIntegerDefault0\" },\n" +
" \"pattern\": {\n" +
" \"type\": \"string\",\n" +
" \"format\": \"regex\"\n" +
" },\n" +
" \"additionalItems\": {\n" +
" \"anyOf\": [\n" +
" { \"type\": \"boolean\" },\n" +
" { \"$ref\": \"#\" }\n" +
" ],\n" +
" \"default\": {}\n" +
" },\n" +
" \"items\": {\n" +
" \"anyOf\": [\n" +
" { \"$ref\": \"#\" },\n" +
" { \"$ref\": \"#/definitions/schemaArray\" }\n" +
" ],\n" +
" \"default\": {}\n" +
" },\n" +
" \"maxItems\": { \"$ref\": \"#/definitions/positiveInteger\" },\n" +
" \"minItems\": { \"$ref\": \"#/definitions/positiveIntegerDefault0\" },\n" +
" \"uniqueItems\": {\n" +
" \"type\": \"boolean\",\n" +
" \"default\": false\n" +
" },\n" +
" \"maxProperties\": { \"$ref\": \"#/definitions/positiveInteger\" },\n" +
" \"minProperties\": { \"$ref\": \"#/definitions/positiveIntegerDefault0\" },\n" +
" \"required\": { \"$ref\": \"#/definitions/stringArray\" },\n" +
" \"additionalProperties\": {\n" +
" \"anyOf\": [\n" +
" { \"type\": \"boolean\" },\n" +
" { \"$ref\": \"#\" }\n" +
" ],\n" +
" \"default\": {}\n" +
" },\n" +
" \"definitions\": {\n" +
" \"type\": \"object\",\n" +
" \"additionalProperties\": { \"$ref\": \"#\" },\n" +
" \"default\": {}\n" +
" },\n" +
" \"properties\": {\n" +
" \"type\": \"object\",\n" +
" \"additionalProperties\": { \"$ref\": \"#\" },\n" +
" \"default\": {}\n" +
" },\n" +
" \"patternProperties\": {\n" +
" \"type\": \"object\",\n" +
" \"additionalProperties\": { \"$ref\": \"#\" },\n" +
" \"default\": {}\n" +
" },\n" +
" \"dependencies\": {\n" +
" \"type\": \"object\",\n" +
" \"additionalProperties\": {\n" +
" \"anyOf\": [\n" +
" { \"$ref\": \"#\" },\n" +
" { \"$ref\": \"#/definitions/stringArray\" }\n" +
" ]\n" +
" }\n" +
" },\n" +
" \"enum\": {\n" +
" \"type\": \"array\",\n" +
" \"minItems\": 1,\n" +
" \"uniqueItems\": true\n" +
" },\n" +
" \"type\": {\n" +
" \"anyOf\": [\n" +
" { \"$ref\": \"#/definitions/simpleTypes\" },\n" +
" {\n" +
" \"type\": \"array\",\n" +
" \"items\": { \"$ref\": \"#/definitions/simpleTypes\" },\n" +
" \"minItems\": 1,\n" +
" \"uniqueItems\": true\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"format\": { \"type\": \"string\" },\n" +
" \"allOf\": { \"$ref\": \"#/definitions/schemaArray\" },\n" +
" \"anyOf\": { \"$ref\": \"#/definitions/schemaArray\" },\n" +
" \"oneOf\": { \"$ref\": \"#/definitions/schemaArray\" },\n" +
" \"not\": { \"$ref\": \"#\" },\n" +
" \"prefix\": {\n" +
" \"type\": \"object\",\n" +
" \"patternProperties\": {\n" +
Expand Down Expand Up @@ -219,6 +344,27 @@ public boolean isProvValid(String jsonInput) {
" }\n" +
" },\n" +
" \"definitions\": {\n" +
" \"schemaArray\": {\n" +
" \"type\": \"array\",\n" +
" \"minItems\": 1,\n" +
" \"items\": { \"$ref\": \"#\" }\n" +
" },\n" +
" \"positiveInteger\": {\n" +
" \"type\": \"integer\",\n" +
" \"minimum\": 0\n" +
" },\n" +
" \"positiveIntegerDefault0\": {\n" +
" \"allOf\": [ { \"$ref\": \"#/definitions/positiveInteger\" }, { \"default\": 0 } ]\n" +
" },\n" +
" \"simpleTypes\": {\n" +
" \"enum\": [ \"array\", \"boolean\", \"integer\", \"null\", \"number\", \"object\", \"string\" ]\n" +
" },\n" +
" \"stringArray\": {\n" +
" \"type\": \"array\",\n" +
" \"items\": { \"type\": \"string\" },\n" +
" \"minItems\": 1,\n" +
" \"uniqueItems\": true\n" +
" },\n"+
" \"typedLiteral\": {\n" +
" \"title\": \"PROV-JSON Typed Literal\",\n" +
" \"type\": \"object\",\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void handleFileUpload(FileUploadEvent event) throws IOException {

if(!provUtil.isProvValid(provJsonState)) { //if uploaded prov-json does not comply with schema
Logger.getLogger(ProvPopupFragmentBean.class.getName())
.log(Level.SEVERE, BundleUtil.getStringFromBundle("file.editProvenanceDialog.invalidSchemaError"));
.log(Level.INFO, BundleUtil.getStringFromBundle("file.editProvenanceDialog.invalidSchemaError"));
removeJsonAndRelatedData();
JH.addMessage(FacesMessage.SEVERITY_ERROR, JH.localize("file.editProvenanceDialog.invalidSchemaError"));
}
Expand Down
1 change: 0 additions & 1 deletion src/main/webapp/filesFragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@
<span class="glyphicon glyphicon-download-alt"/> #{bundle.download}
</p:commandLink>
</div>
<!--MAD: My work -->
<div jsf:id="downloadButtonBlockTabular" class="btn-group"
jsf:rendered="#{(!(empty DatasetPage.workingVersion.fileMetadatas)
and DatasetPage.workingVersion.fileMetadatas.size() > 1) and DatasetPage.downloadButtonAvailable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ public void testProvNamesNotInsideEntity() throws IOException {
assertFalse(entities.size() > 0);
}

//MAD: write a simple entity test as well, also ensure logging works after getting a real tostring together
//also write a test of parsing different cases, we don't want to catch "fakename" but we do want to catch "rdt:name" and "name"

@Category(NonEssentialTests.class)
@Test
public void testProvNameJsonParserEmptyEntities() throws IOException {
Expand Down

0 comments on commit 8c01a38

Please sign in to comment.