comparison gwt-client/src/main/java/org/dive4elements/river/client/server/CreateCollectionServiceImpl.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-client/src/main/java/org/dive4elements/river/client/server/CreateCollectionServiceImpl.java@821a02bbfb4e
children 172338b1407f
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.client.server;
2
3 import org.w3c.dom.Document;
4
5 import org.apache.log4j.Logger;
6
7 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
8
9 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
10 import org.dive4elements.artifacts.common.utils.ClientProtocolUtils;
11 import org.dive4elements.artifacts.common.utils.XMLUtils;
12
13 import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException;
14 import org.dive4elements.artifacts.httpclient.http.HttpClient;
15 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl;
16 import org.dive4elements.artifacts.httpclient.http.response.DocumentResponseHandler;
17
18 import org.dive4elements.river.client.shared.exceptions.ServerException;
19 import org.dive4elements.river.client.shared.model.Collection;
20 import org.dive4elements.river.client.shared.model.DefaultCollection;
21 import org.dive4elements.river.client.client.services.CreateCollectionService;
22
23
24 /**
25 * This interface provides the createCollection service to create new
26 * collections in the artifact server.
27 *
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
29 */
30 public class CreateCollectionServiceImpl
31 extends RemoteServiceServlet
32 implements CreateCollectionService
33 {
34 /** Private logger. */
35 private static final Logger logger =
36 Logger.getLogger(CreateCollectionServiceImpl.class);
37
38 /** XPath to figure out the uuid of the created collection.*/
39 public static final String XPATH_COLLECTION_UUID =
40 "/art:result/art:artifact-collection/@art:uuid";
41
42 /** XPath to figure out the ttl of the created collection.*/
43 public static final String XPATH_COLLECTION_TTL =
44 "/art:result/art:artifact-collection/@art:ttl";
45
46 /** Error message key that is thrown if an error occured while creating
47 * a new collection.*/
48 public static final String ERROR_CREATE_COLLECTION =
49 "error_create_collection";
50
51
52 /** Attempt creation of Collection. */
53 public Collection create(String locale, String ownerId)
54 throws ServerException
55 {
56 logger.info("Start creating a new collection.");
57
58 String url = getServletContext().getInitParameter("server-url");
59
60 Document create =
61 ClientProtocolUtils.newCreateCollectionDocument(null);
62 HttpClient client = new HttpClientImpl(url, locale);
63
64 try {
65 Document doc = (Document) client.createCollection(
66 create, ownerId, new DocumentResponseHandler());
67
68 String uuid = XMLUtils.xpathString(
69 doc, XPATH_COLLECTION_UUID, ArtifactNamespaceContext.INSTANCE);
70
71 String ttlStr = XMLUtils.xpathString(
72 doc, XPATH_COLLECTION_TTL, ArtifactNamespaceContext.INSTANCE);
73
74 if (uuid.trim().length() == 0 || ttlStr.length() == 0) {
75 throw new ServerException(ERROR_CREATE_COLLECTION);
76 }
77
78 return new DefaultCollection(uuid, Long.valueOf(ttlStr), uuid);
79 }
80 catch (ConnectionException ce) {
81 logger.error(ce, ce);
82 }
83
84 throw new ServerException(ERROR_CREATE_COLLECTION);
85 }
86 }
87 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org