changeset 8314:5294660df81b

merged.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 24 Sep 2014 12:02:37 +0200
parents e3a63d9c5bb1 (diff) e3a8aa6eee32 (current diff)
children d4c501d2c098
files
diffstat 16 files changed, 220 insertions(+), 152 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/doc/conf/artifacts/sqrelation.xml	Tue Sep 23 16:45:47 2014 +0200
+++ b/artifacts/doc/conf/artifacts/sqrelation.xml	Wed Sep 24 12:02:37 2014 +0200
@@ -1,9 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <artifact name="staticsqrelation">
     <states>
+        <state id="state.sqrelation.init" description="state.sqrelation.init" state="org.dive4elements.river.artifacts.states.sq.SQInitState">
+            <data name="river" type="String"/>
+            <data name="station" type="Integer" />
+            <data name="station_name" type="String" />
+        </state>
+        <transition transition="org.dive4elements.river.artifacts.transitions.DefaultTransition">
+            <from state="state.sqrelation.init"/>
+            <to state="state.sqrelation.static"/>
+        </transition>
          <state id="state.sqrelation.static" description="state.sqrelation.static" state="org.dive4elements.river.artifacts.states.sq.SQStaticState">
-            <data name="river" type="String" />
-            <data name="station" type="String" />
             <outputmodes>
                 <outputmode name="sq_relation_a" description="output.sq_relation" type="chart">
                     <facets>
@@ -47,17 +54,6 @@
                         <facet name="sq_g_curve" description="A facet for sq curve"/>
                     </facets>
                 </outputmode>
-                <outputmode name="sq_overview" description="output.sq_overview" type="overview">
-                    <facets>
-                        <facet name="sq_chart_overview" description="A facet for sq chart overview"/>
-                    </facets>
-                </outputmode>
-                <outputmode name="sqrelation_export" description="output.sqrelation_export" mime-type="text/plain" type="export">
-                    <facets>
-                        <facet name="csv" description="facet.sqrelation_export.csv" />
-                        <facet name="pdf" description="facet.sqrelation_export.pdf" />
-                    </facets>
-                </outputmode>
             </outputmodes>
          </state>
     </states>
--- a/artifacts/doc/conf/conf.xml	Tue Sep 23 16:45:47 2014 +0200
+++ b/artifacts/doc/conf/conf.xml	Wed Sep 24 12:02:37 2014 +0200
@@ -12,6 +12,7 @@
     <!ENTITY modules SYSTEM "modules.xml">
     <!ENTITY porosity-artifact  SYSTEM "artifacts/porosity.xml">
     <!ENTITY gaugedischargecurve-artifact  SYSTEM "artifacts/gaugedischargecurve.xml">
+    <!ENTITY sqrelation-artifact SYSTEM "artifacts/sqrelation.xml">
     <!ENTITY sedimentload-artifact  SYSTEM "artifacts/sedimentload.xml">
     <!ENTITY sedimentload-ls-artifact  SYSTEM "artifacts/sedimentload-ls.xml">
 
@@ -140,7 +141,7 @@
                 artifact="org.dive4elements.river.artifacts.BedHeightsArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
             <artifact-factory name="staticsqrelation" description="Factory to create an artifact that generates sq relations from db."
                 ttl="3600000"
-                artifact="org.dive4elements.river.artifacts.SQRelationArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
+                artifact="org.dive4elements.river.artifacts.D4EArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
             <artifact-factory name="morph-width" description="Factory to create an artifact used in minfo datacage."
                 ttl="3600000"
                 artifact="org.dive4elements.river.artifacts.StaticMorphWidthArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
@@ -291,7 +292,7 @@
         <artifact name="fixanalysis" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/fixanalysis.xml" />
         <artifact name="gaugedischarge" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/gaugedischarge.xml" />
         <artifact name="qsector" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/qsector.xml" />
