Skip to content

Commit 41cd85a

Browse files
committed
Fixed PATCH case which clears the graph
1 parent 9e45c8a commit 41cd85a

3 files changed

Lines changed: 60 additions & 5 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
initialize_dataset "$END_USER_BASE_URL" "$TMP_END_USER_DATASET" "$END_USER_ENDPOINT_URL"
5+
initialize_dataset "$ADMIN_BASE_URL" "$TMP_ADMIN_DATASET" "$ADMIN_ENDPOINT_URL"
6+
purge_cache "$END_USER_VARNISH_SERVICE"
7+
purge_cache "$ADMIN_VARNISH_SERVICE"
8+
purge_cache "$FRONTEND_VARNISH_SERVICE"
9+
10+
# add agent to the writers group
11+
12+
add-agent-to-group.sh \
13+
-f "$OWNER_CERT_FILE" \
14+
-p "$OWNER_CERT_PWD" \
15+
--agent "$AGENT_URI" \
16+
"${ADMIN_BASE_URL}acl/groups/writers/"
17+
18+
# Test that PATCH with DELETE WHERE that matches no triples does NOT delete the entire graph
19+
# This is a regression test for bug where changedModel.isEmpty() incorrectly triggered graph deletion
20+
21+
# Create test graph URI
22+
test_graph_uri="${ADMIN_BASE_URL}test-graph-$(date +%s)/"
23+
24+
# Create test graph with multiple triples using bin/put.sh
25+
echo "<http://example.org/resource1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/TestClass> .
26+
<http://example.org/resource1> <http://example.org/property1> \"value1\" .
27+
<http://example.org/resource1> <http://example.org/property2> \"value2\" .
28+
<http://example.org/resource2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/OtherClass> .
29+
<http://example.org/resource2> <http://example.org/property3> \"value3\" ." | \
30+
put.sh \
31+
-f "$OWNER_CERT_FILE" \
32+
-p "$OWNER_CERT_PWD" \
33+
-t "application/n-triples" \
34+
"$test_graph_uri"
35+
36+
# Execute PATCH with DELETE WHERE that matches nothing (non-existent triple)
37+
echo "PREFIX ex: <http://example.org/>
38+
PREFIX owl: <http://www.w3.org/2002/07/owl#>
39+
40+
DELETE WHERE { ex:nonExistentResource owl:imports ex:nonExistentOntology }" | \
41+
patch.sh \
42+
-f "$OWNER_CERT_FILE" \
43+
-p "$OWNER_CERT_PWD" \
44+
"$test_graph_uri"
45+
46+
# Verify graph still exists and contains original triples
47+
graph_content=$(get.sh \
48+
-f "$OWNER_CERT_FILE" \
49+
-p "$OWNER_CERT_PWD" \
50+
--accept "application/n-triples" \
51+
"$test_graph_uri")
52+
53+
# Verify essential triples are still present (grep for exact n-triples format)
54+
echo "$graph_content" | grep -q "<http://example.org/resource1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/TestClass>"
55+
echo "$graph_content" | grep -q "<http://example.org/resource1> <http://example.org/property1> \"value1\""
56+
echo "$graph_content" | grep -q "<http://example.org/resource2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/OtherClass>"
57+
echo "$graph_content" | grep -q "<http://example.org/resource2> <http://example.org/property3> \"value3\""

src/main/java/com/atomgraph/linkeddatahub/resource/admin/pkg/UninstallPackage.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ public Response post(@FormParam("package-uri") String packageURI, @HeaderParam("
154154
regenerateMasterStylesheet(endUserApp, pkg);
155155
}
156156

157-
//removeImportFromApplication(endUserApp, packageURI);
158-
159157
if (log.isInfoEnabled()) log.info("Successfully uninstalled package: {}", packageURI);
160158

161159
URI redirectURI = (referer != null) ? referer : endUserApp.getBaseURI();
@@ -169,7 +167,7 @@ public Response post(@FormParam("package-uri") String packageURI, @HeaderParam("
169167
}
170168

171169
/**
172-
* Uninstalls ontology by deleting the package ontology document and removing owl:imports from namespace graph.
170+
* Uninstalls ontology by deleting the package ontology document.
173171
*
174172
* @param app the end-user application
175173
* @param packageOntologyURI the package ONTOLOGY URI

src/main/java/com/atomgraph/linkeddatahub/server/model/impl/DirectGraphStoreImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ public Response patch(UpdateRequest updateRequest)
403403
for (Resource resource : changedResources)
404404
changedModel.add(existingModel.listStatements(resource, null, (RDFNode) null));
405405

406-
// if PATCH results in an empty model, treat it as a DELETE request
407-
if (changedModel.isEmpty()) return delete();
406+
// if PATCH results in an empty graph, treat it as a DELETE request
407+
if (existingModel.isEmpty()) return delete();
408408

409409
validate(changedModel); // this would normally be done transparently by the ValidatingModelProvider
410410
put(dataset.getDefaultModel(), Boolean.FALSE, getURI());

0 commit comments

Comments
 (0)