annotate artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java @ 196:171b6200d26d

Added a describe() action for collections - the implementation in the artifact server is currently just a stub that throws an not implemented exception. artifacts/trunk@1426 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 08 Mar 2011 10:38:14 +0000
parents fbaeb5931d10
children 6de74b0b878e
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
196
171b6200d26d Added a describe() action for collections - the implementation in the artifact server is currently just a stub that throws an not implemented exception.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 189
diff changeset
66 /** Action name for describing the collection.*/
171b6200d26d Added a describe() action for collections - the implementation in the artifact server is currently just a stub that throws an not implemented exception.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 189
diff changeset
67 public static final String ACTION_DESCRIBE = "describe";
171b6200d26d Added a describe() action for collections - the implementation in the artifact server is currently just a stub that throws an not implemented exception.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 189
diff changeset
68
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 /** 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
70 * collection.*/
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 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
72
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 /** 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
74 * 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_SET_ATTRIBUTE = "setattribute";
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 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
78 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
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 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
81 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
82
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 /** 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
84 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
85
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 * 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
89 * 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
90 * artifact database 'db'.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 * @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
93 * @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
94 * @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
95 * @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
96 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 * @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
98 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 protected Representation dispatch(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 String identifier,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 String action,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 Document source,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 ArtifactDatabase db
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 ) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 Document out = null;
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 try {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 CallMeta meta = getCallMeta();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 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
111 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
112 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
113 }
196
171b6200d26d Added a describe() action for collections - the implementation in the artifact server is currently just a stub that throws an not implemented exception.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 189
diff changeset
114 else if (action.equals(ACTION_DESCRIBE)) {
171b6200d26d Added a describe() action for collections - the implementation in the artifact server is currently just a stub that throws an not implemented exception.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 189
diff changeset
115 logger.info("Describe collection '" + identifier + "'");
171b6200d26d Added a describe() action for collections - the implementation in the artifact server is currently just a stub that throws an not implemented exception.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 189
diff changeset
116
171b6200d26d Added a describe() action for collections - the implementation in the artifact server is currently just a stub that throws an not implemented exception.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 189
diff changeset
117 out = db.describeCollection(identifier, meta);
171b6200d26d Added a describe() action for collections - the implementation in the artifact server is currently just a stub that throws an not implemented exception.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 189
diff changeset
118 }
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 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
120 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
121
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 logger.info("Add artifact '" + art + "' to collection.");
189
fbaeb5931d10 Implemented addCollectionArtifact() and listCollectionArtifacts() of the artifact database.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 142
diff changeset
123 out = db.addCollectionArtifact(identifier, art, source, meta);
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 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
126 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
127
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 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
129 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
130 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 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
132 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
133 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
134 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 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
136 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
137
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 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
139 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
140 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141 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
142 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
143
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 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
145 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
146 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147 else {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148 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
149 }
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 catch (ArtifactDatabaseException adbe) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 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
153
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 response.setStatus(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 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
157 return new EmptyRepresentation();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 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
161 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162
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 @Override
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 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
166 Document input = null;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167 try {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 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
169 in.setNamespaceAware(true);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 input = in.getDocument();
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 catch (IOException ioe) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 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
174
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 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
177 return new EmptyRepresentation();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180 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
181 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
182
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183 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
184 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185 response.setStatus(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 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
187 return new EmptyRepresentation();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 }
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 Request request = getRequest();
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 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
193
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194 ArtifactDatabase db = getArtifactDatabase();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
195
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196 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
197 }
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
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201 * 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
202 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 * @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
204 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
205 * @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
206 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
207 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
208 return XMLUtils.xpathString(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209 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
210 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
211 }

http://dive4elements.wald.intevation.org