changeset 6046:4493ef20d357

merged
author Tom Gottfried <tom@intevation.de>
date Thu, 16 May 2013 18:04:35 +0200
parents 2d16f4a0bdcc (current diff) 477d2d18452e (diff)
children 1bb4b51ff1e6
files
diffstat 12 files changed, 169 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/doc/conf/artifacts/gaugedischargecurve.xml	Thu May 16 18:03:39 2013 +0200
+++ b/artifacts/doc/conf/artifacts/gaugedischargecurve.xml	Thu May 16 18:04:35 2013 +0200
@@ -9,6 +9,8 @@
                 <outputmode name="discharge_curve" description="output.discharge_curve" type="chart">
                     <facets>
                         <facet name="gauge_discharge_curve"/>
+                        <facet name="mainvalues.q" description="facet.mainvalues.q"/>
+                        <facet name="mainvalues.w" description="facet.mainvalues.w"/>
                     </facets>
                 </outputmode>
                 <outputmode name="computed_dischargecurve_at_export" description="output.computed_dischargecurve_at_export" mime-type="text/plain" type="export">
--- a/artifacts/doc/conf/meta-data.xml	Thu May 16 18:03:39 2013 +0200
+++ b/artifacts/doc/conf/meta-data.xml	Thu May 16 18:04:35 2013 +0200
@@ -566,13 +566,13 @@
               <dc:for-each>
                 <dc:context>
                   <dc:statement>
-                    SELECT min(station) AS from,
-                           max(station) AS to
+                    SELECT min(station) AS from_station,
+                           max(station) AS to_station
                     FROM morphologic_width_values
                     WHERE morphologic_width_id = ${width_id}
                   </dc:statement>
                   <dc:for-each>
-                    <morphologic-width name="{$from} - {$to}"
+                    <morphologic-width name="{$from_station} - {$to_station}"
                                        ids="{$width_id}"
                                        factory="morph-width"/>
                   </dc:for-each>
@@ -710,6 +710,9 @@
                   <dc:call-macro name="cross_sections"/>
                   <dc:call-macro name="hyks"/>
                 </dc:when>
+                <dc:when test="$out = 'discharge_curve'">
+                  <dc:call-macro name="mainvalues"/>
+                </dc:when>
                 <dc:when test="$out = 'computed_discharge_curve'">
                   <dc:call-macro name="mainvalues"/>
                   <dc:call-macro name="basedata_2_fixations_wqkms"/>
@@ -787,6 +790,9 @@
                 <dc:when test="$out = 'discharge_longitudinal_section'">
                   <dc:call-macro name="longitudinal-section-prototype"/>
                 </dc:when>
+                <dc:when test="$out = 'discharge_curve'">
+                  <dc:call-macro name="mainvalues"/>
+                </dc:when>
                 <dc:when test="$out = 'duration_curve'">
                   <dc:call-macro name="mainvalues"/>
                   <dc:call-macro name="basedata_2_fixations_relative_point"/>
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/GaugeDischargeCurveArtifact.java	Thu May 16 18:03:39 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/GaugeDischargeCurveArtifact.java	Thu May 16 18:04:35 2013 +0200
@@ -42,7 +42,7 @@
 public class GaugeDischargeCurveArtifact
 extends      AbstractStaticStateArtifact
 {
-
+    /** Private logger. */
     private static final Logger logger =
         Logger.getLogger(GaugeDischargeCurveArtifact.class);
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java	Thu May 16 18:03:39 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/MainValuesArtifact.java	Thu May 16 18:04:35 2013 +0200
@@ -25,6 +25,9 @@
 import org.dive4elements.artifacts.ArtifactFactory;
 import org.dive4elements.artifacts.CallMeta;
 
+import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
+import org.dive4elements.artifacts.common.utils.XMLUtils;
+
 import org.dive4elements.river.model.Gauge;
 import org.dive4elements.river.model.MainValue;
 import org.dive4elements.river.model.River;
@@ -106,6 +109,8 @@
         logger.debug("MainValuesArtifact.setup");
         state = new StaticState(STATIC_STATE_NAME);
 
+        initFromGaugeDoc(data, callMeta);
+
         List<Facet> fs = new ArrayList<Facet>();
         addFacets(state.getID(), fs);
         spawnState();
@@ -176,6 +181,41 @@
         }
     }
 