-        <artifact name="staticsqrelation" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/sqrelation.xml" />
+        &sqrelation-artifact;
         &porosity-artifact;
         &gaugedischargecurve-artifact;
         &sedimentload-artifact;
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/GaugeDischargeInitState.java	Tue Sep 23 16:45:47 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/GaugeDischargeInitState.java	Wed Sep 24 12:02:37 2014 +0200
@@ -7,6 +7,6 @@
 
     @Override
     protected String getUIProvider() {
-        return "gauge_discharge_curve";
+        return "static_data";
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQInitState.java	Wed Sep 24 12:02:37 2014 +0200
@@ -0,0 +1,14 @@
+package org.dive4elements.river.artifacts.states.sq;
+
+import org.dive4elements.river.artifacts.states.DefaultState;
+
+
+public class SQInitState
+extends DefaultState
+{
+
+    @Override
+    protected String getUIProvider() {
+        return "static_data";
+    }
+}
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQStaticState.java	Tue Sep 23 16:45:47 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQStaticState.java	Wed Sep 24 12:02:37 2014 +0200
@@ -15,9 +15,12 @@
 import org.apache.log4j.Logger;
 
 import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.CallMeta;
 import org.dive4elements.river.artifacts.D4EArtifact;
 import org.dive4elements.river.artifacts.access.StaticSQRelationAccess;
+import org.dive4elements.river.artifacts.model.DataFacet;
+import org.dive4elements.river.artifacts.model.FacetTypes;
 import org.dive4elements.river.artifacts.model.sq.StaticSQContainer;
 import org.dive4elements.river.artifacts.model.sq.StaticSQFactory;
 import org.dive4elements.river.artifacts.model.sq.StaticSQRelation;
@@ -27,6 +30,7 @@
 
 public class SQStaticState
 extends StaticState
+implements FacetTypes
 {
 
     private static final Logger log =
@@ -44,6 +48,61 @@
     }
 
     @Override
+    public Object computeAdvance(
+        D4EArtifact artifact,
+        String hash,
+        CallContext context,
+        List<Facet> facets,
+        Object old) {
+        StaticSQContainer sqRelations;
+        StaticSQRelationAccess access = new StaticSQRelationAccess(artifact);
+        String river = access.getRiverName();
+        String measurementStation = access.getMeasurementStation();
+
+        int ms = -1;
+        try {
+            ms = Integer.parseInt(measurementStation);
+        }
+        catch (NumberFormatException nfe) {
+            log.error("Unparseable measurement station: " + measurementStation);
+            return null;
+        }
+        log.debug("Parsed measurement station: " + ms);
+
+        sqRelations = StaticSQFactory.getSQRelations(river, ms);
+        DateFormat df = new SimpleDateFormat("yyyy");
+
+        for (StaticSQRelation.Parameter p: StaticSQRelation.Parameter.values()) {
+            log.debug("parameter: " + p.toString());
+            List<StaticSQRelation> relations =
+                sqRelations.getRelationsByParameter(p);
+
+            if (!relations.isEmpty()) {
+                int count = 0;
+
+                for (StaticSQRelation relation : relations) {
+                    log.debug("add facet for " + p.toString().toLowerCase());
+                    String name = "sq_" + p.toString().toLowerCase() + "_curve";
+                    String desc =
+                        Resources.getMsg(context.getMeta(),
+                            FACET_DESCRIPTION,
+                            FACET_DESCRIPTION,
+                            new Object[] {
+                                df.format(relation.getStartTime()),
+                                df.format(relation.getStopTime())});
+                    facets.add(new StaticSQRelationFacet(
+                        count,
+                        name,
+                        desc,
+                        relation));
+                    count++;
+                }
+            }
+        }
+        return null;
+    }
+
+    @Override
     public Object computeInit(
         D4EArtifact artifact,
         String       hash,
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYS.java	Tue Sep 23 16:45:47 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYS.java	Wed Sep 24 12:02:37 2014 +0200
@@ -496,60 +496,6 @@
     }
 
 
-    public void newSQRelation(String river, int measurementStation) {
-        Config config = Config.getInstance();
-
-        final String locale = config.getLocale();
-        final String riv = river;
-        final int mStation = measurementStation;
-        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<Collection>() {
-                @Override
-                public void onFailure(Throwable caught) {
-                    GWT.log("Could not create new collection.");
-                    SC.warn(getExceptionString(MSG, caught));
-                }
-
-                @Override
-                public void onSuccess(Collection collection) {
-                    GWT.log("Successfully created a new collection.");
-                    final Collection col = collection;
-                    artifactService.createSQRelationArtifact(
-                        col, locale, riv, mStation,
-                        new AsyncCallback<Artifact>() {
-                            @Override
-                            public void onFailure(Throwable caught) {
-                                GWT.log("Could not create the new artifact.");
-                                SC.warn(getExceptionString(MSG, caught));
-                            }
-
-                            @Override
-                            public void onSuccess(Artifact artifact) {
-                                GWT.log("Successfully created a new artifact.");
-                                CollectionView view = new CollectionView(flys,
-                                    col, artifact);
-                                workspace.addView(col.identifier(), view);
-
-                                view.addCollectionChangeHandler(getProjectList());
-                                view.addCloseClickHandler(
-                                    new CloseCollectionViewHandler(
-                                        FLYS.this, col.identifier()));
-                                projectList.updateUserCollections();
-                            }
-                    });
-                }
-            });
-    }
-
     @Override
     public void onCollectionChange(CollectionChangeEvent event) {
         Collection oldC = event.getOldValue();
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java	Tue Sep 23 16:45:47 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java	Wed Sep 24 12:02:37 2014 +0200
@@ -1403,5 +1403,9 @@
     String gauge_name();
 
     String reference_gauge();
+
+    String station();
+
+    String station_name();
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties	Tue Sep 23 16:45:47 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties	Wed Sep 24 12:02:37 2014 +0200
@@ -734,4 +734,6 @@
 river=Fluss
 ld_locations=Ort
 gauge_name=Pegel
-reference_gauge=Pegelnummer
\ No newline at end of file
+reference_gauge=Pegelnummer
+station=Messstellennummer
+station_name=Messstelle
\ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties	Tue Sep 23 16:45:47 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties	Wed Sep 24 12:02:37 2014 +0200
@@ -675,4 +675,6 @@
 river=River
 ld_locations=Location
 gauge_name=Gauge
-reference_gauge=Gaugenumber
\ No newline at end of file
+reference_gauge=Gaugenumber
+station=Measurementstationnumber
+station_name=Measurementstation
\ No newline at end of file
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/services/ArtifactService.java	Tue Sep 23 16:45:47 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/services/ArtifactService.java	Wed Sep 24 12:02:37 2014 +0200
@@ -40,19 +40,5 @@
         String         factory,
         Recommendation recommendation
     ) throws ServerException;
