comparison artifact-database/src/main/java/org/dive4elements/artifactdatabase/rest/CreateUserResource.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/CreateUserResource.java@82809c5992e1
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.Response;
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.resource.ResourceException;
21
22 import org.w3c.dom.Document;
23
24 import de.intevation.artifacts.ArtifactDatabase;
25 import de.intevation.artifacts.ArtifactDatabaseException;
26
27
28 /**
29 * Resource to create a new users within the artifact database.
30 *
31 * @author <a href="mailto:ingo.weinzierl@intevation">Ingo Weinzierl</a>
32 */
33 public class CreateUserResource
34 extends BaseResource
35 {
36 /** The logger used in this class.*/
37 private static Logger logger = Logger.getLogger(CreateUserResource.class);
38
39 /** The URL part for this resource.*/
40 public static final String PATH = "/create-user";
41
42
43 @Override
44 protected Representation innerPost(Representation requestRepr)
45 throws ResourceException
46 {
47 Document input = null;
48
49 try {
50 DomRepresentation in = new DomRepresentation(requestRepr);
51 in.setNamespaceAware(true);
52 input = in.getDocument();
53 }
54 catch (IOException ioe) {
55 logger.error(ioe.getLocalizedMessage(), ioe);
56
57 Response response = getResponse();
58 response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ioe);
59 return new EmptyRepresentation();
60 }
61
62 logger.debug("Create user");
63
64 ArtifactDatabase db = getArtifactDatabase();
65
66 try {
67 return new DomRepresentation(
68 MediaType.APPLICATION_XML,
69 db.createUser(input, getCallMeta()));
70 }
71 catch (ArtifactDatabaseException adbe) {
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