annotate src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java @ 50:64aa756c60cc

annotations ui can show and delete annotations now.
author casties
date Thu, 27 Sep 2012 17:12:08 +0200
parents b1fb0d117877
children 4efb21cf0ce0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
1 package de.mpiwg.itgroup.annotations.restlet;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
2
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
3 import java.io.File;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
4 import java.io.FileInputStream;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
5 import java.io.FileNotFoundException;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
6 import java.io.IOException;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
7 import java.io.InputStream;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
8 import java.util.Hashtable;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
9 import java.util.Properties;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
10
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
11 import javax.naming.NamingEnumeration;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
12 import javax.naming.NamingException;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
13 import javax.naming.directory.Attribute;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
14 import javax.naming.directory.DirContext;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
15 import javax.naming.directory.InitialDirContext;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
16 import javax.naming.directory.SearchControls;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
17 import javax.naming.directory.SearchResult;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
18 import javax.servlet.ServletContext;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
19
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
20 import org.apache.log4j.BasicConfigurator;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
21 import org.apache.log4j.Logger;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
22 import org.neo4j.graphdb.GraphDatabaseService;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
23 import org.neo4j.graphdb.factory.GraphDatabaseFactory;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
24 import org.neo4j.kernel.AbstractGraphDatabase;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
25 import org.neo4j.server.WrappingNeoServerBootstrapper;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
26 import org.restlet.Application;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
27 import org.restlet.Context;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
28
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
29 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
30
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
31 public abstract class BaseRestlet extends Application {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
32
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
33 public static Logger logger = Logger.getLogger(BaseRestlet.class);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
34
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
35 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
36 * Properties holding consumer keys and secrets
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
37 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
38 protected Properties consumerKeys;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
39 public String CONSUMER_KEYS_PATH = "WEB-INF/consumerkeys.property";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
40 public static final String CONSUMERKEYS_KEY = "annotationmanager.consumerkeys";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
41
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
42 protected Properties serverConfig;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
43 public String CONFIG_PROPS_PATH = "WEB-INF/serverconfig.property";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
44 public static final String SERVERCONFIG_KEY = "annotationmanager.serverconfig";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
45
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
46 protected GraphDatabaseService graphDb;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
47 public static final String GRAPHDB_KEY = "annotationmanager.graphdb";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
48 public static final String GRAPHDB_PATH_KEY = "annotationmanager.graphdb.path";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
49 public String graphdbPath = "WEB-INF/neo4j-annotation-db";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
50
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
51 protected WrappingNeoServerBootstrapper srv;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
52 public static final String GRAPHDBSRV_KEY = "annotationmanager.graphdb.srv";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
53
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
54 protected AnnotationStore store;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
55 public static final String ANNSTORE_KEY = "annotationmanager.store";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
56
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
57 protected String ldapServerUrl;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
58 public static final String LDAP_SERVER_KEY = "annotationmanager.ldapserver.url";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
59
50
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 22
diff changeset
60 public static final String ADMIN_USER_KEY = "annotationmanager.admin.user";
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 22
diff changeset
61 public static final String ADMIN_PASSWORD_KEY = "annotationmanager.admin.password";
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 22
diff changeset
62
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
63 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
64 * constructor
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
65 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
66 * @param context
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
67 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
68 public BaseRestlet(Context context) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
69 super(context);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
70 configure();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
71 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
72
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
73 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
74 * Configures the restlet.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
75 * Reads serverConfig, consumerKeys and graphDb config from config files and starts graphDb.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
76 * Uses config from webapp context if already initialized.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
77 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
78 protected void configure() {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
79 ServletContext sc = (ServletContext) getContext().getServerDispatcher().getContext().getAttributes()
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
80 .get("org.restlet.ext.servlet.ServletContext");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
81 if (sc != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
82 if (sc.getAttribute("annotationserver.log4j.configured") == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
83 // TODO: is this the right place to run the log4j configurator?
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
84 BasicConfigurator.configure();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
85 sc.setAttribute("annotationserver.log4j.configured", "done");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
86 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
87 logger.info(getVersion() + " starting...");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
88
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
89 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
90 * read config from webapp
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
91 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
92 serverConfig = (Properties) sc.getAttribute(SERVERCONFIG_KEY);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
93 if (serverConfig == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
94 serverConfig = new Properties();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
95 InputStream ps = getResourceAsStream(sc, CONFIG_PROPS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
96 if (ps != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
97 logger.debug("loading config from " + CONFIG_PROPS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
98 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
99 serverConfig.load(ps);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
100 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
101 * read serverconfig options
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
102 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
103 graphdbPath = serverConfig.getProperty(GRAPHDB_PATH_KEY, graphdbPath);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
104 ldapServerUrl = serverConfig.getProperty(LDAP_SERVER_KEY, null);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
105 } catch (IOException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
106 logger.warn("Error loading server config: ", e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
107 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
108 logger.debug("config: " + serverConfig);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
109 } else {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
110 logger.error("Unable to get resource " + CONFIG_PROPS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
111 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
112 // store config
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
113 sc.setAttribute(SERVERCONFIG_KEY, serverConfig);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
114 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
115 // look for database service in context
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
116 graphDb = (GraphDatabaseService) sc.getAttribute(GRAPHDB_KEY);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
117 if (graphDb == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
118 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
119 * open database
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
120 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
121 String dbFn = getResourcePath(sc, graphdbPath);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
122 if (dbFn != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
123 logger.debug("opening DB " + dbFn);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
124 graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbFn);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
125 registerShutdownHook(graphDb);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
126 // store in context
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
127 sc.setAttribute(GRAPHDB_KEY, graphDb);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
128 // AnnotationStore
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
129 store = new AnnotationStore(graphDb);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
130 sc.setAttribute(ANNSTORE_KEY, store);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
131 // admin server
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
132 srv = new WrappingNeoServerBootstrapper((AbstractGraphDatabase) graphDb);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
133 logger.debug("Starting DB admin server...");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
134 // store in context
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
135 sc.setAttribute(GRAPHDBSRV_KEY, srv);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
136 srv.start();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
137 } else {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
138 logger.error("Unable to get resource " + dbFn);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
139 }
22
b1fb0d117877 adding and listing groups via html works now.
casties
parents: 19
diff changeset
140 } else {
b1fb0d117877 adding and listing groups via html works now.
casties
parents: 19
diff changeset
141 // get existing AnnotationStore
b1fb0d117877 adding and listing groups via html works now.
casties
parents: 19
diff changeset
142 store = (AnnotationStore) sc.getAttribute(ANNSTORE_KEY);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
143 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
144 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
145 * read consumerKeys from webapp
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
146 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
147 consumerKeys = (Properties) sc.getAttribute(CONSUMERKEYS_KEY);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
148 if (consumerKeys == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
149 consumerKeys = new Properties();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
150 InputStream ps = getResourceAsStream(sc, CONSUMER_KEYS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
151 if (ps != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
152 logger.debug("loading consumer keys from " + CONSUMER_KEYS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
153 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
154 consumerKeys.load(ps);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
155 } catch (IOException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
156 // TODO Auto-generated catch block
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
157 e.printStackTrace();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
158 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
159 logger.debug("consumer keys: " + consumerKeys);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
160 } else {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
161 logger.error("Unable to get resource " + CONSUMER_KEYS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
162 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
163 // store config
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
164 sc.setAttribute(CONSUMERKEYS_KEY, consumerKeys);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
165 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
166 } else {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
167 logger.error("Unable to get ServletContext!");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
168 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
169 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
170
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
171 public abstract String getVersion();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
172
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
173 /**
19
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
174 * @return the store
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
175 */
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
176 public AnnotationStore getAnnotationStore() {
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
177 return store;
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
178 }
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
179
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
180 /**
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
181 * returns consumer secret for consumer key. returns null if consumer key
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
182 * doesn't exist.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
183 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
184 * @param consumerKey
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
185 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
186 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
187 public String getConsumerSecret(String consumerKey) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
188 return consumerKeys.getProperty(consumerKey);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
189 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
190
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
191 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
192 * Hole den vollen Benutzernamen aus dem LDAP
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
193 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
194 * @param creator
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
195 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
196 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
197 public String getFullNameFromLdap(String creator) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
198 String retString = creator; // falls nichts gefunden wird einfach den
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
199 // creator zurueckgeben
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
200 if (ldapServerUrl == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
201 return retString;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
202 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
203 Hashtable<String, String> env = new Hashtable<String, String>();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
204 String sp = "com.sun.jndi.ldap.LdapCtxFactory";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
205 env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, sp);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
206 env.put(javax.naming.Context.PROVIDER_URL, ldapServerUrl);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
207
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
208 DirContext dctx;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
209 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
210 dctx = new InitialDirContext(env);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
211 } catch (NamingException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
212 logger.error("Error in getFullNameFromLDAP!", e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
213 return retString;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
214 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
215
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
216 String base = "ou=people";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
217
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
218 SearchControls sc = new SearchControls();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
219 String[] attributeFilter = { "cn", "mail" };
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
220 sc.setReturningAttributes(attributeFilter);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
221 sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
222
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
223 String filter = "(uid=" + creator + ")";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
224
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
225 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
226 NamingEnumeration<SearchResult> results = dctx.search(base, filter, sc);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
227 while (results.hasMore()) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
228 SearchResult sr = (SearchResult) results.next();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
229 javax.naming.directory.Attributes attrs = sr.getAttributes();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
230
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
231 Attribute attr = attrs.get("cn");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
232 retString = (String) attr.get();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
233 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
234 } catch (NamingException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
235 logger.error("Error in getFullNameFromLDAP!", e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
236 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
237
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
238 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
239 dctx.close();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
240 } catch (NamingException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
241 logger.error("Error in getFullNameFromLDAP!", e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
242 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
243 return retString;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
244 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
245
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
246 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
247 * returns resource from path (in webapp) as InputStream.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
248 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
249 * @param sc
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
250 * @param path
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
251 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
252 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
253 protected InputStream getResourceAsStream(ServletContext sc, String path) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
254 InputStream ps = sc.getResourceAsStream(path);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
255 if (ps == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
256 // try as file
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
257 File pf = new File(sc.getRealPath(path));
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
258 if (pf != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
259 logger.debug("trying file for: " + pf);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
260 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
261 ps = new FileInputStream(pf);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
262 } catch (FileNotFoundException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
263 logger.error(e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
264 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
265 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
266 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
267 return ps;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
268 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
269
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
270 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
271 * get a real file name for a web app file pathname.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
272 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
273 * If filename starts with "/" its treated as absolute else the path is
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
274 * appended to the base directory of the web-app.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
275 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
276 * @param filename
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
277 * @param sc
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
278 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
279 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
280 public static String getResourcePath(ServletContext sc, String filename) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
281 File f = new File(filename);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
282 // is the filename absolute?
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
283 if (!f.isAbsolute()) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
284 // relative path -> use getRealPath to resolve in webapp
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
285 filename = sc.getRealPath(filename);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
286 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
287 return filename;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
288 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
289
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
290 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
291 * (non-Javadoc)
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
292 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
293 * @see org.restlet.Application#stop()
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
294 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
295 @Override
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
296 public synchronized void stop() throws Exception {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
297 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
298 * trying to clean up databases, not sure if this is the right way...
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
299 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
300 if (srv != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
301 logger.debug("Stopping DB admin server...");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
302 srv.stop();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
303 srv = null;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
304 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
305 if (graphDb != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
306 logger.debug("Stopping DB...");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
307 graphDb.shutdown();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
308 graphDb = null;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
309 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
310 super.stop();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
311 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
312
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
313 private static void registerShutdownHook(final GraphDatabaseService graphDb) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
314 // Registers a shutdown hook for the Neo4j instance so that it
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
315 // shuts down nicely when the VM exits (even if you "Ctrl-C" the
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
316 // running example before it's completed)
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
317 Runtime.getRuntime().addShutdownHook(new Thread() {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
318 @Override
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
319 public void run() {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
320 graphDb.shutdown();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
321 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
322 });
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
323 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
324
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
325 }