annotate artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CollectionResource.java @ 273:22a90706d32d

Enables the artifact server to set the TTL of a specific collection via REST call. artifacts/trunk@2070 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 07 Jun 2011 16:27:47 +0000
parents 4edaf3073109
children e92d5944fe4b
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
273
22a90706d32d Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 268
diff changeset
97 /** Action name for setting the ttl of a collection.*/
22a90706d32d Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 268
diff changeset
98 public static final String ACTION_SET_TTL = "settimetolive";
22a90706d32d Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 268
diff changeset
99
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 * 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
103 * 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
104 * artifact database 'db'.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 * @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
107 * @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
108 * @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
109 * @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
110 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 * @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
112 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 protected Representation dispatch(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 String identifier,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 String action,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 Document source,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 ArtifactDatabase db
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 ) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 Document out = null;
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 try {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 CallMeta meta = getCallMeta();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 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
125 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
126 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
127 }
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
128 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
129 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
130
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
131 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
132 }
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 else if (action.equals(ACTION_ADD_ARTIFACT)) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 String art = getArtifactIdentifier(source);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 logger.info("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
137 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
138 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 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
140 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
141
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 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
143 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
144 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 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
146 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
147 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
148 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 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
150 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
151
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
152 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
153
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
154 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
155
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
156 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
157 }
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
158 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
159 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
160
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 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
162 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
163 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 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
165 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
166
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
167 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
168 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
169 }
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
170 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
171 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
172
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 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
174 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
175 }
273
22a90706d32d Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 268
diff changeset
176 else if (action.equals(ACTION_SET_TTL)) {
22a90706d32d Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 268
diff changeset
177 out = db.setCollectionTTL(identifier, source, meta);
22a90706d32d Enables the artifact server to set the TTL of a specific collection via REST call.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 268
diff changeset
178 }
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 else {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180 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
181 }
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 catch (ArtifactDatabaseException adbe) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 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
185
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187 response.setStatus(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 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
189 return new EmptyRepresentation();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
190 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
192 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
193 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
195
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196 @Override
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
197 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
198 Document input = null;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 try {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200 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
201 in.setNamespaceAware(true);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202 input = in.getDocument();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204 catch (IOException ioe) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
205 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
206
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
207 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
208 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
209 return new EmptyRepresentation();
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
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
212 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
213 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
214
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
215 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
216 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
217 response.setStatus(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
218 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
219 return new EmptyRepresentation();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
220 }
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 Request request = getRequest();
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 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
225
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
226 ArtifactDatabase db = getArtifactDatabase();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
227
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
228 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
229 }
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
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 * 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
234 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
235 * @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
236 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
237 * @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
238 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
239 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
240 return XMLUtils.xpathString(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
241 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
242 }
268
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
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 * 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
247 *
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
248 * @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
249 *
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
250 * @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
251 */
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
252 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
253 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
254 request,
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
255 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
256 XPathConstants.NODE,
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
257 ArtifactNamespaceContext.INSTANCE);
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 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
260
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
261 if (attr == null) {
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
262 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
263 return newAttr;
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
264 }
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
265
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
266 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
267
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
268 return newAttr;
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
269 }
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
270 }

http://dive4elements.wald.intevation.org