annotate artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CreateResource.java @ 89:d348fe1fd822

More javadoc (fixes small glitches, too). artifacts/trunk@845 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 26 Mar 2010 16:16:32 +0000
parents 69c84cf7c5d7
children 730ff077a58c
rev   line source
21
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.artifactdatabase.rest;
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.io.IOException;
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
75
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
5 import org.apache.log4j.Logger;
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
6 import org.restlet.data.MediaType;
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
7 import org.restlet.data.Response;
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
8 import org.restlet.data.Status;
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
9 import org.restlet.ext.xml.DomRepresentation;
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
10 import org.restlet.representation.EmptyRepresentation;
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
11 import org.restlet.representation.Representation;
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
12 import org.restlet.resource.ResourceException;
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
13 import org.w3c.dom.Document;
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
14
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
15 import de.intevation.artifactdatabase.XMLUtils;
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
16 import de.intevation.artifacts.ArtifactDatabase;
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
17 import de.intevation.artifacts.ArtifactDatabaseException;
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
18 import de.intevation.artifacts.ArtifactNamespaceContext;
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
19
21
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 /**
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
21 * Resource to create a new artifact within artifact database.
77
48d1a9a082c2 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 75
diff changeset
22 * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a>
21
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 */
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 public class CreateResource
40
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 32
diff changeset
25 extends BaseResource
21
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 {
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 private static Logger logger = Logger.getLogger(CreateResource.class);
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
29 /**
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
30 * server URL where to reach the resource.
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
31 */
21
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 public static final String PATH = "/create";
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
34 /**
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
35 * XPATH to figure out the name of the factory which should be used
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
36 * to create the new artifact.
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
37 */
65
82f62ef25a8f Create namespace aware documents for 'create' and 'out' targets. Adapted XPath expressions for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 48
diff changeset
38 public static final String XPATH_FACTORY = "/art:action/art:factory/@name";
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
39
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
40 /**
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
41 * Error message if no factory was given.
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
42 */
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
43 public static final String NO_FACTORY_MESSAGE = "No factory given";
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
44
88
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
45 /**
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
46 * Error message if no artifact was created.
69c84cf7c5d7 Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 86
diff changeset
47 */
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
48 public static final String NO_ARTIFACT_CREATED = "No artifact created";
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
49
89
d348fe1fd822 More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 88
diff changeset
50 @Override
40
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 32
diff changeset
51 protected Representation innerPost(Representation requestRepr)
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 32
diff changeset
52 throws ResourceException
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 32
diff changeset
53 {
21
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 Document inputDocument = null;
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 try {
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 DomRepresentation input = new DomRepresentation(requestRepr);
65
82f62ef25a8f Create namespace aware documents for 'create' and 'out' targets. Adapted XPath expressions for this.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 48
diff changeset
57 input.setNamespaceAware(true);
21
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 inputDocument = input.getDocument();
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 }
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 catch (IOException ioe) {
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 logger.error(ioe.getMessage());
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 Response response = getResponse();
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ioe);
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 return new EmptyRepresentation();
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 }
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
66
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
67 String factory = XMLUtils.xpathString(
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
68 inputDocument,
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
69 XPATH_FACTORY,
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
70 ArtifactNamespaceContext.INSTANCE);
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
71
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
72 if (factory == null || factory.length() == 0) {
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
73 Response response = getResponse();
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
74 response.setStatus(
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
75 Status.CLIENT_ERROR_BAD_REQUEST, NO_FACTORY_MESSAGE);
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
76 return new EmptyRepresentation();
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
77 }
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
78
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
79 if (logger.isDebugEnabled()) {
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
80 logger.debug("Create artifact with factory '" + factory + "'");
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
81 }
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
82
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
83 ArtifactDatabase db = (ArtifactDatabase)getContext()
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
84 .getAttributes().get("database");
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
85
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
86 try {
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
87 return new DomRepresentation(
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
88 MediaType.APPLICATION_XML,
86
b2e0cb83631c Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
89 db.createArtifactWithFactory(factory,
75
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
90 getCallMeta(),
d4c4c23847f5 Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
Tim Englich <tim.englich@intevation.de>
parents: 65
diff changeset
91 inputDocument));
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
92 }
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
93 catch (ArtifactDatabaseException adbe) {
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
94 Response response = getResponse();
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
95 response.setStatus(
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
96 Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY, adbe.getMessage());
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
97 return new EmptyRepresentation();
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
98 }
21
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 }
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 }
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org