Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial fix for 404 on missing entity #161

Merged
merged 2 commits into from
Oct 17, 2022
Merged
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
4 changes: 2 additions & 2 deletions src/main/java/com/epimorphics/registry/RegRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public static void main(String[] args) throws Exception {

tomcat.setBaseDir(".");

// String contextPath = "/registry"; // Use for local testing without nginx/apache front end reverse proxy
String contextPath = "/ldregistry";
String contextPath = "/registry"; // Use for local testing without nginx/apache front end reverse proxy
// String contextPath = "/ldregistry";

File rootF = new File(root);
if (!rootF.exists()) {
Expand Down
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>
.