annotate artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java @ 268:4edaf3073109

Repaired the setting of a new attribute for a Collection. artifacts/trunk@2016 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 27 May 2011 08:47:31 +0000
parents a2df2b48d2aa
children 22a90706d32d
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
268
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
17 import de.intevation.artifactdatabase.ArtifactDatabaseImpl;
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
18
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 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
20
268
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
21 import javax.xml.xpath.XPathConstants;
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
22
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 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
24
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.data.MediaType;
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.data.Status;
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.ext.xml.DomRepresentation;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 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
29 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
30 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
31 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
32
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 import org.w3c.dom.Document;
268
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
34 import org.w3c.dom.Node;
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36
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 * @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
39 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 public class CollectionResource
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 extends BaseResource
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 /** 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
44 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
45
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 /** 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
47 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
48
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 * 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
51 * incoming POST request.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 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
54
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 * 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
57 * action.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 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
60 "/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
61
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 /** 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
63 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
64
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 /** 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
66 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
67
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 /** 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
69 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
70
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
71 /** 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
72 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
73
253
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
74 /** Action name for retrieving the attribute of a collection.*/
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
75 public static final String ACTION_GET_ATTRIBUTE = "getattribute";
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
76
142
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 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
78 * collection.*/
253
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
79 public static final String ACTION_GET_ITEM_ATTRIBUTE = "getitemattribute";
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
80
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
81 /** Action name for setting the attribute of a collection.*/
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
82 public static final String ACTION_SET_ATTRIBUTE = "setattribute";
142
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 /** 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
85 * collection.*/
253
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
86 public static final String ACTION_SET_ITEM_ATTRIBUTE = "setitemattribute";
142
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 /** 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
89 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
90
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 /** 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
92 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
93
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 /** 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
95 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
96
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97
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 * 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
100 * 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
101 * artifact database 'db'.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 * @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
104 * @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
105 * @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
106 * @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
107 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 * @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
109 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 protected Representation dispatch(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 String identifier,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 String action,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 Document source,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 ArtifactDatabase db
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 ) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 Document out = null;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 try {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 CallMeta meta = getCallMeta();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 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
122 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
123 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
124 }
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
125 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
126 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
127
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
128 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
129 }
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 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
131 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
132
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 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
134 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
135 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 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
137 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
138
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 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
140 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
141 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 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
143 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
144 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
145 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 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
147 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
148
253
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
149 logger.info("Set attribute for collection '" + identifier + "'");
268
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
150
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
151 Document attr = getCollectionAttribute(source);
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
152
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
153 out = db.setCollectionAttribute(identifier, meta, attr);
253
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
154 }
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
155 else if (action.equals(ACTION_SET_ITEM_ATTRIBUTE)) {
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
156 String art = getArtifactIdentifier(source);
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
157
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 logger.info("Set attribute for artifact '" + art + "'");
252
6de74b0b878e Changed the method names to get and set the attributes of collection items.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 196
diff changeset
159 out = db.setCollectionItemAttribute(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
160 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 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
162 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
163
253
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
164 logger.info("Retrieve attribute of collection '" + identifier + "'");
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
165 out = db.getCollectionAttribute(identifier, meta);
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
166 }
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
167 else if (action.equals(ACTION_GET_ITEM_ATTRIBUTE)) {
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
168 String art = getArtifactIdentifier(source);
a2df2b48d2aa Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 252
diff changeset
169
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 logger.info("Retrieve attribute of artifact '" + art + "'");
252
6de74b0b878e Changed the method names to get and set the attributes of collection items.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 196
diff changeset
171 out = db.getCollectionItemAttribute(identifier, art, meta);
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 else {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 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
175 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 catch (ArtifactDatabaseException adbe) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 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
179
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181 response.setStatus(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 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
183 return new EmptyRepresentation();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 }
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 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
187 }
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 @Override
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191 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
192 Document input = null;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193 try {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194 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
195 in.setNamespaceAware(true);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196 input = in.getDocument();
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 catch (IOException ioe) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 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
200
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202 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
203 return new EmptyRepresentation();
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
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
206 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
207 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
208
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209 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
210 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
211 response.setStatus(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
212 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
213 return new EmptyRepresentation();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
214 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
215
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
216 Request request = getRequest();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
217
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
218 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
219
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
220 ArtifactDatabase db = getArtifactDatabase();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
222 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
223 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
224
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
225
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
226 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
227 * 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
228 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
229 * @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
230 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
231 * @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
232 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
233 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
234 return XMLUtils.xpathString(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
235 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
236 }
268
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
237
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
238
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
239 /**
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
240 * Returns the attribute for a collection of the incoming request document.
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
241 *
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
242 * @param request The request document.
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
243 *
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
244 * @return the contained attribute as document.
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
245 */
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
246 protected Document getCollectionAttribute(Document request) {
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
247 Node attr = (Node) XMLUtils.xpath(
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
248 request,
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
249 ArtifactDatabaseImpl.XPATH_COLLECTION_ATTRIBUTE,
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
250 XPathConstants.NODE,
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
251 ArtifactNamespaceContext.INSTANCE);
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
252
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
253 Document newAttr = XMLUtils.newDocument();
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
254
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
255 if (attr == null) {
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
256 logger.error("Collection attribute document not found!");
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
257 return newAttr;
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
258 }
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
259
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
260 newAttr.appendChild(newAttr.importNode(attr, true));
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
261
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
262 return newAttr;
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
263 }
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
264 }

http://dive4elements.wald.intevation.org