annotation_service/commit

FIXED: broken named graph logic of target annotation causing delete's to fail

authorJacco van Ossenbruggen
Thu Sep 18 23:31:24 2014 +0200
committerJacco van Ossenbruggen
Thu Sep 18 23:31:24 2014 +0200
commit23ee1d298dd099dfdc3fd51c03da74067897c7da
treeea63d1475ee0b2adf410bda4768d5dce7c2ccd6a
parent24aee2110020976f61057d57ff7fc9bf6e6a389e
Diff style: patch stat
diff --git a/api/annotation.pl b/api/annotation.pl
index 9652a1e..58cf92b 100644
--- a/api/annotation.pl
+++ b/api/annotation.pl
@@ -136,11 +136,10 @@ http_remove_annotation(Request) :-
 	user_url(User),
 
 	rdf_has(Annotation, oa:hasBody, Body),
-	rdf_get_annotation_target(Annotation, TargetURI),
-	Graph = TargetURI,
+	rdf_get_annotation_target(Annotation, Graph),
 	!,
-	format(atom(CommitComment), 'rm annotation: ~w on ~w~n~n~w', [Body, TargetURI, UserComment]),
-	with_mutex(TargetURI,
+	format(atom(CommitComment), 'rm annotation: ~w on ~w~n~n~w', [Body, Graph, UserComment]),
+	with_mutex(Graph,
 		   (   rdf_remove_annotation(Annotation),
 		       remove_meta_annotations(Annotation),
 		       commit_when_needed(Graph, User, CommitComment, Head))),
diff --git a/lib/oa_annotation.pl b/lib/oa_annotation.pl
index 3eb6852..fdbfcea 100644
--- a/lib/oa_annotation.pl
+++ b/lib/oa_annotation.pl
@@ -15,7 +15,8 @@ literal body tags.
 @author Jacco van Ossenbruggen
 @license LGPL
 */
-
+:- use_module(library(lists)).
+:- use_module(library(option)).
 :- use_module(library(semweb/rdf_db)).
 :- use_module(library(semweb/rdfs)).
 :- use_module(library(semweb/rdf_label)).
@@ -29,8 +30,10 @@ literal body tags.
 	normalize_object(r,o,o),
 	rdf_has_graph(r,r,r,r).
 
-:- rdf_register_ns(oa_target,   'http://localhost/.well-known/genid/oa/target/target_').
-:- rdf_register_ns(oa_selector, 'http://localhost/.well-known/genid/oa/target/selector_').
+:- rdf_register_ns(oa_target,
+		   'http://localhost/.well-known/genid/oa/target/target_').
+:- rdf_register_ns(oa_selector,
+		   'http://localhost/.well-known/genid/oa/target/selector_').
 
 upgrade_property_name(annotated, annotatedAt).
 upgrade_property_name(annotator, annotatedBy).
@@ -235,14 +238,19 @@ rdf_get_annotation(Annotation, Props) :-
 %%	rdf_get_annotation_target(+Annotation, -TargetUri) is semidet.
 %%	rdf_get_annotation_target(-Annotation, +TargetUri) is nondet.
 %
-%	Get Target uri, abstracting away OA selector stuff
+%	Get Target uri, abstracting away OA selector stuff.
+%	Prefer direct Target over oa:hasSource of oa:SpecificResource.
+rdf_get_annotation_target(Annotation, TargetUri) :-
+	ground(Annotation), !,
+	rdf_has(Annotation, oa:hasTarget, TargetUri),
+	\+ rdfs_individual_of(TargetUri, oa:'SpecificResource').
+
 rdf_get_annotation_target(Annotation, TargetUri) :-
 	ground(Annotation), !,
 	rdf_has(Annotation, oa:hasTarget, TargetNode),
-	(   rdfs_individual_of(TargetNode, oa:'SpecificResource')
-	->  rdf_has(TargetNode, oa:hasSource, TargetUri)
-	;   TargetNode = TargetUri
-	).
+	rdfs_individual_of(TargetNode, oa:'SpecificResource'),
+	rdf_has(TargetNode, oa:hasSource, TargetUri).
+
 rdf_get_annotation_target(Annotation, TargetUri) :-
 	ground(TargetUri),
 	rdf_has(TargetNode, oa:hasSource, TargetUri),