Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/server/ArtifactHelper.java @ 3865:436eec3be6ff
Allow to create a discharge curve from a gauge info
This is only a draft yet.
flys-client/trunk@5639 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 08:57:48 +0000 |
parents | ab8eb2f544f2 |
children | b660090b417d |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactHelper.java Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactHelper.java Fri Sep 28 08:57:48 2012 +0000 @@ -1,6 +1,7 @@ package de.intevation.flys.client.server; import org.w3c.dom.Document; +import org.w3c.dom.Element; import org.apache.log4j.Logger; @@ -14,13 +15,14 @@ import de.intevation.artifacts.httpclient.exceptions.ConnectionException; import de.intevation.artifacts.httpclient.http.HttpClient; import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.utils.ArtifactNamespaceContext; +import de.intevation.artifacts.httpclient.utils.XMLUtils; import de.intevation.flys.client.shared.exceptions.ServerException; import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.Recommendation; - /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ @@ -33,6 +35,11 @@ * creation.*/ public static final String ERROR_CREATE_ARTIFACT = "error_create_artifact"; + /** + * Name of the factory to generate a GaugeDischargeCurveArtifact + */ + private static final String GAUGE_DISCHARGE_CURVE_ARTIFACT = "gaugedischargecurve"; + private ArtifactHelper() { } @@ -68,10 +75,58 @@ Document create = ClientProtocolUtils.newCreateDocument( factory, uuid, ids, filter); + return sendCreate(serverUrl, locale, create); + + } + + /** + * Creates a new GaugeDischargeCurverArtifact + * + * @param river the name of the river + * @param reference the reference id of the gauge (official number) + */ + public static Artifact createGaugeDischargeCurveArtifact( + String serverUrl, + String locale, + String river, + Long reference) + throws ServerException + { + Document create = ClientProtocolUtils.newCreateDocument( + GAUGE_DISCHARGE_CURVE_ARTIFACT); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + create, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element root = create.getDocumentElement(); + + Element eriver = ec.create("river"); + ec.addAttr(eriver, "name", river); + + Element egauge = ec.create("gauge"); + ec.addAttr(egauge, "reference", reference.toString()); + + root.appendChild(eriver); + root.appendChild(egauge); + + return sendCreate(serverUrl, locale, create); + } + + /** + * Sends a create document to the artifact server + */ + private static Artifact sendCreate( + String serverUrl, + String locale, + Document doc) + throws ServerException + { HttpClient client = new HttpClientImpl(serverUrl, locale); try { - return (Artifact) client.create(create, new FLYSArtifactCreator()); + return (Artifact) client.create(doc, new FLYSArtifactCreator()); } catch (ConnectionException ce) { logger.error(ce, ce);