comparison artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactResource.java @ 88:69c84cf7c5d7

Added javadoc to the REST package of the artifact database (complete). artifacts/trunk@840 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 26 Mar 2010 15:05:11 +0000
parents 48d1a9a082c2
children d348fe1fd822
comparison
equal deleted inserted replaced
87:0f48188a6e02 88:69c84cf7c5d7
24 import java.io.IOException; 24 import java.io.IOException;
25 25
26 import de.intevation.artifactdatabase.XMLUtils; 26 import de.intevation.artifactdatabase.XMLUtils;
27 27
28 /** 28 /**
29 * Resource to expose the core artifact methods
30 * (describe, feed and advance) via REST.
31 *
32 * <ul>
33 * <li>describe() is modelled via GET.</li>
34 * <li>advance() and feed() are modelled via POST.</li>
35 * </ul>
29 * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a> 36 * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a>
30 */ 37 */
31 public class ArtifactResource 38 public class ArtifactResource
32 extends BaseResource 39 extends BaseResource
33 { 40 {
34 private static Logger logger = Logger.getLogger(ArtifactResource.class); 41 private static Logger logger = Logger.getLogger(ArtifactResource.class);
35 42
43 /**
44 * XPath to figure out the type of action (feed, advance) via the
45 * incoming POST request.
46 */
36 public static final String XPATH_ACTION = "/art:action/art:type/@name"; 47 public static final String XPATH_ACTION = "/art:action/art:type/@name";
37 48
49 /**
50 * server URL where to reach the resource.
51 */
38 public static final String PATH = "/artifact/{uuid}"; 52 public static final String PATH = "/artifact/{uuid}";
39 53
54 /**
55 * Error message if no action was given.
56 */
40 public static final String NO_ACTION_MESSAGE = "no action given"; 57 public static final String NO_ACTION_MESSAGE = "no action given";
58
59 /**
60 * Error message if a unknown action was given.
61 */
41 public static final String NO_SUCH_ACTION_MESSAGE = "no such action"; 62 public static final String NO_SUCH_ACTION_MESSAGE = "no such action";
42 63
64 /**
65 * Error message if the requested artifact was not found in
66 * the artifact database.
67 */
43 public static final String NO_ARTIFACT_FOUND = "Artifact not found"; 68 public static final String NO_ARTIFACT_FOUND = "Artifact not found";
44 69
70 /**
71 * Action name 'advance'.
72 */
45 public static final String ADVANCE = "advance"; 73 public static final String ADVANCE = "advance";
74 /**
75 * Action name 'feed'.
76 */
46 public static final String FEED = "feed"; 77 public static final String FEED = "feed";
78 /**
79 * Action name 'describe'.
80 */
47 public static final String DESCRIBE = "describe"; 81 public static final String DESCRIBE = "describe";
48 82
83 @Override
49 protected Representation innerGet() 84 protected Representation innerGet()
50 throws ResourceException 85 throws ResourceException
51 { 86 {
52 Request request = getRequest(); 87 Request request = getRequest();
53 88
72 Status.CLIENT_ERROR_NOT_FOUND, adbe.getMessage()); 107 Status.CLIENT_ERROR_NOT_FOUND, adbe.getMessage());
73 return new EmptyRepresentation(); 108 return new EmptyRepresentation();
74 } 109 }
75 } 110 }
76 111
112 /**
113 * Method to figure out which POST action (feed or advance) was
114 * triggered and perform this operation on the artifact specified
115 * by 'identifier' and found in the artifact database 'db'
116 * @param identifier The identifier of the artifact.
117 * @param action The action to be performed.
118 * @param source The input document to further parameterize the
119 * operation.
120 * @param db The artifact database where to find the artifact.
121 * @return
122 */
77 protected Representation dispatch( 123 protected Representation dispatch(
78 String identifier, 124 String identifier,
79 String action, 125 String action,
80 Document source, 126 Document source,
81 ArtifactDatabase db 127 ArtifactDatabase db
105 } 151 }
106 152
107 return new DomRepresentation(MediaType.APPLICATION_XML, out); 153 return new DomRepresentation(MediaType.APPLICATION_XML, out);
108 } 154 }
109 155
156 @Override
110 protected Representation innerPost(Representation requestRepr) { 157 protected Representation innerPost(Representation requestRepr) {
111 158
112 Document inputDocument = null; 159 Document inputDocument = null;
113 try { 160 try {
114 DomRepresentation input = new DomRepresentation(requestRepr); 161 DomRepresentation input = new DomRepresentation(requestRepr);
142 .getAttributes().get("database"); 189 .getAttributes().get("database");
143 190
144 return dispatch(identifier, action, inputDocument, db); 191 return dispatch(identifier, action, inputDocument, db);
145 } 192 }
146 } 193 }
147 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: 194 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org