annotate src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java @ 66:5b568de5ee0d

updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
author casties
date Wed, 19 Feb 2014 14:38:31 +0100
parents 99d9afcfd04d
children 2b1e6df5e21a
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;
66
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
23 import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
24 import org.neo4j.graphdb.factory.GraphDatabaseFactory;
66
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
25 import org.neo4j.graphdb.factory.GraphDatabaseSettings;
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
26 import org.neo4j.kernel.AbstractGraphDatabase;
66
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
27 import org.neo4j.kernel.GraphDatabaseAPI;
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
28 import org.neo4j.server.WrappingNeoServerBootstrapper;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
29 import org.restlet.Application;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
30 import org.restlet.Context;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
31
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
32 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
33
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
34 public abstract class BaseRestlet extends Application {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
35
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
36 public static Logger logger = Logger.getLogger(BaseRestlet.class);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
37
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
38 /**
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
39 * Properties holding consumer keys and secrets.
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
40 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
41 protected Properties consumerKeys;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
42 public String CONSUMER_KEYS_PATH = "WEB-INF/consumerkeys.property";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
43 public static final String CONSUMERKEYS_KEY = "annotationmanager.consumerkeys";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
44
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
45 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
46 * Properties holding server config.
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
47 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
48 protected Properties serverConfig;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
49 public String CONFIG_PROPS_PATH = "WEB-INF/serverconfig.property";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
50 public static final String SERVERCONFIG_KEY = "annotationmanager.serverconfig";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
51
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
52 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
53 * database instance;
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
54 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
55 protected GraphDatabaseService graphDb;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
56 public static final String GRAPHDB_KEY = "annotationmanager.graphdb";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
57 public static final String GRAPHDB_PATH_KEY = "annotationmanager.graphdb.path";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
58 public String graphdbPath = "WEB-INF/neo4j-annotation-db";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
59
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
60 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
61 * database interface server instance.
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
62 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
63 protected WrappingNeoServerBootstrapper srv;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
64 public static final String GRAPHDBSRV_KEY = "annotationmanager.graphdb.srv";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
65
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
66 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
67 * annotation store instance.
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
68 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
69 protected AnnotationStore store;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
70 public static final String ANNSTORE_KEY = "annotationmanager.store";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
71
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
72 /**
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
73 * LDAP server URI (for looking up full user names).
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
74 */
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
75 protected String ldapServerUrl;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
76 public static final String LDAP_SERVER_KEY = "annotationmanager.ldapserver.url";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
77
50
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 22
diff changeset
78 public static final String ADMIN_USER_KEY = "annotationmanager.admin.user";
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 22
diff changeset
79 public static final String ADMIN_PASSWORD_KEY = "annotationmanager.admin.password";
64aa756c60cc annotations ui can show and delete annotations now.
casties
parents: 22
diff changeset
80
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
81 /**
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
82 * run in authorization mode i.e. with tokens.
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
83 */
58
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
84 protected boolean authorizationMode = false;
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
85 public static final String AUTHORIZATION_MODE_KEY = "annotationmanager.authorization";
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
86
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
87 /**
58
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
88 * prefix to create uris for tags in store.
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
89 */
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
90 public static String TAGS_URI_PREFIX = "";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
91 public static final String TAGS_URI_KEY = "annotationmanager.uris.tags";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
92
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
93 /**
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
94 * prefix to create uris for persons in store.
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
95 */
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
96 public static String PERSONS_URI_PREFIX = "";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
97 public static final String PERSONS_URI_KEY = "annotationmanager.uris.persons";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
98
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
99 /**
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
100 * prefix to create uris for groups in store.
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
101 */
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
102 public static String GROUPS_URI_PREFIX = "";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
103 public static final String GROUPS_URI_KEY = "annotationmanager.uris.groups";
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
104
59
e2f86ef9b871 make annotation uri in store configurable. fix npe with no tags.
casties
parents: 58
diff changeset
105 public static final String ANNOTATIONS_URI_KEY = "annotationmanager.uris.annotations";
e2f86ef9b871 make annotation uri in store configurable. fix npe with no tags.
casties
parents: 58
diff changeset
106
58
f5c0e6df7e88 made uri prefixes in store configurable.
casties
parents: 57
diff changeset
107 /**
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
108 * constructor
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
109 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
110 * @param context
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
111 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
112 public BaseRestlet(Context context) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
113 super(context);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
114 configure();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
115 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
116
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
117 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
118 * Configures the restlet.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
119 * Reads serverConfig, consumerKeys and graphDb config from config files and starts graphDb.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
120 * Uses config from webapp context if already initialized.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
121 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
122 protected void configure() {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
123 ServletContext sc = (ServletContext) getContext().getServerDispatcher().getContext().getAttributes()
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
124 .get("org.restlet.ext.servlet.ServletContext");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
125 if (sc != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
126 if (sc.getAttribute("annotationserver.log4j.configured") == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
127 // TODO: is this the right place to run the log4j configurator?
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
128 BasicConfigurator.configure();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
129 sc.setAttribute("annotationserver.log4j.configured", "done");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
130 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
131 logger.info(getVersion() + " starting...");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
132
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
133 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
134 * read config from webapp
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
135 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
136 serverConfig = (Properties) sc.getAttribute(SERVERCONFIG_KEY);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
137 if (serverConfig == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
138 serverConfig = new Properties();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
139 InputStream ps = getResourceAsStream(sc, CONFIG_PROPS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
140 if (ps != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
141 logger.debug("loading config from " + CONFIG_PROPS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
142 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
143 serverConfig.load(ps);
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 serverconfig options
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
146 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
147 graphdbPath = serverConfig.getProperty(GRAPHDB_PATH_KEY, graphdbPath);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
148 ldapServerUrl = serverConfig.getProperty(LDAP_SERVER_KEY, null);
60
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
149 /*
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
150 * uri prefixes
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
151 */
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
152 if (serverConfig.containsKey(PERSONS_URI_KEY)) {
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
153 BaseRestlet.PERSONS_URI_PREFIX = serverConfig.getProperty(PERSONS_URI_KEY);
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
154 }
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
155 if (serverConfig.containsKey(GROUPS_URI_KEY)) {
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
156 BaseRestlet.GROUPS_URI_PREFIX = serverConfig.getProperty(GROUPS_URI_KEY);
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
157 }
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
158 if (serverConfig.containsKey(TAGS_URI_KEY)) {
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
159 BaseRestlet.TAGS_URI_PREFIX = serverConfig.getProperty(TAGS_URI_KEY);
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
160 }
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
161 if (serverConfig.containsKey(ANNOTATIONS_URI_KEY)) {
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
162 AnnotationStore.ANNOTATION_URI_PREFIX = serverConfig.getProperty(ANNOTATIONS_URI_KEY);
99d9afcfd04d configuration of uri prefixes was completely broken.
casties
parents: 59
diff changeset
163 }
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
164 } catch (IOException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
165 logger.warn("Error loading server config: ", e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
166 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
167 logger.debug("config: " + serverConfig);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
168 } else {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
169 logger.error("Unable to get resource " + CONFIG_PROPS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
170 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
171 // store config
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
172 sc.setAttribute(SERVERCONFIG_KEY, serverConfig);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
173 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
174 // look for database service in context
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
175 graphDb = (GraphDatabaseService) sc.getAttribute(GRAPHDB_KEY);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
176 if (graphDb == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
177 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
178 * open database
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
179 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
180 String dbFn = getResourcePath(sc, graphdbPath);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
181 if (dbFn != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
182 logger.debug("opening DB " + dbFn);
66
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
183 GraphDatabaseBuilder graphDbBuilder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(dbFn);
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
184 graphDbBuilder.setConfig(GraphDatabaseSettings.allow_store_upgrade, "true");
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
185 graphDb = graphDbBuilder.newGraphDatabase();
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
186 registerShutdownHook(graphDb);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
187 // store in context
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
188 sc.setAttribute(GRAPHDB_KEY, graphDb);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
189 // AnnotationStore
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
190 store = new AnnotationStore(graphDb);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
191 sc.setAttribute(ANNSTORE_KEY, store);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
192 // admin server
66
5b568de5ee0d updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents: 60
diff changeset
193 srv = new WrappingNeoServerBootstrapper((GraphDatabaseAPI) graphDb);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
194 logger.debug("Starting DB admin server...");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
195 // store in context
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
196 sc.setAttribute(GRAPHDBSRV_KEY, srv);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
197 srv.start();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
198 } else {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
199 logger.error("Unable to get resource " + dbFn);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
200 }
22
b1fb0d117877 adding and listing groups via html works now.
casties
parents: 19
diff changeset
201 } else {
b1fb0d117877 adding and listing groups via html works now.
casties
parents: 19
diff changeset
202 // get existing AnnotationStore
b1fb0d117877 adding and listing groups via html works now.
casties
parents: 19
diff changeset
203 store = (AnnotationStore) sc.getAttribute(ANNSTORE_KEY);
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
204 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
205 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
206 * read consumerKeys from webapp
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
207 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
208 consumerKeys = (Properties) sc.getAttribute(CONSUMERKEYS_KEY);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
209 if (consumerKeys == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
210 consumerKeys = new Properties();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
211 InputStream ps = getResourceAsStream(sc, CONSUMER_KEYS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
212 if (ps != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
213 logger.debug("loading consumer keys from " + CONSUMER_KEYS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
214 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
215 consumerKeys.load(ps);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
216 } catch (IOException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
217 // TODO Auto-generated catch block
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
218 e.printStackTrace();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
219 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
220 logger.debug("consumer keys: " + consumerKeys);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
221 } else {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
222 logger.error("Unable to get resource " + CONSUMER_KEYS_PATH);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
223 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
224 // store config
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
225 sc.setAttribute(CONSUMERKEYS_KEY, consumerKeys);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
226 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
227 } else {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
228 logger.error("Unable to get ServletContext!");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
229 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
230 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
231
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
232 public abstract String getVersion();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
233
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
234 /**
57
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
235 * @return the authorizationMode
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
236 */
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
237 public boolean isAuthorizationMode() {
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
238 return authorizationMode;
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
239 }
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
240
4efb21cf0ce0 new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents: 50
diff changeset
241 /**
19
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
242 * @return the store
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
243 */
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
244 public AnnotationStore getAnnotationStore() {
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
245 return store;
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
246 }
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
247
f0f55ab768c9 more work on HTML UI.
casties
parents: 18
diff changeset
248 /**
18
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
249 * returns consumer secret for consumer key. returns null if consumer key
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
250 * doesn't exist.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
251 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
252 * @param consumerKey
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
253 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
254 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
255 public String getConsumerSecret(String consumerKey) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
256 return consumerKeys.getProperty(consumerKey);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
257 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
258
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
259 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
260 * Hole den vollen Benutzernamen aus dem LDAP
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
261 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
262 * @param creator
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
263 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
264 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
265 public String getFullNameFromLdap(String creator) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
266 String retString = creator; // falls nichts gefunden wird einfach den
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
267 // creator zurueckgeben
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
268 if (ldapServerUrl == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
269 return retString;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
270 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
271 Hashtable<String, String> env = new Hashtable<String, String>();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
272 String sp = "com.sun.jndi.ldap.LdapCtxFactory";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
273 env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, sp);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
274 env.put(javax.naming.Context.PROVIDER_URL, ldapServerUrl);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
275
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
276 DirContext dctx;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
277 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
278 dctx = new InitialDirContext(env);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
279 } catch (NamingException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
280 logger.error("Error in getFullNameFromLDAP!", e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
281 return retString;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
282 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
283
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
284 String base = "ou=people";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
285
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
286 SearchControls sc = new SearchControls();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
287 String[] attributeFilter = { "cn", "mail" };
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
288 sc.setReturningAttributes(attributeFilter);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
289 sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
290
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
291 String filter = "(uid=" + creator + ")";
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
292
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
293 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
294 NamingEnumeration<SearchResult> results = dctx.search(base, filter, sc);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
295 while (results.hasMore()) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
296 SearchResult sr = (SearchResult) results.next();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
297 javax.naming.directory.Attributes attrs = sr.getAttributes();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
298
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
299 Attribute attr = attrs.get("cn");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
300 retString = (String) attr.get();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
301 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
302 } catch (NamingException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
303 logger.error("Error in getFullNameFromLDAP!", e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
304 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
305
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
306 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
307 dctx.close();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
308 } catch (NamingException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
309 logger.error("Error in getFullNameFromLDAP!", e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
310 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
311 return retString;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
312 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
313
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
314 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
315 * returns resource from path (in webapp) as InputStream.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
316 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
317 * @param sc
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
318 * @param path
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
319 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
320 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
321 protected InputStream getResourceAsStream(ServletContext sc, String path) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
322 InputStream ps = sc.getResourceAsStream(path);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
323 if (ps == null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
324 // try as file
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
325 File pf = new File(sc.getRealPath(path));
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
326 if (pf != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
327 logger.debug("trying file for: " + pf);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
328 try {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
329 ps = new FileInputStream(pf);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
330 } catch (FileNotFoundException e) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
331 logger.error(e);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
332 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
333 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
334 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
335 return ps;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
336 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
337
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
338 /**
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
339 * get a real file name for a web app file pathname.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
340 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
341 * If filename starts with "/" its treated as absolute else the path is
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
342 * appended to the base directory of the web-app.
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
343 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
344 * @param filename
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
345 * @param sc
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
346 * @return
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
347 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
348 public static String getResourcePath(ServletContext sc, String filename) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
349 File f = new File(filename);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
350 // is the filename absolute?
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
351 if (!f.isAbsolute()) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
352 // relative path -> use getRealPath to resolve in webapp
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
353 filename = sc.getRealPath(filename);
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
354 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
355 return filename;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
356 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
357
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
358 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
359 * (non-Javadoc)
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
360 *
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
361 * @see org.restlet.Application#stop()
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
362 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
363 @Override
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
364 public synchronized void stop() throws Exception {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
365 /*
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
366 * trying to clean up databases, not sure if this is the right way...
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
367 */
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
368 if (srv != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
369 logger.debug("Stopping DB admin server...");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
370 srv.stop();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
371 srv = null;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
372 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
373 if (graphDb != null) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
374 logger.debug("Stopping DB...");
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
375 graphDb.shutdown();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
376 graphDb = null;
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
377 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
378 super.stop();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
379 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
380
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
381 private static void registerShutdownHook(final GraphDatabaseService graphDb) {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
382 // Registers a shutdown hook for the Neo4j instance so that it
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
383 // shuts down nicely when the VM exits (even if you "Ctrl-C" the
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
384 // running example before it's completed)
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
385 Runtime.getRuntime().addShutdownHook(new Thread() {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
386 @Override
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
387 public void run() {
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
388 graphDb.shutdown();
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
389 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
390 });
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
391 }
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
392
aafa3884b2c4 new AnnotationStore restlet for HTML-UI.
casties
parents:
diff changeset
393 }