Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactResource.java @ 90:68285f7bc476
More javadoc.
artifacts/trunk@846 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 26 Mar 2010 17:59:50 +0000 |
parents | d348fe1fd822 |
children | e27cf9c84eb8 |
rev | line source |
---|---|
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.artifactdatabase.rest; |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
40
af22d4de275c
Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
35
diff
changeset
|
3 import org.restlet.resource.ResourceException; |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import org.restlet.representation.Representation; |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import org.restlet.representation.EmptyRepresentation; |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import org.restlet.ext.xml.DomRepresentation; |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.artifacts.ArtifactDatabase; |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
11 import de.intevation.artifacts.ArtifactDatabaseException; |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.artifacts.Artifact; |
29
22b03d5c84c5
Added REST out handler for artifacts reachable via HTTP GET '/artifact/{uuid}/{type}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
28
diff
changeset
|
13 import de.intevation.artifacts.ArtifactNamespaceContext; |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import org.restlet.data.Request; |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import org.restlet.data.Response; |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import org.restlet.data.Status; |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 import org.restlet.data.MediaType; |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 import org.apache.log4j.Logger; |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 import org.w3c.dom.Document; |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
28
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
24 import java.io.IOException; |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
25 |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
26 import de.intevation.artifactdatabase.XMLUtils; |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
27 |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 /** |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
29 * Resource to expose the core artifact methods |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
30 * (describe, feed and advance) via REST. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
31 * |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
32 * <ul> |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
33 * <li>describe() is modelled via GET.</li> |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
34 * <li>advance() and feed() are modelled via POST.</li> |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
35 * </ul> |
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:
64
diff
changeset
|
36 * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a> |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 */ |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 public class ArtifactResource |
40
af22d4de275c
Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
35
diff
changeset
|
39 extends BaseResource |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 { |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 private static Logger logger = Logger.getLogger(ArtifactResource.class); |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
43 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
44 * XPath to figure out the type of action (feed, advance) via the |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
45 * incoming POST request. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
46 */ |
64
8b72676698b5
Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
55
diff
changeset
|
47 public static final String XPATH_ACTION = "/art:action/art:type/@name"; |
28
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
48 |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
49 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
50 * server URL where to reach the resource. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
51 */ |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 public static final String PATH = "/artifact/{uuid}"; |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
54 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
55 * Error message if no action was given. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
56 */ |
28
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
57 public static final String NO_ACTION_MESSAGE = "no action given"; |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
58 |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
59 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
60 * Error message if a unknown action was given. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
61 */ |
28
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
62 public static final String NO_SUCH_ACTION_MESSAGE = "no such action"; |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
63 |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
64 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
65 * Error message if the requested artifact was not found in |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
66 * the artifact database. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
67 */ |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 public static final String NO_ARTIFACT_FOUND = "Artifact not found"; |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
70 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
71 * Action name 'advance'. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
72 */ |
55
9a29899b31e5
describe() in REST interface is also handled as POST to pass
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
73 public static final String ADVANCE = "advance"; |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
74 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
75 * Action name 'feed'. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
76 */ |
55
9a29899b31e5
describe() in REST interface is also handled as POST to pass
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
77 public static final String FEED = "feed"; |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
78 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
79 * Action name 'describe'. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
80 */ |
55
9a29899b31e5
describe() in REST interface is also handled as POST to pass
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
81 public static final String DESCRIBE = "describe"; |
28
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
82 |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
83 @Override |
40
af22d4de275c
Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
35
diff
changeset
|
84 protected Representation innerGet() |
af22d4de275c
Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
35
diff
changeset
|
85 throws ResourceException |
af22d4de275c
Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
35
diff
changeset
|
86 { |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 Request request = getRequest(); |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 String identifier = (String)request.getAttributes().get("uuid"); |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 if (logger.isDebugEnabled()) { |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 logger.debug("looking for artifact id '" + identifier + "'"); |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 } |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 ArtifactDatabase db = (ArtifactDatabase)getContext() |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 .getAttributes().get("database"); |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
98 try { |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
99 return new DomRepresentation( |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
100 MediaType.APPLICATION_XML, |
55
9a29899b31e5
describe() in REST interface is also handled as POST to pass
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
101 db.describe(identifier, null, getCallMeta())); |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
102 } |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
103 catch (ArtifactDatabaseException adbe) { |
35
7a01a464a83b
More warning log output in POST case in REST interface of artifact.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
104 logger.warn(adbe.getLocalizedMessage(), adbe); |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
105 Response response = getResponse(); |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
106 response.setStatus( |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
107 Status.CLIENT_ERROR_NOT_FOUND, adbe.getMessage()); |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
108 return new EmptyRepresentation(); |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
109 } |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
110 } |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
112 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
113 * Method to figure out which POST action (feed or advance) was |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
114 * triggered and perform this operation on the artifact specified |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
115 * by 'identifier' and found in the artifact database 'db' |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
116 * @param identifier The identifier of the artifact. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
117 * @param action The action to be performed. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
118 * @param source The input document to further parameterize the |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
119 * operation. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
120 * @param db The artifact database where to find the artifact. |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
88
diff
changeset
|
121 * @return The representation produced by the performed action. |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
122 */ |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
123 protected Representation dispatch( |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
124 String identifier, |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
125 String action, |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
126 Document source, |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
127 ArtifactDatabase db |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
128 ) { |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
129 Document out = null; |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
130 |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
131 try { |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
132 if (action.equals(FEED)) { |
48
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
40
diff
changeset
|
133 out = db.feed(identifier, source, getCallMeta()); |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
134 } |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
135 else if (action.equals(ADVANCE)) { |
48
41c225c8bd41
Add i18n support via "Accept-Language" HTTP headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
40
diff
changeset
|
136 out = db.advance(identifier, source, getCallMeta()); |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
137 } |
55
9a29899b31e5
describe() in REST interface is also handled as POST to pass
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
138 else if (action.equals(DESCRIBE)) { |
9a29899b31e5
describe() in REST interface is also handled as POST to pass
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
139 out = db.describe(identifier, source, getCallMeta()); |
9a29899b31e5
describe() in REST interface is also handled as POST to pass
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
48
diff
changeset
|
140 } |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
141 else { |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
142 throw new ArtifactDatabaseException(NO_SUCH_ACTION_MESSAGE); |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
143 } |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
144 } |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
145 catch (ArtifactDatabaseException adbe) { |
35
7a01a464a83b
More warning log output in POST case in REST interface of artifact.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
34
diff
changeset
|
146 logger.warn(adbe.getLocalizedMessage(), adbe); |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 Response response = getResponse(); |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
148 response.setStatus( |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
149 Status.CLIENT_ERROR_BAD_REQUEST, adbe.getMessage()); |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 return new EmptyRepresentation(); |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 } |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
153 return new DomRepresentation(MediaType.APPLICATION_XML, out); |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 } |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
156 @Override |
40
af22d4de275c
Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
35
diff
changeset
|
157 protected Representation innerPost(Representation requestRepr) { |
28
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
158 |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
159 Document inputDocument = null; |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
160 try { |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
161 DomRepresentation input = new DomRepresentation(requestRepr); |
64
8b72676698b5
Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
55
diff
changeset
|
162 input.setNamespaceAware(true); |
28
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
163 inputDocument = input.getDocument(); |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
164 } |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
165 catch (IOException ioe) { |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
166 logger.error(ioe.getMessage()); |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
167 Response response = getResponse(); |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
168 response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ioe); |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
169 return new EmptyRepresentation(); |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
170 } |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
171 |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
172 String action = XMLUtils.xpathString( |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
173 inputDocument, |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
174 XPATH_ACTION, |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
175 ArtifactNamespaceContext.INSTANCE); |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
176 |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
177 if (action == null || action.length() == 0) { |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
178 Response response = getResponse(); |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
179 response.setStatus( |
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
180 Status.CLIENT_ERROR_BAD_REQUEST, NO_ACTION_MESSAGE); |
28
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
181 return new EmptyRepresentation(); |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
182 } |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
183 |
40
af22d4de275c
Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
35
diff
changeset
|
184 Request request = getRequest(); |
af22d4de275c
Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
35
diff
changeset
|
185 |
28
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
186 String identifier = (String)request.getAttributes().get("uuid"); |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
187 |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
188 ArtifactDatabase db = (ArtifactDatabase)getContext() |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
189 .getAttributes().get("database"); |
019b9f02d523
Added REST handler for 'advance' and 'feed' to be called by HTTP POST '/artifact/{uuid}'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
27
diff
changeset
|
190 |
32
c2d53bd30ab8
Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
29
diff
changeset
|
191 return dispatch(identifier, action, inputDocument, db); |
27
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 } |
75bdaf900473
Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 } |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
194 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |