teichmann@5835: package org.dive4elements.river.client.server; ingo@26: ingo@26: import org.w3c.dom.Document; ingo@26: ingo@1367: import org.apache.log4j.Logger; ingo@1367: ingo@26: import com.google.gwt.user.server.rpc.RemoteServiceServlet; ingo@26: teichmann@5835: import org.dive4elements.artifacts.common.ArtifactNamespaceContext; teichmann@5835: import org.dive4elements.artifacts.common.utils.ClientProtocolUtils; teichmann@5835: import org.dive4elements.artifacts.common.utils.XMLUtils; ingo@26: teichmann@5835: import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; teichmann@5835: import org.dive4elements.artifacts.httpclient.http.HttpClient; teichmann@5835: import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; teichmann@5835: import org.dive4elements.artifacts.httpclient.http.response.DocumentResponseHandler; ingo@26: teichmann@5835: import org.dive4elements.river.client.shared.exceptions.ServerException; teichmann@5835: import org.dive4elements.river.client.shared.model.Collection; teichmann@5835: import org.dive4elements.river.client.shared.model.DefaultCollection; teichmann@5835: import org.dive4elements.river.client.client.services.CreateCollectionService; ingo@26: ingo@26: ingo@26: /** ingo@26: * This interface provides the createCollection service to create new ingo@26: * collections in the artifact server. ingo@26: * ingo@26: * @author Ingo Weinzierl ingo@26: */ ingo@26: public class CreateCollectionServiceImpl ingo@26: extends RemoteServiceServlet ingo@26: implements CreateCollectionService ingo@26: { felix@2941: /** Private logger. */ ingo@1367: private static final Logger logger = ingo@1367: Logger.getLogger(CreateCollectionServiceImpl.class); ingo@1367: ingo@26: /** XPath to figure out the uuid of the created collection.*/ ingo@26: public static final String XPATH_COLLECTION_UUID = ingo@26: "/art:result/art:artifact-collection/@art:uuid"; ingo@26: ingo@587: /** XPath to figure out the ttl of the created collection.*/ ingo@587: public static final String XPATH_COLLECTION_TTL = ingo@587: "/art:result/art:artifact-collection/@art:ttl"; ingo@587: ingo@215: /** Error message key that is thrown if an error occured while creating ingo@215: * a new collection.*/ ingo@215: public static final String ERROR_CREATE_COLLECTION = ingo@215: "error_create_collection"; ingo@26: ingo@215: felix@2941: /** Attempt creation of Collection. */ raimund@1425: public Collection create(String locale, String ownerId) ingo@215: throws ServerException ingo@215: { ingo@1367: logger.info("Start creating a new collection."); ingo@26: raimund@1425: String url = getServletContext().getInitParameter("server-url"); raimund@1425: felix@1430: Document create = ingo@71: ClientProtocolUtils.newCreateCollectionDocument(null); raimund@1425: HttpClient client = new HttpClientImpl(url, locale); ingo@26: ingo@26: try { ingo@26: Document doc = (Document) client.createCollection( ingo@26: create, ownerId, new DocumentResponseHandler()); ingo@26: ingo@71: String uuid = XMLUtils.xpathString( ingo@26: doc, XPATH_COLLECTION_UUID, ArtifactNamespaceContext.INSTANCE); ingo@71: ingo@587: String ttlStr = XMLUtils.xpathString( ingo@587: doc, XPATH_COLLECTION_TTL, ArtifactNamespaceContext.INSTANCE); ingo@587: ingo@587: if (uuid.trim().length() == 0 || ttlStr.length() == 0) { ingo@215: throw new ServerException(ERROR_CREATE_COLLECTION); ingo@215: } ingo@215: ingo@856: return new DefaultCollection(uuid, Long.valueOf(ttlStr), uuid); ingo@26: } ingo@26: catch (ConnectionException ce) { ingo@1367: logger.error(ce, ce); ingo@26: } ingo@26: ingo@215: throw new ServerException(ERROR_CREATE_COLLECTION); ingo@26: } ingo@26: } ingo@26: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :