annotate artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CreateUserResource.java @ 403:bd76529d612b

FacetActivity: Added interface and registry to decide if a facet should initially active or not. artifacts/trunk@5150 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 29 Jul 2012 09:37:55 +0000
parents 82809c5992e1
children
rev   line source
131
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 /*
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2 * Copyright (c) 2011 by Intevation GmbH
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 *
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 * Read the file LGPL.txt coming with the software for details
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 */
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 package de.intevation.artifactdatabase.rest;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 import java.io.IOException;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import org.apache.log4j.Logger;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import org.restlet.Response;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import org.restlet.data.MediaType;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import org.restlet.data.Status;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import org.restlet.ext.xml.DomRepresentation;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import org.restlet.representation.EmptyRepresentation;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import org.restlet.representation.Representation;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import org.restlet.resource.ResourceException;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import org.w3c.dom.Document;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 import de.intevation.artifacts.ArtifactDatabase;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 import de.intevation.artifacts.ArtifactDatabaseException;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 /**
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 * Resource to create a new users within the artifact database.
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 *
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 * @author <a href="mailto:ingo.weinzierl@intevation">Ingo Weinzierl</a>
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 */
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 public class CreateUserResource
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 extends BaseResource
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 {
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 /** The logger used in this class.*/
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 private static Logger logger = Logger.getLogger(CreateUserResource.class);
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 /** The URL part for this resource.*/
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 public static final String PATH = "/create-user";
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 @Override
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 protected Representation innerPost(Representation requestRepr)
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 throws ResourceException
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 {
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 Document input = null;
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 try {
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 DomRepresentation in = new DomRepresentation(requestRepr);
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 in.setNamespaceAware(true);
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 input = in.getDocument();
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 }
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 catch (IOException ioe) {
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 logger.error(ioe.getLocalizedMessage(), ioe);
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 Response response = getResponse();
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ioe);
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 return new EmptyRepresentation();
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 }
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 logger.debug("Create user");
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 ArtifactDatabase db = getArtifactDatabase();
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 try {
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 return new DomRepresentation(
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 MediaType.APPLICATION_XML,
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 db.createUser(input, getCallMeta()));
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 }
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 catch (ArtifactDatabaseException adbe) {
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 Response response = getResponse();
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 response.setStatus(
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY, adbe.getMessage());
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 return new EmptyRepresentation();
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 }
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 }
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 }
82809c5992e1 Added a resource '/create-user' to create new users.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org