Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CreateCollectionResource.java @ 406:10aa92f2eca0
Add a account column to the users table
artifacts/trunk@5242 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Thu, 23 Aug 2012 13:33:27 +0000 |
parents | f141ae401a00 |
children |
rev | line source |
---|---|
140
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 /* |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 * Copyright (c) 2011 by Intevation GmbH |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 * |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 */ |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 package de.intevation.artifactdatabase.rest; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.artifacts.ArtifactDatabase; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.artifacts.ArtifactDatabaseException; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import java.io.IOException; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 import org.apache.log4j.Logger; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 import org.restlet.data.MediaType; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 import org.restlet.data.Status; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 import org.restlet.ext.xml.DomRepresentation; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 import org.restlet.representation.EmptyRepresentation; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 import org.restlet.representation.Representation; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 import org.restlet.resource.ResourceException; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 import org.restlet.Response; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 import org.restlet.Request; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 import org.w3c.dom.Document; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 /** |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 * Resource to create a new collections within the artifact database. |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 * |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 * @author <a href="mailto:ingo.weinzierl@intevation">Ingo Weinzierl</a> |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 */ |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 public class CreateCollectionResource |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 extends BaseResource |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 { |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 /** The logger used in this class.*/ |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 private static Logger logger = |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 Logger.getLogger(CreateCollectionResource.class); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 /** The URL part for this resource.*/ |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 public static final String PATH = "/create-collection/{ownerid}"; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 @Override |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 protected Representation innerPost(Representation requestRepr) |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 throws ResourceException |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 { |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 Document input = null; |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 try { |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 DomRepresentation in = new DomRepresentation(requestRepr); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 in.setNamespaceAware(true); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 input = in.getDocument(); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 } |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 catch (IOException ioe) { |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 logger.error(ioe.getLocalizedMessage(), ioe); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 Response response = getResponse(); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ioe); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 return new EmptyRepresentation(); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 } |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 ArtifactDatabase db = getArtifactDatabase(); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 Request request = getRequest(); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 String ownerId = (String) request.getAttributes().get("ownerid"); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 logger.info("Create new collection owned by: " + ownerId); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 try { |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 return new DomRepresentation( |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 MediaType.APPLICATION_XML, |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 db.createCollection(ownerId, input, getCallMeta())); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 } |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 catch (ArtifactDatabaseException adbe) { |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 logger.warn(adbe.getLocalizedMessage(), adbe); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 Response response = getResponse(); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 response.setStatus( |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY, adbe.getMessage()); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 return new EmptyRepresentation(); |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 } |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 } |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 } |
f141ae401a00
Added a Rest resource that might be used to create new collections owned by a specific user.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |