Search in sources :

Example 1 with TrellisUtils

use of org.trellisldp.api.TrellisUtils in project trellis by trellis-ldp.

the class MutatingLdpHandler method emitNotification.

/**
 * Emit notifications for the change.
 * @param identifier the resource identifier
 * @param activityType the activity type
 * @param resourceType the resource type
 * @param revision the resource revision
 * @return the next completion stage
 */
protected CompletionStage<Void> emitNotification(final IRI identifier, final IRI activityType, final IRI resourceType, final String revision) {
    // Always notify about updates for the resource in question
    final IRI notificationResourceType = getExtensionGraphName() != null ? LDP.RDFSource : resourceType;
    getServices().getNotificationService().emit(new SimpleNotification(getUrl(identifier, resourceType), getSession().getAgent(), List.of(PROV.Activity, activityType), ldpResourceTypes(notificationResourceType).collect(toList()), revision != null ? generateEtag(revision).getValue() : null));
    // Further notifications are only relevant for non-extension resources
    if (getExtensionGraphName() == null) {
        // notify about the member resource (if it exists)
        if (AS.Update.equals(activityType) && LDP.IndirectContainer.equals(getParentModel())) {
            return emitMembershipUpdateNotification();
        // If this was a creation or deletion, and the parent is some form of container,
        // notify about the parent resource, too
        } else if (AS.Create.equals(activityType) || AS.Delete.equals(activityType)) {
            final IRI model = getParentModel();
            final IRI id = getParentIdentifier();
            if (isContainer(model)) {
                getServices().getNotificationService().emit(new SimpleNotification(getUrl(id, model), getSession().getAgent(), List.of(PROV.Activity, AS.Update), ldpResourceTypes(model).collect(toList()), generateEtag(parent.getRevision()).getValue()));
                // notify about that membership resource, too (if it exists)
                if (!parent.getMembershipResource().map(TrellisUtils::normalizeIdentifier).filter(isEqual(id)).isPresent()) {
                    return allOf(getServices().getResourceService().touch(id).toCompletableFuture(), emitMembershipUpdateNotification().toCompletableFuture());
                }
                return getServices().getResourceService().touch(id);
            }
        }
    }
    return completedFuture(null);
}
Also used : IRI(org.apache.commons.rdf.api.IRI) SimpleNotification(org.trellisldp.common.SimpleNotification) TrellisUtils(org.trellisldp.api.TrellisUtils)

Aggregations

IRI (org.apache.commons.rdf.api.IRI)1 TrellisUtils (org.trellisldp.api.TrellisUtils)1 SimpleNotification (org.trellisldp.common.SimpleNotification)1