comparison src/de/mpiwg/itgroup/annotationManager/RDFHandling/RDFSearcher.java @ 2:6888ae3287b8

changed to namespace handling for users
author dwinter
date Thu, 24 Nov 2011 11:39:12 +0100
parents 77530be3c747
children 0be9d53a6967
comparison
equal deleted inserted replaced
1:f2f41d0dedf5 2:6888ae3287b8
7 import org.apache.tiles.context.ListAttribute; 7 import org.apache.tiles.context.ListAttribute;
8 import org.openrdf.query.BindingSet; 8 import org.openrdf.query.BindingSet;
9 import org.openrdf.query.TupleQueryResult; 9 import org.openrdf.query.TupleQueryResult;
10 import org.restlet.Context; 10 import org.restlet.Context;
11 import org.restlet.engine.component.ChildContext; 11 import org.restlet.engine.component.ChildContext;
12
13 import sun.security.action.GetBooleanAction;
12 14
13 import de.mpiwg.itgroup.annotationManager.Errors.TripleStoreSearchError; 15 import de.mpiwg.itgroup.annotationManager.Errors.TripleStoreSearchError;
14 import de.mpiwg.itgroup.annotationManager.RDFHandling.Convert.Annotation; 16 import de.mpiwg.itgroup.annotationManager.RDFHandling.Convert.Annotation;
15 import de.mpiwg.itgroup.nimanager.exceptions.TripleStoreHandlerException; 17 import de.mpiwg.itgroup.nimanager.exceptions.TripleStoreHandlerException;
16 import de.mpiwg.itgroup.nimanager.owl.TripleStoreHandler; 18 import de.mpiwg.itgroup.nimanager.owl.TripleStoreHandler;
29 this.context=context; 31 this.context=context;
30 } 32 }
31 33
32 34
33 35
36 /** Sucht im Triplestore nach Annotationen
37 * @param uri Adresse der Annotierten Ressource, in der Regel nicht mit dem xpointer, sonder die URI der kompletten Ressource oder NULL oder leer
38 * @param user Author der Annotationen, entweder als uri der Person oder ein Username, je nachdem wie die Annotatinen angelegt wurden.
39 * @param limit
40 * @param offset
41 * @return
42 * @throws TripleStoreHandlerException
43 * @throws TripleStoreSearchError
44 */
34 public List<Annotation> search(String uri, String user, String limit, 45 public List<Annotation> search(String uri, String user, String limit,
35 String offset) throws TripleStoreHandlerException, TripleStoreSearchError { 46 String offset) throws TripleStoreHandlerException, TripleStoreSearchError {
36 47
37 List<Annotation> retAnnots = new ArrayList<Convert.Annotation>(); 48 List<Annotation> retAnnots = new ArrayList<Convert.Annotation>();
38 ChildContext context = (ChildContext)Context.getCurrent(); 49 ChildContext context = (ChildContext)Context.getCurrent();
44 55
45 String whereString = "?s ?p <http://www.w3.org/2000/10/annotationType#Comment>."; 56 String whereString = "?s ?p <http://www.w3.org/2000/10/annotationType#Comment>.";
46 //whereString +="?s <http://ontologies.mpiwg-berlin.mpg.de/annotations/docuviewerText> ?link."; 57 //whereString +="?s <http://ontologies.mpiwg-berlin.mpg.de/annotations/docuviewerText> ?link.";
47 58
48 if(uri!=null && !uri.equals("")){ 59 if(uri!=null && !uri.equals("")){
49 whereString +=String.format("?s <http://ontologies.mpiwg-berlin.mpg.de/annotations/docuviewerText> <%s>.",uri);} 60 whereString +=String.format("?s <http://ontologies.mpiwg-berlin.mpg.de/annotations/annotatesDocuviewerText> <%s>.",uri);}
50 else { 61 else {
51 whereString +=String.format("?s <http://ontologies.mpiwg-berlin.mpg.de/annotations/docuviewerText> ?uri."); 62 whereString +=String.format("?s <http://ontologies.mpiwg-berlin.mpg.de/annotations/annotatesDocuviewerText> ?uri.");
52 } 63 }
53 whereString +=String.format("?s <http://ontologies.mpiwg-berlin.mpg.de/annotations/textSelection> ?xpointer."); 64 whereString +=String.format("?s <http://ontologies.mpiwg-berlin.mpg.de/annotations/textSelection> ?xpointer.");
54 whereString +=String.format("?s <http://www.w3.org/2000/10/annotation-ns#body> ?annotText."); 65 whereString +=String.format("?s <http://www.w3.org/2000/10/annotation-ns#body> ?annotText.");
55 66
56 if(user!=null && !user.equals("")){ 67 if(user!=null && !user.equals("")){
57 whereString +=String.format("?s <http://www.w3.org/2000/10/annotation-ns#author> \"%s\".",user); 68 if (user.startsWith("http")){
69 whereString +=String.format("?s <http://www.w3.org/2000/10/annotation-ns#author> <%s>.",user);
70 } else {
71 whereString +=String.format("?s <http://www.w3.org/2000/10/annotation-ns#author> \"%s\".",user);
72 }
58 } else { 73 } else {
59 whereString +=String.format("?s <http://www.w3.org/2000/10/annotation-ns#author> ?author."); 74 whereString +=String.format("?s <http://www.w3.org/2000/10/annotation-ns#author> ?author.");
60 } 75 }
61 76
62 whereString +=String.format("?s <http://www.w3.org/2000/10/annotation-ns#created> ?created."); 77 whereString +=String.format("?s <http://www.w3.org/2000/10/annotation-ns#created> ?created.");
89 104
90 105
91 Annotation annot = new Annotation(result.getBinding("xpointer").getValue().stringValue(), 106 Annotation annot = new Annotation(result.getBinding("xpointer").getValue().stringValue(),
92 annotUser, result.getBinding("created").getValue().stringValue(), 107 annotUser, result.getBinding("created").getValue().stringValue(),
93 result.getBinding("text").getValue().stringValue(), null, 108 result.getBinding("text").getValue().stringValue(), null,
94 annotUri); 109 annotUri,result.getBinding("s").getValue().stringValue());
95 retAnnots.add(annot); 110 retAnnots.add(annot);
96 } 111 }
97 } catch (Exception e) { 112 } catch (Exception e) {
98 throw new TripleStoreSearchError(); 113 throw new TripleStoreSearchError();
99 } 114 }