-
-    /**
-     * Create a new SQRelationArtifact.
-     *
-     * @param collection the collection to add the artifact to.
-     * @param river      the river.
-     * @param measurementStation the measurement station id.
-     */
-    public Artifact createSQRelationArtifact(
-            Collection collection,
-            String locale,
-            String river,
-            int measurementStation
-    ) throws ServerException;
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/services/ArtifactServiceAsync.java	Tue Sep 23 16:45:47 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/services/ArtifactServiceAsync.java	Wed Sep 24 12:02:37 2014 +0200
@@ -28,13 +28,5 @@
         String         factory,
         Recommendation recommendation,
         AsyncCallback<Artifact> callback);
-
-    public void createSQRelationArtifact(
-        Collection collection,
-        String locale,
-        String river,
-        int measurementStation,
-        AsyncCallback<Artifact> callback
-    );
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/CollectionView.java	Tue Sep 23 16:45:47 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/CollectionView.java	Wed Sep 24 12:02:37 2014 +0200
@@ -635,7 +635,7 @@
                     @Override
                     public void onSuccess(Collection newCollection) {
                         GWT.log("Successfully added artifacts.");
-                        setCollection(newCollection, true);
+                        setCollection(newCollection);
                     }
                 }
             );
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java	Tue Sep 23 16:45:47 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java	Wed Sep 24 12:02:37 2014 +0200
@@ -173,7 +173,7 @@
         else if (uiProvider.equals("minfo.sedimentload_unit_select")) {
             return new RadioPanel();
         }