+    /**
+     * The MainValueArtifact can be set up with a document giving the
+     * river and gauge.  This happens in context of GaugeDischargeArtifact.
+     * In that case, initalize() is not called.
+     */
+    private void initFromGaugeDoc(Document data, CallMeta callMeta) {
+        String gaugeref = XMLUtils.xpathString(
+                data, GaugeDischargeCurveArtifact.XPATH_GAUGE,
+                ArtifactNamespaceContext.INSTANCE);
+        String rivername = XMLUtils.xpathString(
+                data, GaugeDischargeCurveArtifact.XPATH_RIVER,
+                ArtifactNamespaceContext.INSTANCE);
+
+        if (rivername == null || gaugeref == null || rivername.equals("")
+            || gaugeref.equals("")) {
+            logger.debug("Not setting MainValuesArtifact up from gauge doc.");
+            return;
+        }
+
+        addData("river", new DefaultStateData("river",
+                    Resources.getMsg(callMeta,
+                        "facet.gauge_discharge_curve.river",
+                        "Name of the river"),
+                    "String", rivername));
+
+        try {
+            Long officialNumber = Long.valueOf(gaugeref);
+            Gauge gauge = Gauge.getGaugeByOfficialNumber(officialNumber);
+            addData("ld_locations", new DefaultStateData("ld_locations", null, null,
+                    String.valueOf(gauge.getStation())));
+        } catch (NumberFormatException nfe) {
+            logger.debug("MainValuesArtifact could not parse gaugeref from doc.");
+        }
+    }
+
 
     /**
      * Create "the" state.
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYS.java	Thu May 16 18:03:39 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYS.java	Thu May 16 18:04:35 2013 +0200
@@ -468,6 +468,8 @@
         workspace.addChild(mainValueView);
     }
 
+
+    /** Open window with gauges discharge curve. */
     public void newGaugeDischargeCurve(String river, Long gaugeref) {
         Config config = Config.getInstance();
 
@@ -483,6 +485,7 @@
             return;
         }
 
+        // TODO 1081, this collection needs to be added a mainvalue artifact
         collectionService.create(locale, user.identifier(),
             new AsyncCallback<Collection>() {
                 @Override
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/services/ArtifactService.java	Thu May 16 18:03:39 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/services/ArtifactService.java	Thu May 16 18:04:35 2013 +0200
@@ -42,11 +42,11 @@
     ) throws ServerException;
 
     /**
-     * Create a new GaugeDischageCurveArtifact
+     * Create a new GaugeDischageCurveArtifact.
      *
-     * @param collection the collection to add the artifact to
-     * @param river      the river
-     * @param gaugeref   reference id of the gauge
+     * @param collection the collection to add the artifact to.
+     * @param river      the river.
+     * @param gaugeref   reference id of the gauge.
      */
     public Artifact createGaugeDischargeCurveArtifact(
             Collection collection,
@@ -56,11 +56,11 @@
     ) throws ServerException;
 
     /**
-     * Create a new SQRelationArtifact
+     * Create a new SQRelationArtifact.
      *
-     * @param collection the collection to add the artifact to
-     * @param river      the river
-     * @param measurementStation the measurement station id
+     * @param collection the collection to add the artifact to.
+     * @param river      the river.
+     * @param measurementStation the measurement station id.
      */
     public Artifact createSQRelationArtifact(
             Collection collection,
@@ -68,5 +68,19 @@
             String river,
             int measurementStation
     ) throws ServerException;
+
+    /**
+     * Create a new GaugeDischageCurveArtifact and also a Mainvalueartifact.
+     *
+     * @param collection the collection to add the artifacts to.
+     * @param river      the river.
+     * @param gaugeref   reference id of the gauge.
+     */
+    public Artifact createGaugeDischargeView(
+        Collection collection,
+        String locale,
+        String river,
+        Long   gaugeRef)
+    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	Thu May 16 18:03:39 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/services/ArtifactServiceAsync.java	Thu May 16 18:04:35 2013 +0200
@@ -44,5 +44,12 @@
         int measurementStation,
         AsyncCallback<Artifact> callback
     );
+
+    public void createGaugeDischargeView(
+        Collection collection,
+        String locale,
+        String river,
+        Long   gaugeRef,
+        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/DatacageWidget.java	Thu May 16 18:03:39 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DatacageWidget.java	Thu May 16 18:04:35 2013 +0200
@@ -191,6 +191,7 @@
         triggerTreeBuilding();
     }
 
+    /** Disable input, show spinning wheel of joy. */
     public void lockUI() {
         lockScreen = ScreenLock.lockUI(this, lockScreen);
     }
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeListGrid.java	Thu May 16 18:03:39 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeListGrid.java	Thu May 16 18:04:35 2013 +0200
@@ -307,6 +307,10 @@
         return new WidgetCanvas(new GaugeInfoPanel(item, flys));
     }
 
