Skip to content

Commit

Permalink
Merge pull request #161 from UKGovLD/issue-159/fix-404-for-ext-entity
Browse files Browse the repository at this point in the history
Partial fix for 404 on missing entity
  • Loading branch information
simonoakesepimorphics committed Oct 17, 2022
2 parents 55a4d27 + 34b5bad commit e8c6dc3
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/epimorphics/registry/commands/CommandRead.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ public Response doExecute() {
} else if (ri.getEntity() != null) {
m.add( ri.getEntity().getModel() );
}

// Full solution here would also apply this to the case where entityWithMetadata is set
// that's why the check is inject at this point.
// That full solution currently disabled due to test case issues.
// if (graphEntity || entityWithMetadata) {
if (graphEntity ) {
// Validate that the graph contains a matching entity definition with a type property.
// For both plain and graph registered entities this is enforced at registration time.
// If this is an external entity then the graph will not contain a matching root resource
// and we prefer to return a 404 in that case.
if ( ! m.getResource(target).hasProperty(RDF.type) ) {
throw new NotFoundException();
}
}
}

List<Resource> members = (paged) ? new ArrayList<Resource>(length) : new ArrayList<Resource>() ;
Expand Down
18 changes: 15 additions & 3 deletions src/test/java/com/epimorphics/registry/webapi/TestAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
import javax.ws.rs.core.Response;

import org.apache.jena.riot.RDFDataMgr;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.junit.Before;
import org.junit.Test;

import com.epimorphics.rdfutil.QueryUtil;
Expand Down Expand Up @@ -104,6 +101,8 @@ public void testAll() throws IOException {
// Puts red in reg1/red
doItemRegistrationTests();

// Reference red from another register
testCrossRegisterReference();

// Adds external resource reg1/black
doExternalRegistrationTests();
Expand Down Expand Up @@ -265,6 +264,19 @@ private void doRegisterRegistrationTests() {
assertEquals("Register the same again", 403, postFileStatus("test/reg1.ttl", BASE_URL));
}

private void testCrossRegisterReference() {
Response response = postFile("test/reg4.ttl", BASE_URL, "text/turtle");
assertEquals("Register a register", 201, response.getStatus());
assertEquals(201, postFileStatus("test/reference.ttl", BASE_URL + "reg4"));

assertEquals(404, getResponse(BASE_URL + "reg4/reference").getStatus());

Model m = getModelResponse(BASE_URL + "reg4/_reference");
checkModelResponse(m, ROOT_REGISTER + "reg1/red", "test/expected/reference_red.ttl");

assertEquals(303, post(BASE_URL + "reg4?real_delete").getStatus());
}

// Assumes reg1 has been created
// Adds an item (reg1/red) and checks it all looks OK
// Leaves reg1/red in plce
Expand Down
19 changes: 19 additions & 0 deletions test/expected/reference_red.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .

@prefix reg: <http://purl.org/linked-data/registry#> .

<_reference> a reg:RegisterItem;
reg:definition [
reg:entity <http://location.data.gov.uk/reg1/red>;
]
.

<http://location.data.gov.uk/reg1/red> a skos:Concept;
rdfs:label "red"
.

19 changes: 19 additions & 0 deletions test/reference.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .

@prefix reg: <http://purl.org/linked-data/registry#> .

<_reference> a reg:RegisterItem;
reg:definition [
reg:entity <http://location.data.gov.uk/reg1/red>;
]
.

<http://location.data.gov.uk/reg1/red> a skos:Concept;
rdfs:label "red"
.

25 changes: 25 additions & 0 deletions test/reg4.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix version: <http://purl.org/linked-data/version#> .
@prefix ldp: <http://www.w3.org/ns/ldp#> .
@prefix ssd: <http://www.w3.org/ns/sparql-service-description#> .
@prefix vs: <http://www.w3.org/2003/06/sw-vocab-status/ns#> .
@prefix void: <http://rdfs.org/ns/void#> .
@prefix prov: <http://www.w3.org/ns/prov#> .

@prefix reg: <http://purl.org/linked-data/registry#> .

<reg4> a reg:Register, skos:Collection ;
ldp:membershipPredicate skos:member;
rdfs:label "register 4"@en;
dct:description "Example register 4"@en;
reg:owner <http://example.com/department> ;
reg:manager <http://example.com/registryManagementLtd>
.

0 comments on commit e8c6dc3

Please sign in to comment.