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

Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data to the Artifact-Implementation. artifacts/trunk@649 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 01 Feb 2010 13:54:05 +0000
parents 82f62ef25a8f
children 48d1a9a082c2
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 /**
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 * @author Sascha L. Teichmann (sascha.teichmann@intevation)
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 */
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 public class CreateResource
40
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 32
diff changeset
24 extends BaseResource
21
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 {
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 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
27
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 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
29
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
30 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
31
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
32 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
33
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
34 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
35
40
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 32
diff changeset
36 protected Representation innerPost(Representation requestRepr)
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 32
diff changeset
37 throws ResourceException
af22d4de275c Log RuntimeExceptions in REST calls to log4j.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 32
diff changeset
38 {
21
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 Document inputDocument = null;
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 try {
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 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
42 input.setNamespaceAware(true);
21
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 inputDocument = input.getDocument();
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 }
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 catch (IOException ioe) {
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 logger.error(ioe.getMessage());
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 Response response = getResponse();
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 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
49 return new EmptyRepresentation();
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 }
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
51
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
52 String factory = XMLUtils.xpathString(
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
53 inputDocument,
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
54 XPATH_FACTORY,
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
55 ArtifactNamespaceContext.INSTANCE);
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
56
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
57 if (factory == null || factory.length() == 0) {
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
58 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
59 response.setStatus(
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
60 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
61 return new EmptyRepresentation();
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
62 }
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
63
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
64 if (logger.isDebugEnabled()) {
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
65 logger.debug("Create artifact with factory '" + factory + "'");
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
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
68 ArtifactDatabase db = (ArtifactDatabase)getContext()
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
69 .getAttributes().get("database");
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
70
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
71 try {
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
72 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
73 MediaType.APPLICATION_XML,
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
74 db.createArtifactWithFactory(factory,
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
75 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
76 inputDocument));
32
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
77 }
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
78 catch (ArtifactDatabaseException adbe) {
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
79 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
80 response.setStatus(
c2d53bd30ab8 Re-factored artifact API for better integration of background processing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
81 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
82 return new EmptyRepresentation();
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 22
diff changeset
83 }
21
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 }
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 }
1cd268e07e44 Added resource to create artifacts to web server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org