comparison artifact-database/src/main/java/org/dive4elements/artifactdatabase/rest/FindUserResource.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/FindUserResource.java@733e76413bf8
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 java.io.IOException;
11
12 import org.apache.log4j.Logger;
13
14 import org.restlet.data.MediaType;
15 import org.restlet.data.Status;
16 import org.restlet.ext.xml.DomRepresentation;
17 import org.restlet.representation.EmptyRepresentation;
18 import org.restlet.representation.Representation;
19 import org.restlet.resource.ResourceException;
20 import org.restlet.Response;
21
22 import org.w3c.dom.Document;
23
24 import de.intevation.artifacts.ArtifactDatabase;
25 import de.intevation.artifacts.ArtifactDatabaseException;
26
27 /**
28 * A Rest resource that finds the user provided by the artifact database.
29 *
30 */
31 public class FindUserResource
32 extends BaseResource
33 {
34 /** The logger that is used in this class.*/
35 private static Logger logger = Logger.getLogger(FindUserResource.class);
36
37 /** server URL where to reach the resource.*/
38 public static final String PATH = "/find-user";
39
40
41 @Override
42 protected Representation innerPost(Representation requestRepr)
43 throws ResourceException
44 {
45 Document input = null;
46
47 try {
48 DomRepresentation in = new DomRepresentation(requestRepr);
49 in.setNamespaceAware(true);
50 input = in.getDocument();
51 }
52 catch (IOException ioe) {
53 logger.error(ioe.getLocalizedMessage(), ioe);
54
55 Response response = getResponse();
56 response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ioe);
57 return new EmptyRepresentation();
58 }
59
60 ArtifactDatabase db = getArtifactDatabase();
61
62 try {
63 logger.info(PATH);
64
65 return new DomRepresentation(
66 MediaType.APPLICATION_XML,
67 db.findUser(input, getCallMeta()));
68 }
69 catch (ArtifactDatabaseException adbe) {
70 logger.warn(adbe.getLocalizedMessage(), adbe);
71
72 Response response = getResponse();
73 response.setStatus(
74 Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY, adbe.getMessage());
75 return new EmptyRepresentation();
76 }
77 }
78 }
79 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org