Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ListCollectionsResource.java @ 141:5d40faf1484d
Added a Rest resource that lists all collections of a specific user.
artifacts/trunk@1366 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 02 Mar 2011 13:31:59 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
140:f141ae401a00 | 141:5d40faf1484d |
---|---|
1 /* | |
2 * Copyright (c) 2011 by Intevation GmbH | |
3 * | |
4 * This program is free software under the LGPL (>=v2.1) | |
5 * Read the file LGPL.txt coming with the software for details | |
6 * or visit http://www.gnu.org/licenses/ if it does not exist. | |
7 */ | |
8 package de.intevation.artifactdatabase.rest; | |
9 | |
10 import de.intevation.artifacts.ArtifactDatabase; | |
11 import de.intevation.artifacts.ArtifactDatabaseException; | |
12 | |
13 import org.apache.log4j.Logger; | |
14 | |
15 import org.restlet.data.MediaType; | |
16 import org.restlet.data.Status; | |
17 import org.restlet.ext.xml.DomRepresentation; | |
18 import org.restlet.representation.EmptyRepresentation; | |
19 import org.restlet.representation.Representation; | |
20 import org.restlet.Request; | |
21 import org.restlet.resource.ResourceException; | |
22 import org.restlet.Response; | |
23 | |
24 | |
25 /** | |
26 * A Rest resource that lists the collections of a specific user provided by | |
27 * the artifact database. | |
28 * | |
29 * @author <a href="mailto:ingo.weinzierl@intevation">Ingo Weinzierl</a> | |
30 */ | |
31 public class ListCollectionsResource | |
32 extends BaseResource | |
33 { | |
34 /** The logger that is used in this class.*/ | |
35 private static Logger logger = | |
36 Logger.getLogger(ListCollectionsResource.class); | |
37 | |
38 /** server URL where to reach the resource.*/ | |
39 public static final String PATH = "/list-collections/{ownerid}"; | |
40 | |
41 | |
42 @Override | |
43 protected Representation innerGet() | |
44 throws ResourceException | |
45 { | |
46 Request request = getRequest(); | |
47 | |
48 String ownerId = (String) request.getAttributes().get("ownerid"); | |
49 | |
50 ArtifactDatabase db = getArtifactDatabase(); | |
51 | |
52 try { | |
53 logger.info("List collections owned by " + ownerId); | |
54 | |
55 return new DomRepresentation( | |
56 MediaType.APPLICATION_XML, | |
57 db.listCollections(ownerId, getCallMeta())); | |
58 } | |
59 catch (ArtifactDatabaseException adbe) { | |
60 logger.warn(adbe.getLocalizedMessage(), adbe); | |
61 | |
62 Response response = getResponse(); | |
63 response.setStatus( | |
64 Status.CLIENT_ERROR_NOT_FOUND, adbe.getMessage()); | |
65 return new EmptyRepresentation(); | |
66 } | |
67 } | |
68 } | |
69 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |