Skip to content

Commit 2bccfa7

Browse files
committed
Use LDP type of the deleted resource in events
Resolves #398 When a DELETE request completes, the notification will contain the rdf:type of the deleted resource, rather than the generic ldp:Resource. In fact, all relevant LDP types will be published in notifications
1 parent 5c9ab53 commit 2bccfa7

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

components/test/src/main/java/org/trellisldp/test/EventTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ default void testReceiveDeleteMessage() {
215215
try (final Response res = target(resource).request().header(AUTHORIZATION, buildJwt(agent2, getJwtSecret()))
216216
.delete()) {
217217
assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Verify a successful LDP-RS DELETE response");
218-
assertAll("Check the LDP-BC parent", checkResourceParentLdpBC(resource, agent2, AS.Delete, LDP.Resource));
218+
assertAll("Check the LDP-BC parent", checkResourceParentLdpBC(resource, agent2, AS.Delete, LDP.RDFSource));
219219
}
220220
}
221221

@@ -261,7 +261,7 @@ default void testReceiveDeleteMessageDC() {
261261
.delete()) {
262262
assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful LDP-RS DELETE");
263263
assertAll("Check the LDP-DC parent resource",
264-
checkResourceParentLdpDC(resource, agent2, AS.Delete, LDP.Resource, LDP.Container));
264+
checkResourceParentLdpDC(resource, agent2, AS.Delete, LDP.RDFSource, LDP.Container));
265265
}
266266
}
267267

@@ -343,7 +343,7 @@ default void testReceiveDeleteMessageIC() {
343343
.delete()) {
344344
assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful DELETE in an LDP-IC");
345345
assertAll("Check the LDP-IC parent resource",
346-
checkResourceParentLdpIC(resource, agent2, AS.Delete, LDP.Resource, LDP.Container));
346+
checkResourceParentLdpIC(resource, agent2, AS.Delete, LDP.RDFSource, LDP.Container));
347347
}
348348
}
349349

core/http/src/main/java/org/trellisldp/http/impl/DeleteHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private CompletionStage<Void> handleDeletion(final TrellisDataset mutable,
127127
return handleAclDeletion(mutable, immutable);
128128
}
129129
return handleResourceDeletion(immutable).thenCompose(future ->
130-
emitEvent(getInternalId(), AS.Delete, LDP.Resource));
130+
emitEvent(getInternalId(), AS.Delete, getResource().getInteractionModel()));
131131
}
132132

133133
private CompletionStage<Void> handleAclDeletion(final TrellisDataset mutable,

core/http/src/main/java/org/trellisldp/http/impl/MutatingLdpHandler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static javax.ws.rs.core.Response.status;
2828
import static org.slf4j.LoggerFactory.getLogger;
2929
import static org.trellisldp.api.TrellisUtils.toQuad;
30+
import static org.trellisldp.http.impl.HttpUtils.ldpResourceTypes;
3031
import static org.trellisldp.http.impl.HttpUtils.skolemizeQuads;
3132
import static org.trellisldp.http.impl.HttpUtils.skolemizeTriples;
3233

@@ -187,7 +188,7 @@ protected void readEntityIntoDataset(final IRI graphName, final RDFSyntax syntax
187188
protected CompletionStage<Void> emitEvent(final IRI identifier, final IRI activityType, final IRI resourceType) {
188189
// Always notify about updates for the resource in question
189190
getServices().getEventService().emit(new SimpleEvent(getUrl(identifier), getSession().getAgent(),
190-
asList(PROV.Activity, activityType), asList(resourceType)));
191+
asList(PROV.Activity, activityType), ldpResourceTypes(resourceType).collect(toList())));
191192
// If this was an update and the parent is an ldp:IndirectContainer,
192193
// notify about the member resource (if it exists)
193194
if (AS.Update.equals(activityType) && LDP.IndirectContainer.equals(getParentModel())) {
@@ -199,7 +200,8 @@ protected CompletionStage<Void> emitEvent(final IRI identifier, final IRI activi
199200
final IRI id = getParentIdentifier();
200201
if (HttpUtils.isContainer(model)) {
201202
getServices().getEventService().emit(new SimpleEvent(getUrl(id),
202-
getSession().getAgent(), asList(PROV.Activity, AS.Update), asList(model)));
203+
getSession().getAgent(), asList(PROV.Activity, AS.Update),
204+
ldpResourceTypes(model).collect(toList())));
203205
// If the parent's membership resource is different than the parent itself,
204206
// notify about that membership resource, too (if it exists)
205207
if (!Objects.equals(id, getParentMembershipResource())) {
@@ -313,7 +315,7 @@ private CompletionStage<Void> emitMembershipUpdateEvent() {
313315
if (nonNull(res.getIdentifier())) {
314316
getServices().getEventService().emit(new SimpleEvent(getUrl(res.getIdentifier()),
315317
getSession().getAgent(), asList(PROV.Activity, AS.Update),
316-
asList(res.getInteractionModel())));
318+
ldpResourceTypes(res.getInteractionModel()).collect(toList())));
317319
}
318320
}).toCompletableFuture());
319321
}

0 commit comments

Comments
 (0)