diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeListGrid.java @ 8303:519023ce3500

Updated the client to build a default artifact for gauge discharge curve. * Removed code for special gauge discharge artifact * Updated GaugeListGrid in info panel to create a the new project * Updated i18n
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 22 Sep 2014 17:08:48 +0200
parents f7f86f4e4c8d
children 5e38e2924c07
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeListGrid.java	Mon Sep 22 17:05:37 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeListGrid.java	Mon Sep 22 17:08:48 2014 +0200
@@ -12,16 +12,32 @@
 import java.util.List;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.grid.ListGridField;
 import com.smartgwt.client.widgets.grid.ListGridRecord;
 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
 
+import org.dive4elements.river.client.client.Config;
 import org.dive4elements.river.client.client.FLYS;
+import org.dive4elements.river.client.client.services.AdvanceService;
+import org.dive4elements.river.client.client.services.AdvanceServiceAsync;
+import org.dive4elements.river.client.client.services.ArtifactService;
+import org.dive4elements.river.client.client.services.ArtifactServiceAsync;
+import org.dive4elements.river.client.client.services.CreateCollectionService;
+import org.dive4elements.river.client.client.services.CreateCollectionServiceAsync;
+import org.dive4elements.river.client.client.services.StepForwardService;
+import org.dive4elements.river.client.client.services.StepForwardServiceAsync;
+import org.dive4elements.river.client.client.ui.CollectionView;
+import org.dive4elements.river.client.shared.model.Artifact;
+import org.dive4elements.river.client.shared.model.Collection;
 import org.dive4elements.river.client.shared.model.Data;
 import org.dive4elements.river.client.shared.model.DataItem;
 import org.dive4elements.river.client.shared.model.DataList;
+import org.dive4elements.river.client.shared.model.DefaultData;
+import org.dive4elements.river.client.shared.model.DefaultDataItem;
 import org.dive4elements.river.client.shared.model.GaugeInfo;
 import org.dive4elements.river.client.shared.model.RiverInfo;
 
@@ -33,6 +49,22 @@
 
     private static final int ABFLUSSTAFEL_COLUMN = 6;
 
+    /** The ArtifactService used to communicate with the Artifact server. */
+    protected ArtifactServiceAsync artifactService =
+        GWT.create(ArtifactService.class);
+
+    /** The StepForwardService used to put data into an existing artifact. */
+    protected StepForwardServiceAsync forwardService =
+        GWT.create(StepForwardService.class);
+
+    /** The ArtifactService used to communicate with the Artifact server. */
+    protected CreateCollectionServiceAsync createCollectionService =
+        GWT.create(CreateCollectionService.class);
+
+    /** The StepForwardService used to put data into an existing artifact. */
+    protected AdvanceServiceAsync advanceService =
+        GWT.create(AdvanceService.class);
+
     public GaugeListGrid(FLYS flys) {
         super(flys);
         //TODO i18n!!!
@@ -312,9 +344,110 @@
      */
     @Override
     public void onRecordClick(RecordClickEvent event) {
-        GaugeRecord gauge = (GaugeRecord)event.getRecord();
-        flys.newGaugeDischargeCurve(gauge.getRiverName(),
-                gauge.getOfficialNumber());
+        final GaugeRecord gauge = (GaugeRecord)event.getRecord();
+        Config config       = Config.getInstance();
+        final String locale = config.getLocale();
+        createCollectionService.create(
+                locale,
+                flys.getCurrentUser().identifier(),
+                new AsyncCallback<Collection>() {
+                    @Override
+                    public void onFailure(Throwable caught) {
+                        GWT.log("Could not create the new collection.");
+                        SC.warn(FLYS.getExceptionString(MSG, caught));
+                    }
+
+                    @Override
+                    public void onSuccess(Collection collection) {
+                        GWT.log("Successfully created a new collection.");
+                        createArtifact(collection, locale, gauge);
+                    }
+                }
+            );
+    }
+
+    private void createArtifact(
+        final Collection collection,
+        final String locale,
+        final GaugeRecord gauge
+    ) {
+        artifactService.create(
+           locale, "gaugedischargecurve", null,
+            new AsyncCallback<Artifact>() {
+                @Override
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not create the new artifact.");
+                    SC.warn(FLYS.getExceptionString(MSG, caught));
+                }
+
+                @Override
+                public void onSuccess(Artifact artifact) {
+                    GWT.log("Successfully created a new artifact.");
+
+                    DataItem riverItem = new DefaultDataItem(
+                        "river",
+                        "river",
+                        gauge.getRiverName());
+                    Data river = new DefaultData(
+                        "river",
+                        null,
+                        null,
+                        new DataItem[]{riverItem});
+
+                    DataItem refItem = new DefaultDataItem(
+                        "reference_gauge",
+                        "reference_gauge",
+                        gauge.getOfficialNumber().toString());
+                    Data ref = new DefaultData(
+                        "reference_gauge",
+                        null,
+                        null,
+                        new DataItem[]{refItem});
+
+                    DataItem locItem = new DefaultDataItem(
+                        "ld_locations",
+                        "ld_locations",
+                        gauge.getStation().toString());
+                    Data loc = new DefaultData(
+                        "ld_locations",
+                        null,
+                        null,
+                        new DataItem[]{locItem});
+
+                    DataItem nameItem = new DefaultDataItem(
+                        "gauge_name",
+                        "gauge_name",
+                        gauge.getName());
+                    Data name = new DefaultData(
+                        "gauge_name",
+                        null,
+                        null,
+                        new DataItem[]{nameItem});
+
+                    Data[] data = new Data[]{river, ref, loc, name};
+                    forwardService.go(locale, artifact, data,
+                        new AsyncCallback<Artifact>() {
+                        @Override
+                        public void onFailure(Throwable caught) {
+                            GWT.log("Could not feed the artifact.");
+                            SC.warn(caught.getMessage());
+                        }
+
+                        @Override
+                        public void onSuccess(Artifact artifact) {
+                            GWT.log("Successfully feed the artifact.");
+                            CollectionView view = new CollectionView(
+                                flys,
+                                collection,
+                                artifact);
+                            flys.getWorkspace().addView(
+                                collection.identifier(),
+                                view);
+                            view.addArtifactToCollection(artifact);
+                        }
+                    });
+                }
+            });
     }
 
     @Override

http://dive4elements.wald.intevation.org