changeset 3461:1481322efc02

FixA: Removed instanceof hack to fetch the WQKms of the fix realizations. flys-artifacts/trunk@5129 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 25 Jul 2012 15:07:14 +0000
parents d625f4d06b6a
children 13855a555d3b
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WaterlevelFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWaterlevelFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixRealizingCompute.java
diffstat 4 files changed, 82 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jul 25 12:58:52 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jul 25 15:07:14 2012 +0000
@@ -1,3 +1,14 @@
+2012-07-25	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixWaterlevelFacet.java:
+	  Removed instanceof hack to fetch the WQKms of the fix realizations.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixWaterlevelFacet.java:
+	  New. Subclass of WaterlevelFacet. Used to fetch the WQKms the fix realization way.
+
+	* src/main/java/de/intevation/flys/artifacts/states/fixation/FixRealizingCompute.java:
+	  Create the subclassed waterlevel facets.
+
 2012-07-25  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/fixation/FixRealizingCompute.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WaterlevelFacet.java	Wed Jul 25 12:58:52 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WaterlevelFacet.java	Wed Jul 25 15:07:14 2012 +0000
@@ -5,16 +5,12 @@
 import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.CallContext;
 
-import de.intevation.flys.artifacts.FixationArtifact;
 import de.intevation.flys.artifacts.FLYSArtifact;
 
 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
 
-import de.intevation.flys.artifacts.model.fixings.FixRealizingResult;
-
 import org.apache.log4j.Logger;
 
-
 /**
  * Facet of a Waterlevel (WQKms).
  */
@@ -33,7 +29,6 @@
         ComputeType type,
         String      stateID,
         String      hash
-
     ) {
         super(index, name, description, type, hash, stateID);
     }
@@ -41,6 +36,9 @@
     public WaterlevelFacet() {
     }
 
+    protected WQKms [] getWQKms(CalculationResult res) {
+        return (WQKms [])res.getData();
+    }
 
     /**
      * Get waterlevel data.
@@ -68,18 +66,9 @@
             return null;
         }
 
-        if (winfo instanceof FixationArtifact) {
-            FixRealizingResult fr = (FixRealizingResult) res.getData();
-            if (fr == null || fr.getWQKms() == null) {
-                logger.error("WaterlevelFacet.getData: " +
-                    " corrupted FixationArtifact result.");
-            }
-            return fr.getWQKms()[index];
-        }
+        WQKms [] wqkms = getWQKms(res);
 
-        WQKms [] wqkms = (WQKms []) res.getData();
-
-        return wqkms[index];
+        return wqkms != null ? wqkms[index] : null;
     }
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWaterlevelFacet.java	Wed Jul 25 15:07:14 2012 +0000
@@ -0,0 +1,49 @@
+package de.intevation.flys.artifacts.model.fixings;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.artifacts.model.CalculationResult;
+import de.intevation.flys.artifacts.model.WQKms;
+import de.intevation.flys.artifacts.model.WaterlevelFacet;
+
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+public class FixWaterlevelFacet
+extends      WaterlevelFacet
+{
+    public FixWaterlevelFacet() {
+    }
+
+    public FixWaterlevelFacet(int index, String name, String description) {
+        super(index, name, description, ComputeType.ADVANCE, null, null);
+    }
+
+    public FixWaterlevelFacet(
+        int         index,
+        String      name,
+        String      description,
+        ComputeType type,
+        String      stateID,
+        String      hash
+    ) {
+        super(index, name, description, type, hash, stateID);
+    }
+
+    @Override
+    protected WQKms [] getWQKms(CalculationResult res) {
+        FixRealizingResult fr = (FixRealizingResult)res.getData();
+        return fr != null ? fr.getWQKms() : null;
+    }
+
+    /** Copy deeply. */
+    @Override
+    public Facet deepCopy() {
+        FixWaterlevelFacet copy = new FixWaterlevelFacet();
+        copy.set(this);
+        copy.type    = type;
+        copy.hash    = hash;
+        copy.stateId = stateId;
+        return copy;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixRealizingCompute.java	Wed Jul 25 12:58:52 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/fixation/FixRealizingCompute.java	Wed Jul 25 15:07:14 2012 +0000
@@ -1,24 +1,29 @@
 package de.intevation.flys.artifacts.states.fixation;
 
-import java.util.List;
-
-import org.apache.log4j.Logger;
+import de.intevation.artifactdatabase.state.Facet;
 
-import de.intevation.artifactdatabase.state.Facet;
 import de.intevation.artifacts.CallContext;
+
 import de.intevation.flys.artifacts.FLYSArtifact;
+
 import de.intevation.flys.artifacts.access.FixRealizingAccess;
+
 import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.ReportFacet;
 import de.intevation.flys.artifacts.model.WQCKms;
 import de.intevation.flys.artifacts.model.WQKms;
-import de.intevation.flys.artifacts.model.WaterlevelFacet;
+
 import de.intevation.flys.artifacts.model.fixings.FixRealizingCalculation;
 import de.intevation.flys.artifacts.model.fixings.FixRealizingResult;
+import de.intevation.flys.artifacts.model.fixings.FixWaterlevelFacet;
+
 import de.intevation.flys.artifacts.states.DefaultState;
 
+import java.util.List;
+
+import org.apache.log4j.Logger;
 
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
@@ -61,6 +66,10 @@
             return res;
         }
 
+        if (res.getReport().hasProblems()) {
+            facets.add(new ReportFacet());
+        }
+
         FixRealizingResult fixRes = (FixRealizingResult) res.getData();
         WQKms [] wqkms = fixRes != null ? fixRes.getWQKms() : new WQKms[0];
 
@@ -77,10 +86,10 @@
                 nameQ = "Q(" + nameW + ")";
             }
 
-            Facet w = new WaterlevelFacet(
+            Facet w = new FixWaterlevelFacet(
                 i, LONGITUDINAL_W, nameW);
 
-            Facet q = new WaterlevelFacet(
+            Facet q = new FixWaterlevelFacet(
                 i, LONGITUDINAL_Q, nameQ);
 
             facets.add(w);
@@ -91,7 +100,7 @@
                     "benutzerdefiniert",
                     "benutzerdefiniert [korrigiert]");
 
-                Facet c = new WaterlevelFacet(
+                Facet c = new FixWaterlevelFacet(
                     i, DISCHARGE_LONGITUDINAL_C, nameC);
 
                 facets.add(c);
@@ -103,10 +112,6 @@
             facets.add(new DataFacet(WST, "WST data"));
         }
 
-        if (res.getReport().hasProblems()) {
-            facets.add(new ReportFacet());
-        }
-
         return res;
     }
 }

http://dive4elements.wald.intevation.org