# HG changeset patch # User Bjoern Ricks # Date 1348822668 0 # Node ID 436eec3be6ff5a62af0748224dc36fb72ee3bdf7 # Parent c434dd2e84cf04566ababc23d8ca89c7b66e1086 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 diff -r c434dd2e84cf -r 436eec3be6ff flys-client/ChangeLog --- a/flys-client/ChangeLog Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/ChangeLog Fri Sep 28 08:57:48 2012 +0000 @@ -1,3 +1,22 @@ +2012-09-29 Björn Ricks + + * src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java, + src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java, + src/main/java/de/intevation/flys/client/server/ArtifactHelper.java, + src/main/java/de/intevation/flys/client/shared/model/GaugeDischargeCurveArtifact.java, + src/main/java/de/intevation/flys/client/client/services/ArtifactService.java, + src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java, + src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants.java, + src/main/java/de/intevation/flys/client/client/FLYS.java, + src/main/java/de/intevation/flys/client/client/FLYSConstants.properties, + src/main/java/de/intevation/flys/client/client/ui/ParameterList.java, + src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java, + src/main/java/de/intevation/flys/client/client/ui/GaugeTree.java: + Allow to create a discharge curve from a gauge info. + Currently the dicharge curve will not be displayed. + 2012-09-29 Björn Ricks * src/main/java/de/intevation/flys/client/shared/model/DefaultGaugeInfo.java, diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYS.java Fri Sep 28 08:57:48 2012 +0000 @@ -17,6 +17,8 @@ import de.intevation.flys.client.client.event.CollectionChangeHandler; import de.intevation.flys.client.client.services.ArtifactService; import de.intevation.flys.client.client.services.ArtifactServiceAsync; +import de.intevation.flys.client.client.services.CreateCollectionService; +import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; import de.intevation.flys.client.client.services.DescribeCollectionService; import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync; import de.intevation.flys.client.client.services.GetArtifactService; @@ -72,6 +74,9 @@ protected GetArtifactServiceAsync getArtifactService = GWT.create(GetArtifactService.class); + /** The CreateCollectionServiceAsync used to create a new collection */ + protected CreateCollectionServiceAsync collectionService = + GWT.create(CreateCollectionService.class); /** The menu bar at the top of the application. */ protected MainMenu menu; @@ -440,6 +445,55 @@ }); } + public void newGaugeDischargeCurve(String river, Long gaugeref) { + Config config = Config.getInstance(); + + final String locale = config.getLocale(); + final String riv = river; + final Long ref = gaugeref; + final FLYS flys = this; + + User user = getCurrentUser(); + + if (user == null) { + SC.warn(MSG.error_not_logged_in()); + return; + } + + collectionService.create(locale, user.identifier(), + new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not create new collection."); + SC.warn(MSG.getString(caught.getMessage())); + } + + @Override + public void onSuccess(Collection collection) { + GWT.log("Successfully created a new collection."); + final Collection col = collection; + artifactService.createGaugeDischargeCurverArtifact( + col, locale, riv, ref, + new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + GWT.log("Could not create the new artifact."); + SC.warn(MSG.getString(caught.getMessage())); + } + + @Override + public void onSuccess(Artifact artifact) { + GWT.log("Successfully created a new artifact."); + CollectionView view = new CollectionView(flys, + col, artifact); + workspace.addView("new-project", view); + + view.addCollectionChangeHandler(getProjectList()); + } + }); + } + }); + } @Override public void onCollectionChange(CollectionChangeEvent event) { diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Fri Sep 28 08:57:48 2012 +0000 @@ -406,6 +406,8 @@ String discharge_curve(); + String gauge_discharge_curve(); + String computed_discharge_curve(); String computed_discharge_curves(); @@ -1043,5 +1045,7 @@ String gauge_river_url(); String gauge_url(); + + String gauge_curve_link(); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Fri Sep 28 08:57:48 2012 +0000 @@ -195,6 +195,7 @@ add = Add discharge_curve = Discharge Curves at Gauges +gauge_discharge_curve = Discharge Curves at Gauge computed_discharge_curve = Discharge Curve computed_discharge_curves = Discharge Curves longitudinal_section = Longitudinal Section Curve @@ -542,3 +543,4 @@ gauge_info_link = Gaugeinfo gauge_url = https://flys-intern.intevation.de/PegelInfo/ gauge_river_url = https://flys-intern.intevation.de/GewaesserInfo/ +gauge_curve_link = Dischargecurve diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Fri Sep 28 08:57:48 2012 +0000 @@ -194,6 +194,7 @@ chartPropertiesTooltip = Diagrammeigenschaften discharge_curve = Abflusskurven an Pegeln +gauge_discharge_curve = Abflusskurven an Pegel computed_discharge_curve = Abflusskurve computed_discharge_curves = Abflusskurven longitudinal_section = L\u00e4ngsschnitt @@ -540,3 +541,4 @@ gauge_info_link = Pegelinfo gauge_url = https://flys-intern.intevation.de/PegelInfo/ gauge_river_url = https://flys-intern.intevation.de/GewaesserInfo/ +gauge_curve_link = Abflusskurve diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Fri Sep 28 08:57:48 2012 +0000 @@ -195,6 +195,7 @@ add = Add discharge_curve = Discharge Curves at Gauges +gauge_discharge_curve = Discharge Curves at Gauge computed_discharge_curve = Discharge Curve computed_discharge_curves = Discharge Curves longitudinal_section = Longitudinal Section Curve @@ -541,3 +542,4 @@ gauge_info_link = Gaugeinfo gauge_url = https://flys-intern.intevation.de/PegelInfo/ gauge_river_url = https://flys-intern.intevation.de/GewaesserInfo/ +gauge_curve_link = Dischargecurve diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactService.java Fri Sep 28 08:57:48 2012 +0000 @@ -5,6 +5,7 @@ import de.intevation.flys.client.shared.exceptions.ServerException; import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.Recommendation; @@ -31,5 +32,19 @@ String factory, Recommendation recommendation ) throws ServerException; + + /** + * Create a new GaugeDischageCurveArtifact + * + * @param collection the collection to add the artifact to + * @param river the river + * @param gaugeref reference id of the gauge + */ + public Artifact createGaugeDischargeCurverArtifact( + Collection collection, + String locale, + String river, + Long gaugeref + ) throws ServerException; } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ArtifactServiceAsync.java Fri Sep 28 08:57:48 2012 +0000 @@ -3,6 +3,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback; import de.intevation.flys.client.shared.model.Artifact; +import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.Recommendation; @@ -19,5 +20,13 @@ String factory, Recommendation recommendation, AsyncCallback callback); + + public void createGaugeDischargeCurverArtifact( + Collection collection, + String locale, + String river, + Long gaugeref, + AsyncCallback callback + ); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java Fri Sep 28 08:57:48 2012 +0000 @@ -13,6 +13,7 @@ import com.smartgwt.client.widgets.layout.SectionStackSection; import com.smartgwt.client.widgets.layout.VLayout; +import de.intevation.flys.client.client.FLYS; import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.client.services.GaugeOverviewInfoService; import de.intevation.flys.client.client.services.GaugeOverviewInfoServiceAsync; @@ -37,19 +38,24 @@ /** The message class that provides i18n strings.*/ protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + private FLYS flys; + protected GaugeOverviewInfoServiceAsync gaugeOverviewInfoService = GWT.create(GaugeOverviewInfoService.class); - protected GaugeTree gaugetree = new GaugeTree(); + protected GaugeTree gaugetree; protected RiverInfoPanel riverinfopanel; /** * Creates a new VLayout with a SectionStackSection * The GaugePanel's SectionStackSection is hidden by default. + * + * @param flys The FLYS object * @param sectionStack The section stack section to place the VLayout in. */ - public GaugePanel(SectionStackSection sectionStack) { + public GaugePanel(FLYS flys, SectionStackSection sectionStack) { + gaugetree = new GaugeTree(flys); setOverflow(Overflow.HIDDEN); sectionStack.setHidden(true); sectionStack.setItems(this); diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTree.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTree.java Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTree.java Fri Sep 28 08:57:48 2012 +0000 @@ -5,6 +5,8 @@ import java.util.Iterator; import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.user.client.ui.Anchor; import com.google.gwt.user.client.ui.DecoratorPanel; @@ -16,6 +18,7 @@ import com.smartgwt.client.widgets.layout.HLayout; +import de.intevation.flys.client.client.FLYS; import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.shared.model.Data; @@ -27,13 +30,15 @@ public class GaugeTree extends ScrollPanel { + private FLYS flys; private Tree tree; private DataList[] data; /** The message class that provides i18n strings.*/ protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - public GaugeTree() { + public GaugeTree(FLYS flys) { + this.flys = flys; tree = new Tree(); setWidget(tree); } @@ -82,7 +87,7 @@ } private void addGauge(GaugeInfo gauge) { - GaugeInfoItem gaugeitem = new GaugeInfoItem(gauge); + GaugeInfoItem gaugeitem = new GaugeInfoItem(flys, gauge); tree.addItem(gaugeitem); } @@ -315,8 +320,8 @@ private GaugeInfo gauge; - public GaugeInfoItem(GaugeInfo gauge) { - GaugeInfoHead gaugeinfohead = new GaugeInfoHead(gauge); + public GaugeInfoItem(FLYS flys, GaugeInfo gauge) { + GaugeInfoHead gaugeinfohead = new GaugeInfoHead(flys, gauge); GaugeInfoPanel gaugeinfopanel = new GaugeInfoPanel(gauge); setWidget(gaugeinfohead); addItem(gaugeinfopanel); @@ -338,7 +343,7 @@ class GaugeInfoHead extends HLayout { - public GaugeInfoHead(GaugeInfo gauge) { + public GaugeInfoHead(FLYS flys, GaugeInfo gauge) { setStyleName("gaugeinfohead"); setAutoHeight(); setAutoWidth(); @@ -390,6 +395,29 @@ MSG.gauge_url(); Anchor anchor = new Anchor(MSG.gauge_info_link(), url); addMember(anchor); + + addMember(new GaugeCurveAnchor(flys, gauge)); + } + } + + class GaugeCurveAnchor extends Anchor implements ClickHandler { + + private FLYS flys; + private GaugeInfo gauge; + + public GaugeCurveAnchor(FLYS flys, GaugeInfo gauge) { + super(MSG.gauge_curve_link()); + this.flys = flys; + this.gauge = gauge; + + addClickHandler(this); + } + + public void onClick(ClickEvent ev) { + GWT.log("GaugeCurveAnchor - onClick " + gauge.getRiverName() + + " " + gauge.getOfficialNumber()); + flys.newGaugeDischargeCurve(gauge.getRiverName(), + gauge.getOfficialNumber()); } } diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java Fri Sep 28 08:57:48 2012 +0000 @@ -212,7 +212,7 @@ final SectionStackSection gaugeSection = new SectionStackSection(); gaugeSection.setExpanded(false); gaugeSection.setTitle(MSG.gaugePanelTitle()); - gaugePanel = new GaugePanel(gaugeSection) { + gaugePanel = new GaugePanel(flys, gaugeSection) { public void addMember(Canvas component) { super.addMember(component); gaugeSection.setExpanded(true); diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/server/ArtifactHelper.java --- 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 Ingo Weinzierl */ @@ -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); diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java Fri Sep 28 08:57:48 2012 +0000 @@ -8,6 +8,7 @@ import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.client.services.ArtifactService; +import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.Recommendation; /** @@ -48,5 +49,34 @@ return ArtifactHelper.createArtifact(url, locale, factory, recom); } + + /** + * Create a new GaugeDischageCurveArtifact + * + * @param river the river + * @param gaugeref reference id of the gauge + */ + public Artifact createGaugeDischargeCurveArtifact( + Collection collection, + String locale, + String river, + Long gaugeref) + throws ServerException + { + logger.info("ArtifactServiceImpl.createGaugeDischargeCurverArtifact"); + String url = getServletContext().getInitParameter("server-url"); + + Artifact artifact = ArtifactHelper.createGaugeDischargeCurveArtifact(url, + locale, river, gaugeref); + if (artifact == null) { + return null; + } + logger.info("GaugeDischargeCurveArtifact created successfully"); + + CollectionHelper.addArtifact(collection, artifact, url, locale); + + return artifact; + } + } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java Fri Sep 28 08:52:53 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java Fri Sep 28 08:57:48 2012 +0000 @@ -18,12 +18,13 @@ import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.CalculationMessage; +import de.intevation.flys.client.shared.model.ChartArtifact; import de.intevation.flys.client.shared.model.DefaultArtifact; +import de.intevation.flys.client.shared.model.FixAnalysisArtifact; +import de.intevation.flys.client.shared.model.GaugeDischargeCurveArtifact; +import de.intevation.flys.client.shared.model.MapArtifact; import de.intevation.flys.client.shared.model.MINFOArtifact; import de.intevation.flys.client.shared.model.WINFOArtifact; -import de.intevation.flys.client.shared.model.MapArtifact; -import de.intevation.flys.client.shared.model.ChartArtifact; -import de.intevation.flys.client.shared.model.FixAnalysisArtifact; /** @@ -144,6 +145,10 @@ logger.debug("+++++ NEW FIXANALYSIS ARTIFACT."); return new FixAnalysisArtifact(uuid, hash, background, msg); } + else if (name.length() > 0 && name.equals("gaugedischargecurve")) { + logger.debug("+++++ NEW WINFO ARTIFACT."); + return new GaugeDischargeCurveArtifact(uuid, hash, background, msg); + } return new DefaultArtifact(uuid, hash, background, msg); } diff -r c434dd2e84cf -r 436eec3be6ff flys-client/src/main/java/de/intevation/flys/client/shared/model/GaugeDischargeCurveArtifact.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/GaugeDischargeCurveArtifact.java Fri Sep 28 08:57:48 2012 +0000 @@ -0,0 +1,39 @@ +package de.intevation.flys.client.shared.model; + +import java.util.List; + +/** + * The GaugeDischargeCurveArtifact implementation of an Artifact. + * + * @author Björn Ricks + */ +public class GaugeDischargeCurveArtifact extends DefaultArtifact { + + /** The name of this artifact */ + public static final String NAME = "gauge_discharge_curve"; + + + public GaugeDischargeCurveArtifact() { + } + + + public GaugeDischargeCurveArtifact(String uuid, String hash) { + super(uuid, hash); + } + + + public GaugeDischargeCurveArtifact( + String uuid, + String hash, + boolean inBackground, + List messages + ) { + super(uuid, hash, inBackground, messages); + } + + + public String getName() { + return NAME; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 :