annotate artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactResource.java @ 390:d5db5483b376

Tagged module 'artifacts' as '2.7'. artifacts/trunk@4528 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Sun, 27 May 2012 10:40:55 +0000
parents 3447fa62f007
children
rev   line source
100
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 93
diff changeset
1 /*
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 93
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 93
diff changeset
3 *
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 93
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: 93
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: 93
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: 93
diff changeset
7 */
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 93
diff changeset
8
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 package de.intevation.artifactdatabase.rest;
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
207
b2115f484edb Move Config and XMLUtils totally to commons package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 101
diff changeset
11 import de.intevation.artifacts.common.utils.XMLUtils;
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
93
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
13 import de.intevation.artifacts.Artifact;
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
14 import de.intevation.artifacts.ArtifactDatabase;
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
15 import de.intevation.artifacts.ArtifactDatabaseException;
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
16 import de.intevation.artifacts.ArtifactNamespaceContext;
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
17
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
18 import java.io.IOException;
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
19
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
20 import org.apache.log4j.Logger;
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
21
101
7fc0650f194c Upgraded the Restlet version to 2.0.4 (current stable).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
22 import org.restlet.Request;
7fc0650f194c Upgraded the Restlet version to 2.0.4 (current stable).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
23 import org.restlet.Response;
7fc0650f194c Upgraded the Restlet version to 2.0.4 (current stable).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 100
diff changeset
24
93
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
25 import org.restlet.data.MediaType;
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
26 import org.restlet.data.Status;
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 import org.restlet.ext.xml.DomRepresentation;
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
93
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
30 import org.restlet.representation.EmptyRepresentation;
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
31 import org.restlet.representation.Representation;
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
93
e27cf9c84eb8 Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 89
diff changeset
33 import org.restlet.resource.ResourceException;
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 import org.w3c.dom.Document;
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 /**
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
38 * 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
39 * (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
40 *
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
41 * <ul>
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
42 * <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
43 * <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
44 * </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
45 * @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
46 */
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 public class ArtifactResource
40
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 35
diff changeset
48 extends BaseResource
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 {
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 private static Logger logger = Logger.getLogger(ArtifactResource.class);
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
52 /**
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
53 * 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
54 * 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
55 */
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
56 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
57
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 * 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
60 */
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 public static final String PATH = "/artifact/{uuid}";
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
63 /**
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
64 * 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
65 */
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
66 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
67
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
68 /**
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
69 * 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
70 */
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
71 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
72
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
73 /**
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
74 * 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
75 * 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
76 */
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 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
78
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
79 /**
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
80 * 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
81 */
55
9a29899b31e5 describe() in REST interface is also handled as POST to pass
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 48
diff changeset
82 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
83 /**
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
84 * 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
85 */
55
9a29899b31e5 describe() in REST interface is also handled as POST to pass
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 48
diff changeset
86 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
87 /**
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
88 * 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
89 */
55
9a29899b31e5 describe() in REST interface is also handled as POST to pass
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 48
diff changeset
90 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
91
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
92 @Override
40
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 35
diff changeset
93 protected Representation innerGet()
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 35
diff changeset
94 throws ResourceException
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 35
diff changeset
95 {
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 Request request = getRequest();
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 String identifier = (String)request.getAttributes().get("uuid");
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 if (logger.isDebugEnabled()) {
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 logger.debug("looking for artifact id '" + identifier + "'");
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 }
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 ArtifactDatabase db = (ArtifactDatabase)getContext()
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 .getAttributes().get("database");
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
107 try {
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 DomRepresentation(
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
109 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
110 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
111 }
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
112 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
113 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
114 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
115 response.setStatus(
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
116 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
117 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
118 }
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
119 }
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
121 /**
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
122 * 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
123 * triggered and perform this operation on the artifact specified
326
3447fa62f007 Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 207
diff changeset
124 * by 'identifier' and found in the artifact database 'db'.
3447fa62f007 Minor cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 207
diff changeset
125 *
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
126 * @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
127 * @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
128 * @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
129 * operation.
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
130 * @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
131 * @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
132 */
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
133 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
134 String identifier,
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
135 String action,
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
136 Document source,
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
137 ArtifactDatabase db
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
138 ) {
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
139 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
140
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
141 try {
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
142 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
143 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
144 }
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
145 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
146 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
147 }
55
9a29899b31e5 describe() in REST interface is also handled as POST to pass
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 48
diff changeset
148 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
149 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
150 }
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
151 else {
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
152 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
153 }
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
154 }
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
155 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
156 logger.warn(adbe.getLocalizedMessage(), adbe);
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 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
158 response.setStatus(
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
159 Status.CLIENT_ERROR_BAD_REQUEST, adbe.getMessage());
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 return new EmptyRepresentation();
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 }
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
163 return new DomRepresentation(MediaType.APPLICATION_XML, out);
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 }
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
166 @Override
40
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 35
diff changeset
167 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
168
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 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
170 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
171 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
172 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
173 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
174 }
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 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
176 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
177 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
178 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
179 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
180 }
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
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 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
183 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
184 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
185 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
186
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 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
188 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
189 response.setStatus(
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
190 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
191 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
192 }
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
193
40
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 35
diff changeset
194 Request request = getRequest();
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 35
diff changeset
195
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
196 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
197
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
198 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
199 .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
200
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 29
diff changeset
201 return dispatch(identifier, action, inputDocument, db);
27
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
202 }
75bdaf900473 Added REST handler for 'describe'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
203 }
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
204 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org