Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java @ 318:2ed77f7e1bab
Swapped SQL parameter indices when fetching collection name.
artifacts/trunk@2455 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 02 Aug 2011 14:13:20 +0000 |
parents | fa0d9acea897 |
children | 733e76413bf8 |
rev | line source |
---|---|
100
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
88
diff
changeset
|
1 /* |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
88
diff
changeset
|
2 * Copyright (c) 2010 by Intevation GmbH |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
88
diff
changeset
|
3 * |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
88
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
88
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
88
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
88
diff
changeset
|
7 */ |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
88
diff
changeset
|
8 |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 package de.intevation.artifactdatabase.rest; |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.artifacts.ArtifactDatabase; |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
20
ff666592c1c3
Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
13 import java.util.concurrent.ConcurrentMap; |
ff666592c1c3
Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
14 |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import org.restlet.Application; |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
77
diff
changeset
|
16 import org.restlet.Context; |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import org.restlet.Restlet; |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 import org.restlet.routing.Router; |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 /** |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
22 * This is the core REST application that binds the serveral resources |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
23 * used to manage the artifact database to the HTTP server provided |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
24 * by the Restlet framework. |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 * |
77
48d1a9a082c2
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
73
diff
changeset
|
26 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 */ |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 public class RestApp |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 extends Application |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 { |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
31 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
32 * The central artifact database instance to work with. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
33 */ |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 protected ArtifactDatabase database; |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
36 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
37 * Default constructor |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
38 */ |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 public RestApp() { |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 } |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
264
fa0d9acea897
flys/issue65: Added Jetty HTTP server as a replacement option to foster better scalability. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
143
diff
changeset
|
42 public RestApp(Context context, ArtifactDatabase database) { |
fa0d9acea897
flys/issue65: Added Jetty HTTP server as a replacement option to foster better scalability. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
143
diff
changeset
|
43 super(context); |
fa0d9acea897
flys/issue65: Added Jetty HTTP server as a replacement option to foster better scalability. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
143
diff
changeset
|
44 this.database = database; |
fa0d9acea897
flys/issue65: Added Jetty HTTP server as a replacement option to foster better scalability. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
143
diff
changeset
|
45 } |
fa0d9acea897
flys/issue65: Added Jetty HTTP server as a replacement option to foster better scalability. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
143
diff
changeset
|
46 |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
47 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
48 * Constructor to create REST appliction bound to a specific |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
49 * artifact database. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
50 * |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
51 * @param database The artifact database to be used. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
52 */ |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 public RestApp(ArtifactDatabase database) { |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 this.database = database; |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 } |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
57 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
58 * Overwrites the createRoot() method of Application to |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
59 * build the resource tree to form the exposed server URLs. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
60 * |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
61 * @return The root of the URL tree exposed by the HTTP server. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
62 */ |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
63 @Override |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 public Restlet createRoot() { |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 |
20
ff666592c1c3
Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
66 Context context = getContext(); |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
20
ff666592c1c3
Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
68 ConcurrentMap map = context.getAttributes(); |
ff666592c1c3
Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
69 map.put("database", database); |
ff666592c1c3
Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
70 |
ff666592c1c3
Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
71 Router router = new Router(context); |
ff666592c1c3
Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
72 |
72
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
73 router.attach(ServicesResource.PATH, ServicesResource.class); |
73
d1b8c91b4506
Added url '/service/{service}' to REST server to offer the actual service over HTTP.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
72
diff
changeset
|
74 router.attach(ServiceResource.PATH, ServiceResource.class); |
29
22b03d5c84c5
Added REST out handler for artifacts reachable via HTTP GET '/artifact/{uuid}/{type}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
75 router.attach(FactoriesResource.PATH, FactoriesResource.class); |
22b03d5c84c5
Added REST out handler for artifacts reachable via HTTP GET '/artifact/{uuid}/{type}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
76 router.attach(CreateResource.PATH, CreateResource.class); |
22b03d5c84c5
Added REST out handler for artifacts reachable via HTTP GET '/artifact/{uuid}/{type}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
77 router.attach(ArtifactResource.PATH, ArtifactResource.class); |
22b03d5c84c5
Added REST out handler for artifacts reachable via HTTP GET '/artifact/{uuid}/{type}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
78 router.attach(ArtifactOutResource.PATH, ArtifactOutResource.class); |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
77
diff
changeset
|
79 router.attach(ExportResource.PATH, ExportResource.class); |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
79
diff
changeset
|
80 router.attach(ImportResource.PATH, ImportResource.class); |
131
82809c5992e1
Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
100
diff
changeset
|
81 router.attach(CreateUserResource.PATH, CreateUserResource.class); |
136
e2aad8d8ebd7
Added a Rest resource that lists all users provided by the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
131
diff
changeset
|
82 router.attach(ListUsersResource.PATH, ListUsersResource.class); |
137
f92ad0e40df2
Added a resource that handles user specific actions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
136
diff
changeset
|
83 router.attach(UserResource.PATH, UserResource.class); |
140
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
137
diff
changeset
|
84 router.attach( |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
137
diff
changeset
|
85 CreateCollectionResource.PATH, CreateCollectionResource.class); |
141
5d40faf1484d
Added a Rest resource that lists all collections of a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
140
diff
changeset
|
86 router.attach( |
5d40faf1484d
Added a Rest resource that lists all collections of a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
140
diff
changeset
|
87 ListCollectionsResource.PATH, ListCollectionsResource.class); |
142
e986e32bc7d4
Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
141
diff
changeset
|
88 router.attach( |
e986e32bc7d4
Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
141
diff
changeset
|
89 CollectionResource.PATH, CollectionResource.class); |
143
7e20702a90ed
Implemented an abstract class for the output of artifacts and collections. Added a CollectionOutResource.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
142
diff
changeset
|
90 router.attach( |
7e20702a90ed
Implemented an abstract class for the output of artifacts and collections. Added a CollectionOutResource.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
142
diff
changeset
|
91 CollectionOutResource.PATH, CollectionOutResource.class); |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 return router; |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 } |
79
f69e5b87f05f
Implementation to export artifacts as xml (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
77
diff
changeset
|
96 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |