teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5861: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5861: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.server; ingo@32: ingo@32: import org.w3c.dom.Document; ingo@32: ingo@1367: import org.apache.log4j.Logger; ingo@1367: ingo@32: import com.google.gwt.user.server.rpc.RemoteServiceServlet; ingo@32: 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@32: 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@32: teichmann@5835: import org.dive4elements.river.client.shared.exceptions.ServerException; teichmann@5835: import org.dive4elements.river.client.shared.model.Artifact; teichmann@5835: import org.dive4elements.river.client.client.services.AdvanceService; ingo@32: ingo@32: ingo@32: /** ingo@32: * This interface provides artifact specific operation ADVANCE. ingo@32: * ingo@32: * @author Ingo Weinzierl ingo@32: */ ingo@32: public class AdvanceServiceImpl ingo@32: extends RemoteServiceServlet ingo@32: implements AdvanceService ingo@32: { ingo@1367: private static final Logger logger = Logger.getLogger(AdvanceService.class); ingo@1367: ingo@32: public static final String XPATH_RESULT = "/art:result/text()"; ingo@32: ingo@32: public static final String OPERATION_FAILURE = "FAILED"; ingo@32: ingo@215: public static final String ERROR_ADVANCE_ARTIFACT = "error_advance_artifact"; ingo@32: ingo@215: ingo@229: public Artifact advance( ingo@229: String locale, ingo@229: Artifact artifact, ingo@229: String target) ingo@215: throws ServerException ingo@215: { ingo@1367: logger.info("AdvanceServiceImpl.advance"); ingo@229: felix@3346: String url = getServletContext().getInitParameter("server-url"); raimund@1425: ingo@32: Document advance = ClientProtocolUtils.newAdvanceDocument( ingo@32: artifact.getUuid(), ingo@32: artifact.getHash(), ingo@32: target); ingo@32: raimund@1425: HttpClient client = new HttpClientImpl(url, locale); ingo@32: ingo@32: try { ingo@32: Document description = (Document) client.advance( teichmann@5835: new org.dive4elements.artifacts.httpclient.objects.Artifact( ingo@32: artifact.getUuid(), ingo@32: artifact.getHash()), ingo@32: advance, ingo@32: new DocumentResponseHandler()); ingo@32: ingo@32: if (description == null) { ingo@215: throw new ServerException(ERROR_ADVANCE_ARTIFACT); ingo@32: } ingo@32: ingo@32: String result = XMLUtils.xpathString( ingo@32: description, ingo@32: XPATH_RESULT, ingo@32: ArtifactNamespaceContext.INSTANCE); ingo@32: ingo@32: if (result == null || !result.equals(OPERATION_FAILURE)) { ingo@32: return (Artifact) new FLYSArtifactCreator().create(description); ingo@32: } ingo@32: } ingo@32: catch (ConnectionException ce) { ingo@1367: logger.error(ce, ce); ingo@32: } ingo@32: ingo@215: throw new ServerException(ERROR_ADVANCE_ARTIFACT); ingo@32: } ingo@32: } ingo@32: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :