annotate artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java @ 142:e986e32bc7d4

Added a Rest resource that handles operations specific to a collection. artifacts/trunk@1367 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 02 Mar 2011 15:10:34 +0000
parents
children fbaeb5931d10
rev   line source
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 /*
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2 * Copyright (c) 2011 by Intevation GmbH
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 * Read the file LGPL.txt coming with the software for details
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 package de.intevation.artifactdatabase.rest;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 import de.intevation.artifacts.ArtifactDatabase;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import de.intevation.artifacts.ArtifactDatabaseException;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import de.intevation.artifacts.CallMeta;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import de.intevation.artifacts.common.ArtifactNamespaceContext;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import de.intevation.artifacts.common.utils.XMLUtils;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import java.io.IOException;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import org.apache.log4j.Logger;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 import org.restlet.data.MediaType;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import org.restlet.data.Status;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 import org.restlet.ext.xml.DomRepresentation;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 import org.restlet.representation.EmptyRepresentation;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 import org.restlet.representation.Representation;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 import org.restlet.Request;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 import org.restlet.Response;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 import org.w3c.dom.Document;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 * @author <a href="mailto:ingo.weinzierl@intevation">Ingo Weinzierl</a>
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 public class CollectionResource
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 extends BaseResource
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 /** The logger that is used in this class.*/
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 private static Logger logger = Logger.getLogger(CollectionResource.class);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 /** server URL where to reach the resource.*/
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 public static final String PATH = "/collection/{uuid}";
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 * XPath to figure out the type of action (feed, advance) via the
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 * incoming POST request.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 public static final String XPATH_ACTION = "/art:action/art:type/@name";
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 * XPath to figure out the identifier of the artifact described in the
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 * action.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 public static final String XPATH_ARTIFACT =
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 "/art:action/art:type/art:artifact/@uuid";
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 /** Error message if no action was given.*/
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 public static final String NO_ACTION_MSG = "no action given";
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 /** Error message if a unknown action was given.*/
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 public static final String NO_SUCH_ACTION_MSG = "no such action";
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 /** Action name for deleting a collection.*/
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 public static final String ACTION_DELETE = "delete";
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 /** Action name for retrieving the attributes of an artifact stored in the
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 * collection.*/
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 public static final String ACTION_GET_ATTRIBUTE = "getattribute";
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 /** Action name for setting the attribute for an artifact stored in the
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 * collection.*/
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 public static final String ACTION_SET_ATTRIBUTE = "setattribute";
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 /** Action name for adding a new artifact to the collection.*/
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 public static final String ACTION_ADD_ARTIFACT = "addartifact";
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 /** Action name for removing an artifact from the collection.*/
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 public static final String ACTION_REMOVE_ARTIFACT = "removeartifact";
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 /** Action name for listing the artifacts of the collection.*/
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 public static final String ACTION_LIST_ARTIFACTS = "listartifacts";
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 * Method to figure out which POST action was triggered and perform this
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 * operation on the collection specified by 'identifier' and found in the
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 * artifact database 'db'.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 * @param identifier The identifier of the collection.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 * @param action The action to be performed.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 * @param source The input document to further parameterize the operation.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 * @param db The artifact database where to find the collection.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 * @return The representation produced by the performed action.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 protected Representation dispatch(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 String identifier,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 String action,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 Document source,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 ArtifactDatabase db
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 ) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 Document out = null;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 try {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 CallMeta meta = getCallMeta();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 if (action.equals(ACTION_DELETE)) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 logger.info("Delete collection '" + identifier + "'");
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 out = db.deleteCollection(identifier, getCallMeta());
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 else if (action.equals(ACTION_ADD_ARTIFACT)) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 String art = getArtifactIdentifier(source);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 logger.info("Add artifact '" + art + "' to collection.");
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 out = db.addCollectionArtifact(identifier, art, meta);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 else if (action.equals(ACTION_REMOVE_ARTIFACT)) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 String art = getArtifactIdentifier(source);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 logger.info("Remove artifact '" + art + "' from collection.");
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 out = db.removeCollectionArtifact(identifier, art, meta);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 else if (action.equals(ACTION_LIST_ARTIFACTS)) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 logger.info("List artifacts of collection '" + identifier +"'");
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 out = db.listCollectionArtifacts(identifier, meta);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 else if (action.equals(ACTION_SET_ATTRIBUTE)) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 String art = getArtifactIdentifier(source);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 logger.info("Set attribute for artifact '" + art + "'");
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 out = db.setCollectionAttribute(identifier, art, source, meta);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 else if (action.equals(ACTION_GET_ATTRIBUTE)) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 String art = getArtifactIdentifier(source);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 logger.info("Retrieve attribute of artifact '" + art + "'");
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 out = db.getCollectionAttribute(identifier, art, meta);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 else {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 throw new ArtifactDatabaseException(NO_SUCH_ACTION_MSG);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 catch (ArtifactDatabaseException adbe) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 logger.warn(adbe.getLocalizedMessage(), adbe);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147 response.setStatus(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148 Status.CLIENT_ERROR_BAD_REQUEST, adbe.getMessage());
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 return new EmptyRepresentation();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 return new DomRepresentation(MediaType.APPLICATION_XML, out);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 @Override
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157 protected Representation innerPost(Representation requestRepr) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 Document input = null;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159 try {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 DomRepresentation in = new DomRepresentation(requestRepr);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 in.setNamespaceAware(true);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 input = in.getDocument();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
163 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 catch (IOException ioe) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 logger.error(ioe.getLocalizedMessage(), ioe);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
166
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ioe);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
169 return new EmptyRepresentation();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
171
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 String action = XMLUtils.xpathString(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 input, XPATH_ACTION, ArtifactNamespaceContext.INSTANCE);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 if (action == null || action.length() == 0) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 response.setStatus(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 Status.CLIENT_ERROR_BAD_REQUEST, NO_ACTION_MSG);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 return new EmptyRepresentation();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 Request request = getRequest();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 String identifier = (String) request.getAttributes().get("uuid");
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 ArtifactDatabase db = getArtifactDatabase();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 return dispatch(identifier, action, input, db);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
190
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
192 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193 * Retrieves the identifier of the artifact used in the action.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
195 * @param source The incoming document that describes the operation.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
197 * @return the uuid of the artifact described in the document.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 protected String getArtifactIdentifier(Document source) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200 return XMLUtils.xpathString(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201 source, XPATH_ARTIFACT, ArtifactNamespaceContext.INSTANCE);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 }

http://dive4elements.wald.intevation.org