annotate artifact-database/src/main/java/org/dive4elements/artifactdatabase/rest/CollectionResource.java @ 570:584591f8203c 3.2.x

Upgrade to Log4j 2
author Tom Gottfried <tom@intevation.de>
date Mon, 28 Feb 2022 17:41:14 +0100
parents 415df0fc4fa1
children
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 */
475
415df0fc4fa1 Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents: 473
diff changeset
8 package org.dive4elements.artifactdatabase.rest;
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9
475
415df0fc4fa1 Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents: 473
diff changeset
10 import org.dive4elements.artifacts.ArtifactDatabase;
415df0fc4fa1 Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents: 473
diff changeset
11 import org.dive4elements.artifacts.ArtifactDatabaseException;
415df0fc4fa1 Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents: 473
diff changeset
12 import org.dive4elements.artifacts.CallMeta;
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13
475
415df0fc4fa1 Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents: 473
diff changeset
14 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
415df0fc4fa1 Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents: 473
diff changeset
15 import org.dive4elements.artifacts.common.utils.XMLUtils;
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16
475
415df0fc4fa1 Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents: 473
diff changeset
17 import org.dive4elements.artifactdatabase.ArtifactDatabaseImpl;
268
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
570
584591f8203c Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 475
diff changeset
23 import org.apache.logging.log4j.Logger;
584591f8203c Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 475
diff changeset
24 import org.apache.logging.log4j.LogManager;
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25
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.MediaType;
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.data.Status;
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.ext.xml.DomRepresentation;
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.EmptyRepresentation;
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.representation.Representation;
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.Request;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 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
33
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 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
35 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
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 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 * @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
40 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 public class CollectionResource
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 extends BaseResource
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 /** The logger that is used in this class.*/
570
584591f8203c Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 475
diff changeset
45 private static Logger logger = LogManager.getLogger(CollectionResource.class);
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 /** 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
48 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
49
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 * XPath to figure out the 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
52 * incoming POST request.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 public static final String XPATH_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
55
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 * 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
58 * action.
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 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
61 "/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
62
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 /** 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
64 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
65
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 /** 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
67 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
68
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 /** Action name for deleting a collection.*/
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 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
71
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
72 /** 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
73 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
74
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
75 /** 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
76 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
77
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 /** 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
79 * 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
80 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
81
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 /** 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
83 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
84
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 /** 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
86 * 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
87 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
88
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 /** 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
90 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
91
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 /** 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
93 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
94
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 /** 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
96 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
97
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
98 /** 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
99 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
100
275
e92d5944fe4b Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 273
diff changeset
101 /** Action name for setting the name of a collection.*/
e92d5944fe4b Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 273
diff changeset
102 public static final String ACTION_SET_NAME = "setname";
e92d5944fe4b Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 273
diff changeset
103
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 * 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
107 * 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
108 * artifact database 'db'.
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 * @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
111 * @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
112 * @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
113 * @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
114 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 * @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
116 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 protected Representation dispatch(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 String identifier,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 String action,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 Document source,
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 ArtifactDatabase db
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 ) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 Document out = null;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 try {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 CallMeta meta = getCallMeta();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 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
129 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
130 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
131 }
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
132 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
133 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
134
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
135 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
136 }
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 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
138 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
139
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 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
141 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
142 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 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
144 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
145
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 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
147 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
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_LIST_ARTIFACTS)) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 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
151 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
152 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 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
154 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
155
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
156 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
157
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
158 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
159
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
160 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
161 }
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
162 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
163 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
164
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 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
166 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
167 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 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
169 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
170
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
171 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
172 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
173 }
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
174 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
175 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
176
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 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
178 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
179 }
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
180 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
181 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
182 }
275
e92d5944fe4b Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 273
diff changeset
183 else if (action.equals(ACTION_SET_NAME)) {
e92d5944fe4b Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 273
diff changeset
184 out = db.setCollectionName(identifier, source, meta);
e92d5944fe4b Enabled the artifact database to retrieve requests to change the name of a specific collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 273
diff changeset
185 }
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 else {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187 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
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 catch (ArtifactDatabaseException adbe) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191 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
192
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194 response.setStatus(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
195 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
196 return new EmptyRepresentation();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
197 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 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
200 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 @Override
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204 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
205 Document input = null;
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
206 try {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
207 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
208 in.setNamespaceAware(true);
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209 input = in.getDocument();
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 catch (IOException ioe) {
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
212 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
213
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
214 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
215 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
216 return new EmptyRepresentation();
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
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
219 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
220 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
221
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
222 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
223 Response response = getResponse();
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
224 response.setStatus(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
225 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
226 return new EmptyRepresentation();
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
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
229 Request request = getRequest();
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 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
232
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
233 ArtifactDatabase db = getArtifactDatabase();
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 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
236 }
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
237
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 /**
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
240 * 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
241 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
242 * @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
243 *
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
244 * @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
245 */
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
246 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
247 return XMLUtils.xpathString(
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
248 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
249 }
268
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
250
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 /**
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
253 * 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
254 *
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
255 * @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
256 *
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
257 * @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
258 */
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
259 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
260 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
261 request,
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
262 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
263 XPathConstants.NODE,
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
264 ArtifactNamespaceContext.INSTANCE);
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 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
267
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
268 if (attr == null) {
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
269 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
270 return newAttr;
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
271 }
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
272
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
273 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
274
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
275 return newAttr;
4edaf3073109 Repaired the setting of a new attribute for a Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 253
diff changeset
276 }
142
e986e32bc7d4 Added a Rest resource that handles operations specific to a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
277 }

http://dive4elements.wald.intevation.org