# HG changeset patch # User casties # Date 1332410096 -3600 # Node ID 667d98fd28bde1dc032e07a96b4d52e5d632e2ef # Parent 6c7c4140630d6908ef09f95df3e01d51cb91a8e9 working on search and update. diff -r 6c7c4140630d -r 667d98fd28bd src/de/mpiwg/itgroup/annotationManager/RDFHandling/RDFSearcher.java --- a/src/de/mpiwg/itgroup/annotationManager/RDFHandling/RDFSearcher.java Wed Mar 21 18:12:45 2012 +0100 +++ b/src/de/mpiwg/itgroup/annotationManager/RDFHandling/RDFSearcher.java Thu Mar 22 10:54:56 2012 +0100 @@ -10,6 +10,7 @@ import org.restlet.engine.component.ChildContext; import de.mpiwg.itgroup.annotationManager.Errors.TripleStoreSearchError; +import de.mpiwg.itgroup.annotationManager.Errors.TripleStoreStoreError; import de.mpiwg.itgroup.annotationManager.RDFHandling.Convert.Annotation; import de.mpiwg.itgroup.triplestoremanager.exceptions.TripleStoreHandlerException; import de.mpiwg.itgroup.triplestoremanager.owl.TripleStoreHandler; @@ -30,7 +31,98 @@ - /** Sucht im Triplestore nach Annotationen + /** Sucht im Triplestore nach Annotationen. + * + * @param id id der Annotation + * @return + * @throws TripleStoreHandlerException + * @throws TripleStoreSearchError + */ + public List searchById(String id) throws TripleStoreHandlerException, TripleStoreSearchError { + + List retAnnots = new ArrayList(); + ChildContext context = (ChildContext)Context.getCurrent(); + String tripleStoreUser = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUser"); + String tripleStorePW = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUserPassword"); + String connectionURL = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreConnectionURL"); + if (tripleStoreUser == null || tripleStorePW == null || connectionURL == null) { + logger.error(String.format("Missing triplestore parameters! (user=%s pw=%s url=%s)", tripleStoreUser, tripleStorePW, connectionURL)); + throw new TripleStoreStoreError(); + } + + th = new TripleStoreHandler(connectionURL, tripleStoreUser, tripleStorePW); + String queryString=""; + + String whereString = "?s ?p ."; + //whereString +="?s ?link."; +/* String uri = null; + if(uri!=null && !uri.equals("")){ + whereString +=String.format("?s <%s>.",uri);} + else { */ + whereString +=String.format("?s ?uri."); +// } + + whereString +=String.format("?s ?xpointer."); + whereString +=String.format("?s ?annotText."); + +/* String user = null; + if(user!=null && !user.equals("")){ + if (user.startsWith("http")){ + whereString +=String.format("?s <%s>.",user); + } else { + whereString +=String.format("?s \"%s\".",user); + } + } else { */ + whereString +=String.format("?s ?author."); +// } + + whereString +=String.format("?s ?created."); + + whereString +=String.format(" OPTIONAL {?annotText ?text.}"); + + queryString=String.format("select distinct * where {%s}",whereString); + + + logger.debug("RDFSearcher:"+queryString); + + try { + TupleQueryResult results = th.querySPARQL(queryString); + + while (results.hasNext()) { + BindingSet result = results.next(); + String annotUri; + if(uri!=null && !uri.equals("")){ + annotUri=uri; + } else { + annotUri = result.getBinding("uri").getValue().stringValue(); + } + + String annotUser; + if(user!=null && !user.equals("")){ + annotUser=user; + } else { + annotUser = result.getBinding("author").getValue().stringValue(); + } + + String textString=""; + if (result.getBinding("text")!=null){ + textString= result.getBinding("text").getValue().stringValue(); + } + Annotation annot = new Annotation(result.getBinding("xpointer").getValue().stringValue(), + annotUser, result.getBinding("created").getValue().stringValue(), + textString, null, + annotUri,result.getBinding("s").getValue().stringValue()); + retAnnots.add(annot); + } + } catch (Exception e) { + e.printStackTrace(); + throw new TripleStoreSearchError(); + } + // TODO Auto-generated method stub + return retAnnots; + } + + /** Sucht im Triplestore nach Annotationen * @param uri Adresse der Annotierten Ressource, in der Regel nicht mit dem xpointer, sonder die URI der kompletten Ressource oder NULL oder leer * @param user Author der Annotationen, entweder als uri der Person oder ein Username, je nachdem wie die Annotatinen angelegt wurden. * @param limit @@ -39,15 +131,20 @@ * @throws TripleStoreHandlerException * @throws TripleStoreSearchError */ - public List search(String uri, String user, String limit, + public List searchByUriUser(String uri, String user, String limit, String offset) throws TripleStoreHandlerException, TripleStoreSearchError { List retAnnots = new ArrayList(); ChildContext context = (ChildContext)Context.getCurrent(); String tripleStoreUser = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUser"); String tripleStorePW = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUserPassword"); + String connectionURL = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreConnectionURL"); + if (tripleStoreUser == null || tripleStorePW == null || connectionURL == null) { + logger.error(String.format("Missing triplestore parameters! (user=%s pw=%s url=%s)", tripleStoreUser, tripleStorePW, connectionURL)); + throw new TripleStoreStoreError(); + } - th = new TripleStoreHandler("jdbc:virtuoso://virtuoso.mpiwg-berlin.mpg.de:1111", tripleStoreUser, tripleStorePW);//TODO should go into config + th = new TripleStoreHandler(connectionURL, tripleStoreUser, tripleStorePW); String queryString=""; String whereString = "?s ?p ."; diff -r 6c7c4140630d -r 667d98fd28bd src/de/mpiwg/itgroup/annotationManager/restlet/AddAndReadAnnotations.java --- a/src/de/mpiwg/itgroup/annotationManager/restlet/AddAndReadAnnotations.java Wed Mar 21 18:12:45 2012 +0100 +++ b/src/de/mpiwg/itgroup/annotationManager/restlet/AddAndReadAnnotations.java Thu Mar 22 10:54:56 2012 +0100 @@ -100,7 +100,7 @@ "%s%s%s%s%s"; try { - List annots=searcher.search(uri,user,limit,offset); + List annots=searcher.searchByUriUser(uri,user,limit,offset); for (Convert.Annotation annot:annots){ @@ -200,7 +200,7 @@ JSONArray ja; try { - List annots=searcher.search(uri,user,limit,offset); + List annots=searcher.searchByUriUser(uri,user,limit,offset); ja = new JSONArray(); for (Convert.Annotation annot:annots){ diff -r 6c7c4140630d -r 667d98fd28bd src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorAnnotations.java --- a/src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorAnnotations.java Wed Mar 21 18:12:45 2012 +0100 +++ b/src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorAnnotations.java Thu Mar 22 10:54:56 2012 +0100 @@ -73,7 +73,7 @@ JSONArray results; try { - List annots = searcher.search(uri, user, limit, offset); + List annots = searcher.searchByUriUser(uri, user, limit, offset); results = new JSONArray(); for (Convert.Annotation annot : annots) { diff -r 6c7c4140630d -r 667d98fd28bd src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorSearch.java --- a/src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorSearch.java Wed Mar 21 18:12:45 2012 +0100 +++ b/src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorSearch.java Thu Mar 22 10:54:56 2012 +0100 @@ -65,7 +65,7 @@ JSONArray ja; try { - List annots = searcher.search(uri, user, limit, offset); + List annots = searcher.searchByUriUser(uri, user, limit, offset); ja = new JSONArray(); for (Convert.Annotation annot : annots) { @@ -141,7 +141,7 @@ + "%s%s%s%s%s"; try { - List annots = searcher.search(uri, user, limit, offset); + List annots = searcher.searchByUriUser(uri, user, limit, offset); for (Convert.Annotation annot : annots) { diff -r 6c7c4140630d -r 667d98fd28bd src/de/mpiwg/itgroup/annotationManager/restlet/SearchAnnotations.java --- a/src/de/mpiwg/itgroup/annotationManager/restlet/SearchAnnotations.java Wed Mar 21 18:12:45 2012 +0100 +++ b/src/de/mpiwg/itgroup/annotationManager/restlet/SearchAnnotations.java Thu Mar 22 10:54:56 2012 +0100 @@ -97,7 +97,7 @@ "%s%s%s%s%s"; try { - List annots=searcher.search(uri,user,limit,offset); + List annots=searcher.searchByUriUser(uri,user,limit,offset); for (Convert.Annotation annot:annots){ @@ -196,7 +196,7 @@ JSONArray ja; try { - List annots=searcher.search(uri,user,limit,offset); + List annots=searcher.searchByUriUser(uri,user,limit,offset); ja = new JSONArray(); for (Convert.Annotation annot:annots){