+    /**
+     * When clicked on the gauge discharge link, open new Gauge Discharge
+     * Curve view.
+     */
     @Override
     public void onRecordClick(RecordClickEvent event) {
         GaugeRecord gauge = (GaugeRecord)event.getRecord();
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/ArtifactHelper.java	Thu May 16 18:03:39 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/ArtifactHelper.java	Thu May 16 18:04:35 2013 +0200
@@ -36,6 +36,7 @@
  */
 public class ArtifactHelper {
 
+    /** Private logging instance. */
     private static final Logger logger = Logger.getLogger(ArtifactHelper.class);
 
 
@@ -43,10 +44,12 @@
      * creation.*/
     public static final String ERROR_CREATE_ARTIFACT = "error_create_artifact";
 
-    /**
-     * Name of the factory to generate a GaugeDischargeCurveArtifact
-     */
+    /** Name of the factory to generate a GaugeDischargeCurveArtifact. */
     private static final String GAUGE_DISCHARGE_CURVE_ARTIFACT = "gaugedischargecurve";
+
+    /** Name of the factory to generate a MainvaluesArtifact. */
+    private static final String MAINVALUE_ARTIFACT_FACTORY = "mainvalue";
+
     private static final String SQ_RELATION_ARTIFACT = "staticsqrelation";
 
     private ArtifactHelper() {
@@ -88,6 +91,39 @@
     }
 
     /**
+     * Creates a new MainvaluesArtifact.
+     *
+     * @param river the name of the river
+     */
+    public static Artifact createMainvalueArtifact(
+            String serverUrl,
+            String locale,
+            String river,
+            Long   gaugeRef)
+    throws ServerException
+    {
+        Document create = ClientProtocolUtils.newCreateDocument(
+                MAINVALUE_ARTIFACT_FACTORY);
+
+        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", gaugeRef.toString());
+
+        root.appendChild(eriver);
+        root.appendChild(egauge);
+
+        return sendCreate(serverUrl, locale, create);
+    }
+    /**
      * Creates a new GaugeDischargeCurverArtifact
      *
      * @param river the name of the river
@@ -123,7 +159,7 @@
     }
 
     /**
-     * Sends a create document to the artifact server
+     * Sends a create document to the artifact server.
      */
     private static Artifact sendCreate(
             String   serverUrl,
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/ArtifactServiceImpl.java	Thu May 16 18:03:39 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/ArtifactServiceImpl.java	Thu May 16 18:04:35 2013 +0200
@@ -58,6 +58,43 @@
         return ArtifactHelper.createArtifact(url, locale, factory, recom);
     }
 
+
+    /**
+     * Create a new GaugeDischageCurveArtifact and MainValueArtifact, stuff
+     * them into a collection.
+     *
+     * @param river    the river.
+     * @param gaugeref reference id of the gauge.
+     */
+    public Artifact createGaugeDischargeView(
+        Collection collection,
+        String locale,
+        String river,
+        Long   gaugeRef)
+    throws ServerException
+    {
+        logger.info("ArtifactServiceImpl.createGaugeDischargeCurveView");
+        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);
+        Artifact mainVArtifact = ArtifactHelper.createMainvalueArtifact(url,
+                locale, river, gaugeRef);
+        if (mainVArtifact == null) {
+            logger.info("Failed to create MainValueArtifact");
+            return null;
+        }
+        CollectionHelper.addArtifact(collection, mainVArtifact, url, locale);
+
+        return artifact;
+    }
+
     /**
      * Create a new GaugeDischageCurveArtifact
      *
@@ -71,7 +108,7 @@
             Long   gaugeref)
     throws ServerException
     {
-        logger.info("ArtifactServiceImpl.createGaugeDischargeCurverArtifact");
+        logger.info("ArtifactServiceImpl.createGaugeDischargeCurveArtifact");
         String url  = getServletContext().getInitParameter("server-url");
 
         Artifact artifact = ArtifactHelper.createGaugeDischargeCurveArtifact(url,
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/FacetFilter.java	Thu May 16 18:03:39 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/FacetFilter.java	Thu May 16 18:04:35 2013 +0200
@@ -40,6 +40,8 @@
         this.ids = ids;
     }
 
+    /** Return false if only a or b are null, true if both are null
+     * result of String.equals otherwise. */
     protected static boolean equals(String a, String b) {
         if (a == null && b == null) return true;
         if (a == null && b != null) return false;

http://dive4elements.wald.intevation.org