changeset 58:f5c0e6df7e88

made uri prefixes in store configurable.
author casties
date Tue, 20 Nov 2012 18:23:52 +0100
parents 4efb21cf0ce0
children e2f86ef9b871
files src/main/java/de/mpiwg/itgroup/annotations/Actor.java src/main/java/de/mpiwg/itgroup/annotations/NS.java src/main/java/de/mpiwg/itgroup/annotations/Tag.java src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotationsByTags.java src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorTags.java src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java src/main/webapp/WEB-INF/serverconfig.property.template
diffstat 9 files changed, 49 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotations/Actor.java	Tue Nov 20 17:56:35 2012 +0100
+++ b/src/main/java/de/mpiwg/itgroup/annotations/Actor.java	Tue Nov 20 18:23:52 2012 +0100
@@ -4,6 +4,7 @@
 package de.mpiwg.itgroup.annotations;
 
 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
+import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
 
 /**
  * @author casties
@@ -111,9 +112,9 @@
      */
     public static String getIdFromUri(String uri, boolean isGroup) {
         String id = null;
-        String prefix = NS.MPIWG_PERSONS_URL;
+        String prefix = BaseRestlet.PERSONS_URI_PREFIX;
         if (isGroup) {
-            prefix = NS.MPIWG_GROUPS_URL;
+            prefix = BaseRestlet.GROUPS_URI_PREFIX;
         }
         if (uri != null && uri.startsWith(prefix)) {
             id = uri.replace(prefix, "");
@@ -129,9 +130,9 @@
      */
     public static String getUriFromId(String id, boolean isGroup) {
         String uri = null;
-        String prefix = NS.MPIWG_PERSONS_URL;
+        String prefix = BaseRestlet.PERSONS_URI_PREFIX;
         if (isGroup) {
-            prefix = NS.MPIWG_GROUPS_URL;
+            prefix = BaseRestlet.GROUPS_URI_PREFIX;
         }
         if (id != null && !id.startsWith("http://")) {
             uri = prefix + id;
--- a/src/main/java/de/mpiwg/itgroup/annotations/NS.java	Tue Nov 20 17:56:35 2012 +0100
+++ b/src/main/java/de/mpiwg/itgroup/annotations/NS.java	Tue Nov 20 18:23:52 2012 +0100
@@ -1,9 +1,6 @@
 package de.mpiwg.itgroup.annotations;
 
 public class NS {
-    public static final String MPIWG_PERSONS_URL = "http://entities.mpiwg-berlin.mpg.de/persons/";
-    public static final String MPIWG_TAGS_URL = "http://entities.mpiwg-berlin.mpg.de/tags/";
-    public static final String MPIWG_GROUPS_URL = "http://entities.mpiwg-berlin.mpg.de/groups/";
     public static final String OAC_NS = "http://www.openannotation.org/ns/";
     public static final String CNT_NS = "http://www.w3.org/2011/content#";
     public static final String DCTERMS_NS = "http://www.purl.org/dc/terms/";
--- a/src/main/java/de/mpiwg/itgroup/annotations/Tag.java	Tue Nov 20 17:56:35 2012 +0100
+++ b/src/main/java/de/mpiwg/itgroup/annotations/Tag.java	Tue Nov 20 18:23:52 2012 +0100
@@ -1,5 +1,7 @@
 package de.mpiwg.itgroup.annotations;
 
+import de.mpiwg.itgroup.annotations.restlet.BaseRestlet;
+
 /**
  * @author dwinter
  *
@@ -18,7 +20,7 @@
 		}
 		public String getUri() {
 			if (uri==null){
-				return NS.MPIWG_TAGS_URL+getId(); // erzeuge uri aus if falls keine ID
+				return BaseRestlet.TAGS_URI_PREFIX+getId(); // erzeuge uri aus if falls keine ID
 			}
 			return uri;
 		}
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotationsByTags.java	Tue Nov 20 17:56:35 2012 +0100
+++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotationsByTags.java	Tue Nov 20 18:23:52 2012 +0100
@@ -14,7 +14,6 @@
 import org.restlet.resource.Get;
 
 import de.mpiwg.itgroup.annotations.Annotation;
-import de.mpiwg.itgroup.annotations.NS;
 import de.mpiwg.itgroup.annotations.Person;
 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
 import de.mpiwg.itgroup.annotations.restlet.utils.JSONObjectComparator;
@@ -55,7 +54,7 @@
         logger.debug("annotation-id=" + id);
         
         AnnotationStore store = getAnnotationStore();
-  	  	String tagUri=NS.MPIWG_TAGS_URL+id;
+        String tagUri = BaseRestlet.TAGS_URI_PREFIX + id;
         List<Annotation> annotations = store.getAnnotationsByTag(tagUri);
         
 		//JSONArray results = new JSONArray();
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java	Tue Nov 20 17:56:35 2012 +0100
+++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java	Tue Nov 20 18:23:52 2012 +0100
@@ -37,7 +37,6 @@
 import de.mpiwg.itgroup.annotations.Annotation;
 import de.mpiwg.itgroup.annotations.Annotation.FragmentTypes;
 import de.mpiwg.itgroup.annotations.Group;
-import de.mpiwg.itgroup.annotations.NS;
 import de.mpiwg.itgroup.annotations.Person;
 import de.mpiwg.itgroup.annotations.Resource;
 import de.mpiwg.itgroup.annotations.Target;
@@ -521,7 +520,7 @@
             if (username.startsWith("http")) {
                 userUri = username;
             } else {
-                userUri = NS.MPIWG_PERSONS_URL + username;
+                userUri = BaseRestlet.PERSONS_URI_PREFIX + username;
             }
         }
         // TODO: should we overwrite the creator?
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java	Tue Nov 20 17:56:35 2012 +0100
+++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java	Tue Nov 20 18:23:52 2012 +0100
@@ -14,7 +14,7 @@
  */
 public class AnnotatorRestlet extends BaseRestlet {
 
-    public final String version = "AnnotationManagerN4J/Annotator 0.2.3";
+    public final String version = "AnnotationManagerN4J/Annotator 0.2.4";
 
     public static Logger logger = Logger.getLogger(AnnotatorRestlet.class);
 
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorTags.java	Tue Nov 20 17:56:35 2012 +0100
+++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorTags.java	Tue Nov 20 18:23:52 2012 +0100
@@ -14,7 +14,6 @@
 import org.restlet.representation.Representation;
 import org.restlet.resource.Get;
 
-import de.mpiwg.itgroup.annotations.NS;
 import de.mpiwg.itgroup.annotations.Tag;
 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
 
@@ -59,7 +58,7 @@
     
     protected Representation getTag(String id){
     	  AnnotationStore store = getAnnotationStore();
-    	  String tagUri=NS.MPIWG_TAGS_URL+id;
+    	  String tagUri = BaseRestlet.TAGS_URI_PREFIX + id;
           Node tagNode = store.getTagNodeByUri(tagUri);
           Tag tag = store.createTagFromNode(tagNode);
           JSONObject jo = new JSONObject();
--- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java	Tue Nov 20 17:56:35 2012 +0100
+++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java	Tue Nov 20 18:23:52 2012 +0100
@@ -78,10 +78,28 @@
     /**
      * run in authorization mode i.e. with tokens.
      */
-    protected boolean authorizationMode = false; 
+    protected boolean authorizationMode = false;
     public static final String AUTHORIZATION_MODE_KEY = "annotationmanager.authorization";
     
     /**
+     * prefix to create uris for tags in store.
+     */
+    public static String TAGS_URI_PREFIX = "";
+    public static final String TAGS_URI_KEY = "annotationmanager.uris.tags";
+
+    /**
+     * prefix to create uris for persons in store.
+     */
+    public static String PERSONS_URI_PREFIX = "";
+    public static final String PERSONS_URI_KEY = "annotationmanager.uris.persons";
+
+    /**
+     * prefix to create uris for groups in store.
+     */
+    public static String GROUPS_URI_PREFIX = ""; 
+    public static final String GROUPS_URI_KEY = "annotationmanager.uris.groups";
+
+    /**
      * constructor
      * 
      * @param context
@@ -184,6 +202,21 @@
                 // store config
                 sc.setAttribute(CONSUMERKEYS_KEY, consumerKeys);
             }
+            /*
+             * read uri prefixes
+             */
+            String pup = (String) sc.getAttribute(PERSONS_URI_KEY);
+            if (pup != null) {
+                BaseRestlet.PERSONS_URI_PREFIX = pup;
+            }
+            String gup = (String) sc.getAttribute(GROUPS_URI_KEY);
+            if (gup != null) {
+                BaseRestlet.GROUPS_URI_PREFIX = gup;
+            }
+            String tup = (String) sc.getAttribute(TAGS_URI_KEY);
+            if (tup != null) {
+                BaseRestlet.TAGS_URI_PREFIX = tup;
+            }
         } else {
             logger.error("Unable to get ServletContext!");
         }
--- a/src/main/webapp/WEB-INF/serverconfig.property.template	Tue Nov 20 17:56:35 2012 +0100
+++ b/src/main/webapp/WEB-INF/serverconfig.property.template	Tue Nov 20 18:23:52 2012 +0100
@@ -5,3 +5,6 @@
 annotationmanager.ldapserver.url = ldap://ldap.mpiwg-berlin.mpg.de/dc=mpiwg-berlin,dc=mpg,dc=de
 annotationmanager.admin.user = adminuser
 annotationmanager.admin.password = adminpw
+annotationmanager.uris.tags = http://entities.mpiwg-berlin.mpg.de/tags/
+annotationmanager.uris.persons = http://entities.mpiwg-berlin.mpg.de/persons/
+annotationmanager.uris.groups = http://entities.mpiwg-berlin.mpg.de/groups/