comparison artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CreateResource.java @ 32:c2d53bd30ab8

Re-factored artifact API for better integration of background processing. artifacts/trunk@78 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 13 Sep 2009 14:50:53 +0000
parents 83a059c204f8
children af22d4de275c
comparison
equal deleted inserted replaced
31:c4d85a8532d1 32:c2d53bd30ab8
21 import org.restlet.representation.EmptyRepresentation; 21 import org.restlet.representation.EmptyRepresentation;
22 22
23 import java.io.IOException; 23 import java.io.IOException;
24 24
25 import de.intevation.artifacts.ArtifactNamespaceContext; 25 import de.intevation.artifacts.ArtifactNamespaceContext;
26 import de.intevation.artifacts.ArtifactDatabaseException;
26 import de.intevation.artifacts.ArtifactDatabase; 27 import de.intevation.artifacts.ArtifactDatabase;
27 import de.intevation.artifacts.Artifact;
28 28
29 /** 29 /**
30 * @author Sascha L. Teichmann (sascha.teichmann@intevation) 30 * @author Sascha L. Teichmann (sascha.teichmann@intevation)
31 */ 31 */
32 public class CreateResource 32 public class CreateResource
66 XPATH_FACTORY, 66 XPATH_FACTORY,
67 ArtifactNamespaceContext.INSTANCE); 67 ArtifactNamespaceContext.INSTANCE);
68 68
69 if (factory == null || factory.length() == 0) { 69 if (factory == null || factory.length() == 0) {
70 Response response = getResponse(); 70 Response response = getResponse();
71 response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, NO_FACTORY_MESSAGE); 71 response.setStatus(
72 Status.CLIENT_ERROR_BAD_REQUEST, NO_FACTORY_MESSAGE);
72 return new EmptyRepresentation(); 73 return new EmptyRepresentation();
73 } 74 }
74 75
75 if (logger.isDebugEnabled()) { 76 if (logger.isDebugEnabled()) {
76 logger.debug("Create artifact with factory '" + factory + "'"); 77 logger.debug("Create artifact with factory '" + factory + "'");
77 } 78 }
78 79
79 ArtifactDatabase db = (ArtifactDatabase)getContext() 80 ArtifactDatabase db = (ArtifactDatabase)getContext()
80 .getAttributes().get("database"); 81 .getAttributes().get("database");
81 82
82 Artifact artifact = db.createArtifactWithFactory(factory); 83 try {
83 84 return new DomRepresentation(
84 if (artifact == null) { 85 MediaType.APPLICATION_XML,
86 db.createArtifactWithFactory(factory));
87 }
88 catch (ArtifactDatabaseException adbe) {
85 Response response = getResponse(); 89 Response response = getResponse();
86 response.setStatus(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY, NO_ARTIFACT_CREATED); 90 response.setStatus(
91 Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY, adbe.getMessage());
87 return new EmptyRepresentation(); 92 return new EmptyRepresentation();
88 } 93 }
89
90 Document outputDocument = artifact.describe(
91 db.getArtifactContext());
92
93 return new DomRepresentation(
94 MediaType.APPLICATION_XML, outputDocument);
95 } 94 }
96 } 95 }
97 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: 96 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org