-        else if (uiProvider.equals("gauge_discharge_curve")) {
+        else if (uiProvider.equals("static_data")) {
             return new StaticDataPanel();
         }
         else if (uiProvider.equals("minfo.sedimentload_distance_select")) {
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/MeasurementStationListGrid.java	Tue Sep 23 16:45:47 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/MeasurementStationListGrid.java	Wed Sep 24 12:02:37 2014 +0200
@@ -9,14 +9,30 @@
 package org.dive4elements.river.client.client.ui.stationinfo;
 
 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.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.DefaultData;
+import org.dive4elements.river.client.shared.model.DefaultDataItem;
 import org.dive4elements.river.client.shared.model.MeasurementStation;
 import org.dive4elements.river.client.shared.model.RiverInfo;
 
@@ -30,6 +46,18 @@
 extends InfoListGrid
 implements RecordClickHandler {
 
+    /** 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);
+
     public MeasurementStationListGrid(FLYS flys) {
         super(flys);
         ListGridField nfield = new ListGridField("name", "Messtelle");
@@ -109,9 +137,101 @@
 
     @Override
     public void onRecordClick(RecordClickEvent event) {
-        MeasurementStationRecord station =
+        final MeasurementStationRecord station =
             (MeasurementStationRecord)event.getRecord();
-        flys.newSQRelation(station.getRiverName(), station.getID());
+        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, station);
+                    }
+                }
+            );
+    }
+
+    private void createArtifact(
+        final Collection collection,
+        final String locale,
+        final MeasurementStationRecord station
+    ) {
+        artifactService.create(
+           locale, "staticsqrelation", 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",
+                        station.getRiverName());
+                    Data river = new DefaultData(
+                        "river",
+                        null,
+                        null,
+                        new DataItem[]{riverItem});
+
+                    DataItem refItem = new DefaultDataItem(
+                        "station",
+                        "station",
+                        station.getID().toString());
+                    Data ref = new DefaultData(
+                        "station",
+                        null,
+                        null,
+                        new DataItem[]{refItem});
+
+                    DataItem nameItem = new DefaultDataItem(
+                        "station_name",
+                        "station_name",
+                        station.getID().toString());
+                    Data name = new DefaultData(
+                        "station_name",
+                        null,
+                        null,
+                        new DataItem[]{nameItem});
+
+                    Data[] data = new Data[]{river, ref, 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
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/ArtifactHelper.java	Tue Sep 23 16:45:47 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/ArtifactHelper.java	Wed Sep 24 12:02:37 2014 +0200
@@ -192,35 +192,5 @@
 
         return cf;
     }
-
-
-    public static Artifact createSQRelationArtifact(
-        String serverUrl,
-        String locale,
-        String river,
-        int measurementStation)
-    throws ServerException
-    {
-        Document create = ClientProtocolUtils.newCreateDocument(
-                SQ_RELATION_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 estation = ec.create("measurement_station");
-        ec.addAttr(estation, "number", String.valueOf(measurementStation));
-
-        root.appendChild(eriver);
-        root.appendChild(estation);
-
-        return sendCreate(serverUrl, locale, create);
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/ArtifactServiceImpl.java	Tue Sep 23 16:45:47 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/ArtifactServiceImpl.java	Wed Sep 24 12:02:37 2014 +0200
@@ -57,29 +57,5 @@
 
         return ArtifactHelper.createArtifact(url, locale, factory, recom);
     }
-
-    @Override
-    public Artifact createSQRelationArtifact(
-        Collection collection,
-        String locale,
-        String river,
-        int measurementStation)
-    throws ServerException
-    {
-        log.info("ArtifactServiceImpl.createSQRelationArtifact");
-        String url  = getServletContext().getInitParameter("server-url");
-
-        Artifact artifact = ArtifactHelper.createSQRelationArtifact(url,
-                locale, river, measurementStation);
-        if (artifact == null) {
-            return null;
-        }
-        log.info("SQRelationArtifact created successfully");
-
-        CollectionHelper.addArtifact(collection, artifact, url, locale);
-
-        return artifact;
-    }
-
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org