Mercurial > dive4elements > framework
changeset 27:75bdaf900473
Added REST handler for 'describe'.
artifacts/trunk@64 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 10 Sep 2009 14:21:58 +0000 |
parents | 83a059c204f8 |
children | 019b9f02d523 |
files | Changelog artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactResource.java artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java |
diffstat | 4 files changed, 89 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/Changelog Thu Sep 10 12:29:57 2009 +0000 +++ b/Changelog Thu Sep 10 14:21:58 2009 +0000 @@ -1,3 +1,14 @@ +2009-09-10 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactResource.java: + Handler for describe to be fetced by HTTP GET '/artifact/{uuid}'. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java: + Add route to new describe handler. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java: Fixed + problems with serialization of artifacts to backing database. + 2009-09-10 Sascha L. Teichmann <sascha.teichmann@intevation.de> * artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Thu Sep 10 12:29:57 2009 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Thu Sep 10 14:21:58 2009 +0000 @@ -139,6 +139,7 @@ oos.writeObject(original); oos.flush(); + oos.close(); return bos.toByteArray(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactResource.java Thu Sep 10 14:21:58 2009 +0000 @@ -0,0 +1,76 @@ +package de.intevation.artifactdatabase.rest; + +import org.restlet.resource.Get; +import org.restlet.resource.Post; +import org.restlet.resource.ServerResource; + +import org.restlet.representation.Representation; +import org.restlet.representation.EmptyRepresentation; + +import org.restlet.ext.xml.DomRepresentation; + +import de.intevation.artifacts.ArtifactDatabase; +import de.intevation.artifacts.Artifact; + +import org.restlet.data.Request; +import org.restlet.data.Response; +import org.restlet.data.Status; + +import org.restlet.data.MediaType; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; + +/** + * @author Sascha L. Teichmann (sascha.teichmann@intevation) + */ +public class ArtifactResource +extends ServerResource +{ + private static Logger logger = Logger.getLogger(ArtifactResource.class); + + public static final String PATH = "/artifact/{uuid}"; + + public static final String NO_ARTIFACT_FOUND = "Artifact not found"; + + @Get + public Representation represent() { + + Request request = getRequest(); + + String identifier = (String)request.getAttributes().get("uuid"); + + if (logger.isDebugEnabled()) { + logger.debug("looking for artifact id '" + identifier + "'"); + } + + ArtifactDatabase db = (ArtifactDatabase)getContext() + .getAttributes().get("database"); + + Artifact artifact = db.getArtifact(identifier); + + if (artifact == null) { + Response response = getResponse(); + response.setStatus(Status.CLIENT_ERROR_NOT_FOUND, NO_ARTIFACT_FOUND); + return new EmptyRepresentation(); + } + + Document description = artifact.describe(db.getArtifactContext()); + + if (logger.isDebugEnabled()) { + logger.debug("out document: " + description); + } + + return new DomRepresentation( + MediaType.APPLICATION_XML, description); + } + + /* + @Post + public Representation representPost() { + return new EmptyRepresentation(); + } + */ +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java Thu Sep 10 12:29:57 2009 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java Thu Sep 10 14:21:58 2009 +0000 @@ -37,6 +37,7 @@ router.attach(FactoriesResource.PATH, FactoriesResource.class); router.attach(CreateResource.PATH, CreateResource.class); + router.attach(ArtifactResource.PATH, ArtifactResource.class); return router; }