comparison artifact-database/src/main/java/org/dive4elements/artifactdatabase/rest/ListCollectionsResource.java @ 473:d0ac790a6c89 dive4elements-move

Moved directories to org.dive4elements
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 10:57:18 +0200
parents artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ListCollectionsResource.java@5d40faf1484d
children 415df0fc4fa1
comparison
equal deleted inserted replaced
472:783cc1b6b615 473:d0ac790a6c89
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 :

http://dive4elements.wald.intevation.org