changeset 3230:b888c5eb65b3

Added new *Access objects for bed height calculation and flow velocity calculation; removed methods for specific data access from MINFOArtifact. flys-artifacts/trunk@4859 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 03 Jul 2012 12:13:36 +0000 (2012-07-03)
parents ad9640211db3
children f6b571220852
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/MINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/BedHeightAccess.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/FixationArtifactAccess.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/FlowVelocityAccess.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FlowVelocityCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MiddleBedHeightCalculation.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FlowVelocityState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MiddleBedHeight.java
diffstat 9 files changed, 230 insertions(+), 126 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jul 03 11:03:16 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jul 03 12:13:36 2012 +0000
@@ -1,3 +1,21 @@
+2012-07-03  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/access/BedHeightAccess.java,
+	  src/main/java/de/intevation/flys/artifacts/access/FlowVelocityAccess.java:
+	  New Access objects to access relevant information of Artifacts specific
+	  to bed heights and flow velocity calculations.
+
+	* src/main/java/de/intevation/flys/artifacts/model/FlowVelocityCalculation.java,
+	  src/main/java/de/intevation/flys/artifacts/model/MiddleBedHeightCalculation.java,
+	  src/main/java/de/intevation/flys/artifacts/access/FixationArtifactAccess.java,
+	  src/main/java/de/intevation/flys/artifacts/states/FlowVelocityState.java,
+	  src/main/java/de/intevation/flys/artifacts/states/MiddleBedHeight.java:
+	  Use *Access objects to get required information from Artifact.
+
+	* src/main/java/de/intevation/flys/artifacts/MINFOArtifact.java: Moved
+	  methods to access specific information for calculations to *Access
+	  objects.
+
 2012-07-03	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	Fix issue695 (labeling of waterlines).
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MINFOArtifact.java	Tue Jul 03 11:03:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MINFOArtifact.java	Tue Jul 03 12:13:36 2012 +0000
@@ -2,14 +2,6 @@
 
 import de.intevation.flys.artifacts.model.FacetTypes;
 
-import de.intevation.flys.artifacts.states.SoundingsSelect;
-
-import de.intevation.flys.utils.FLYSUtils;
-
-import gnu.trove.TIntArrayList;
-
-import org.apache.log4j.Logger;
-
 /**
  * The default MINFO artifact.
  *
@@ -19,15 +11,9 @@
 extends      FLYSArtifact
 implements   FacetTypes {
 
-    /** The logger for this class. */
-    private static Logger logger = Logger.getLogger(MINFOArtifact.class);
-
     /** The name of the artifact. */
     public static final String ARTIFACT_NAME = "minfo";
 
-    /** XPath */
-    public static final String XPATH_STATIC_UI ="/art:result/art:ui/art:static";
-
 
     /**
      * The default constructor.
@@ -44,86 +30,5 @@
     public String getName() {
         return ARTIFACT_NAME;
     }
-
-    public int[] getMainChannels() {
-        String data = getDataAsString("main.channel");
-
-        if (data == null) {
-            logger.warn("No 'main.channel' parameter specified!");
-            return null;
-        }
-
-        return FLYSUtils.intArrayFromString(data);
-    }
-
-
-    public int[] getTotalChannels() {
-        String data = getDataAsString("total.channel");
-
-        if (data == null) {
-            logger.warn("No 'total.channel' parameter specified!");
-            return null;
-        }
-
-        return FLYSUtils.intArrayFromString(data);
-    }
-
-
-    public int[] getBedHeightSingleIDs() {
-        String data = getDataAsString("soundings");
-
-        if (data == null) {
-            logger.warn("No 'soundings' parameter specified!");
-            return null;
-        }
-
-        String[] parts = data.split(";");
-
-        TIntArrayList ids = new TIntArrayList();
-
-        for (String part: parts) {
-            if (part.indexOf(SoundingsSelect.PREFIX_SINGLE) >= 0) {
-                String tmp = part.replace(SoundingsSelect.PREFIX_SINGLE, "");
-
-                try {
-                    ids.add(Integer.parseInt(tmp));
-                }
-                catch (NumberFormatException nfe) {
-                    logger.warn("Cannot parse int from string: '" + tmp + "'");
-                }
-            }
-        }
-
-        return ids.toNativeArray();
-    }
-
-
-    public int[] getBedHeightEpochIDs() {
-        String data = getDataAsString("soundings");
-
-        if (data == null) {
-            logger.warn("No 'soundings' parameter specified!");
-            return null;
-        }
-
-        String[] parts = data.split(";");
-
-        TIntArrayList ids = new TIntArrayList();
-
-        for (String part: parts) {
-            if (part.indexOf(SoundingsSelect.PREFIX_EPOCH) >= 0) {
-                String tmp = part.replace(SoundingsSelect.PREFIX_EPOCH, "");
-
-                try {
-                    ids.add(Integer.parseInt(tmp));
-                }
-                catch (NumberFormatException nfe) {
-                    logger.warn("Cannot parse int from string: '" + tmp + "'");
-                }
-            }
-        }
-
-        return ids.toNativeArray();
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/BedHeightAccess.java	Tue Jul 03 12:13:36 2012 +0000
@@ -0,0 +1,110 @@
+package de.intevation.flys.artifacts.access;
+
+import gnu.trove.TIntArrayList;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.states.SoundingsSelect;
+
+
+public class BedHeightAccess extends Access {
+
+	private static final Logger logger = Logger.getLogger(BedHeightAccess.class);
+	
+	
+	private int[] singleIDs;
+	private int[] epochIDs;
+	
+	private Double lowerKM;
+	private Double upperKM;
+	
+	
+	public BedHeightAccess(FLYSArtifact artifact) {
+		super(artifact);
+	}
+	
+	
+	public Double getLowerKM() {
+    	if (lowerKM == null) {
+    		lowerKM = getDouble("ld_from");
+    	}
+    	
+    	return lowerKM;
+    }
+    
+    
+    public Double getUpperKM() {
+    	if (upperKM == null) {
+    		upperKM = getDouble("ld_to");
+    	}
+    	
+    	return upperKM;
+    }
+	
+    
+    public int[] getBedHeightSingleIDs() {
+    	if (singleIDs == null) {
+	        String data = getString("soundings");
+	
+	        if (data == null) {
+	            logger.warn("No 'soundings' parameter specified!");
+	            return null;
+	        }
+	
+	        String[] parts = data.split(";");
+	
+	        TIntArrayList ids = new TIntArrayList();
+	
+	        for (String part: parts) {
+	            if (part.indexOf(SoundingsSelect.PREFIX_SINGLE) >= 0) {
+	                String tmp = part.replace(SoundingsSelect.PREFIX_SINGLE, "");
+	
+	                try {
+	                    ids.add(Integer.parseInt(tmp));
+	                }
+	                catch (NumberFormatException nfe) {
+	                    logger.warn("Cannot parse int from string: '" + tmp + "'");
+	                }
+	            }
+	        }
+	        
+	        singleIDs = ids.toNativeArray();
+    	}
+
+    	return singleIDs;
+    }
+
+
+    public int[] getBedHeightEpochIDs() {
+    	if (epochIDs == null) {
+	        String data = getString("soundings");
+	
+	        if (data == null) {
+	            logger.warn("No 'soundings' parameter specified!");
+	            return null;
+	        }
+	
+	        String[] parts = data.split(";");
+	
+	        TIntArrayList ids = new TIntArrayList();
+	
+	        for (String part: parts) {
+	            if (part.indexOf(SoundingsSelect.PREFIX_EPOCH) >= 0) {
+	                String tmp = part.replace(SoundingsSelect.PREFIX_EPOCH, "");
+	
+	                try {
+	                    ids.add(Integer.parseInt(tmp));
+	                }
+	                catch (NumberFormatException nfe) {
+	                    logger.warn("Cannot parse int from string: '" + tmp + "'");
+	                }
+	            }
+	        }
+	
+	        epochIDs = ids.toNativeArray();
+    	}
+    	
+    	return epochIDs;
+    }
+}
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/FixationArtifactAccess.java	Tue Jul 03 11:03:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/FixationArtifactAccess.java	Tue Jul 03 12:13:36 2012 +0000
@@ -11,6 +11,7 @@
 
 import org.apache.log4j.Logger;
 
+
 public class FixationArtifactAccess
 extends      Access
 {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/FlowVelocityAccess.java	Tue Jul 03 12:13:36 2012 +0000
@@ -0,0 +1,54 @@
+package de.intevation.flys.artifacts.access;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+
+public class FlowVelocityAccess extends Access {
+	
+	private int[] mainChannels;
+	private int[] totalChannels;
+	
+	private Double lowerKM;
+	private Double upperKM;
+	
+	
+	public FlowVelocityAccess(FLYSArtifact artifact) {
+		super(artifact);
+	}
+	
+	
+	public int[] getMainChannels() {
+		if (mainChannels == null) {
+			mainChannels = getIntArray("main.channel");
+		}
+		
+		return mainChannels;
+    }
+
+
+    public int[] getTotalChannels() {
+    	if (totalChannels == null) {
+    		totalChannels = getIntArray("total.channel");
+    	}
+    	
+    	return totalChannels;
+    }
+    
+    
+    public Double getLowerKM() {
+    	if (lowerKM == null) {
+    		lowerKM = getDouble("ld_from");
+    	}
+    	
+    	return lowerKM;
+    }
+    
+    
+    public Double getUpperKM() {
+    	if (upperKM == null) {
+    		upperKM = getDouble("ld_to");
+    	}
+    	
+    	return upperKM;
+    }
+}
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FlowVelocityCalculation.java	Tue Jul 03 11:03:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FlowVelocityCalculation.java	Tue Jul 03 12:13:36 2012 +0000
@@ -5,12 +5,13 @@
 
 import org.apache.log4j.Logger;
 
+import de.intevation.artifacts.Artifact;
 import de.intevation.flys.model.DischargeZone;
 import de.intevation.flys.model.FlowVelocityModel;
 import de.intevation.flys.model.FlowVelocityModelValue;
 import de.intevation.flys.model.River;
 
-import de.intevation.flys.artifacts.MINFOArtifact;
+import de.intevation.flys.artifacts.access.FlowVelocityAccess;
 import de.intevation.flys.artifacts.model.FlowVelocityData;
 import de.intevation.flys.utils.FLYSUtils;
 
@@ -19,16 +20,18 @@
 
     private static final Logger logger =
         Logger.getLogger(FlowVelocityCalculation.class);
-
+    
+    
 
-    public CalculationResult calculate(MINFOArtifact artifact) {
+    public CalculationResult calculate(FlowVelocityAccess access) {
         logger.info("FlowVelocityCalculation.calculate");
-
-        int[] mainIds  = artifact.getMainChannels();
-        int[] totalIds = artifact.getTotalChannels();
+        
+        int[] mainIds  = access.getMainChannels();
+        int[] totalIds = access.getTotalChannels();
 
         if (logger.isDebugEnabled()) {
-            logger.debug("Artifact '" + artifact.identifier() + "' contains:");
+        	Artifact a = access.getArtifact();
+            logger.debug("Artifact '" + a.identifier() + "' contains:");
             if (mainIds != null) {
                 logger.debug("   " + mainIds.length + " main channel ids");
             }
@@ -39,9 +42,9 @@
         }
 
         List<DischargeZone>     zones  = getDischargeZones(mainIds, totalIds);
-        List<FlowVelocityModel> models = getFlowVelocityModels(artifact, zones);
+        List<FlowVelocityModel> models = getFlowVelocityModels(access, zones);
 
-        return buildCalculationResult(artifact, models);
+        return buildCalculationResult(access, models);
     }
 
 
@@ -76,10 +79,10 @@
 
 
     protected List<FlowVelocityModel> getFlowVelocityModels(
-        MINFOArtifact       artifact,
+    	FlowVelocityAccess  access,
         List<DischargeZone> zones
     ) {
-        River river = FLYSUtils.getRiver(artifact);
+        River river = FLYSUtils.getRiver(access.getArtifact());
 
         List<FlowVelocityModel> models = new ArrayList<FlowVelocityModel>();
 
@@ -129,11 +132,11 @@
 
 
     protected CalculationResult buildCalculationResult(
-        MINFOArtifact           artifact,
+    	FlowVelocityAccess 	    access,
         List<FlowVelocityModel> models
     ) {
-        double kmLo = artifact.getDataAsDouble("ld_from");
-        double kmHi = artifact.getDataAsDouble("ld_to");
+        double kmLo = access.getLowerKM();
+        double kmHi = access.getUpperKM();
 
         logger.debug("Prepare data for km range: " + kmLo + " - " + kmHi);
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MiddleBedHeightCalculation.java	Tue Jul 03 11:03:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MiddleBedHeightCalculation.java	Tue Jul 03 12:13:36 2012 +0000
@@ -5,6 +5,7 @@
 
 import org.apache.log4j.Logger;
 
+import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.common.utils.DateUtils;
 
 import de.intevation.flys.model.BedHeightEpoch;
@@ -13,7 +14,7 @@
 import de.intevation.flys.model.BedHeightSingleValue;
 import de.intevation.flys.model.TimeInterval;
 
-import de.intevation.flys.artifacts.MINFOArtifact;
+import de.intevation.flys.artifacts.access.BedHeightAccess;
 import de.intevation.flys.artifacts.model.MiddleBedHeightData;
 
 
@@ -23,13 +24,16 @@
         Logger.getLogger(MiddleBedHeightCalculation.class);
 
 
-    public CalculationResult calculate(MINFOArtifact artifact) {
+    public CalculationResult calculate(BedHeightAccess access) {
         logger.info("MiddleBedHeightCalculation.calculate");
 
-        int[] singleIds = artifact.getBedHeightSingleIDs();
-        int[] epochIds  = artifact.getBedHeightEpochIDs();
+        int[] singleIds = access.getBedHeightSingleIDs();
+        int[] epochIds  = access.getBedHeightEpochIDs();
+        
 
         if (logger.isDebugEnabled()) {
+        	Artifact artifact = access.getArtifact();
+        	
             logger.debug("Artifact '" + artifact.identifier() + "' contains:");
             if (singleIds != null) {
                 logger.debug("   " + singleIds.length + " single bedheight ids");
@@ -40,14 +44,17 @@
             }
         }
 
-        List<BedHeightSingle> singles = getSingles(artifact, singleIds);
-        List<BedHeightEpoch>  epochs  = getEpochs(artifact, epochIds);
+        List<BedHeightSingle> singles = getSingles(access, singleIds);
+        List<BedHeightEpoch>  epochs  = getEpochs(access, epochIds);
 
-        return buildCalculationResult(artifact, singles, epochs);
+        return buildCalculationResult(access, singles, epochs);
     }
 
 
-    protected List<BedHeightSingle> getSingles(MINFOArtifact minfo, int[] ids) {
+    protected List<BedHeightSingle> getSingles(
+    	BedHeightAccess access,
+    	int[] ids
+    ) {
         List<BedHeightSingle> singles = new ArrayList<BedHeightSingle>();
 
         for (int id: ids) {
@@ -66,7 +73,10 @@
     }
 
 
-    protected List<BedHeightEpoch> getEpochs(MINFOArtifact minfo, int[] ids) {
+    protected List<BedHeightEpoch> getEpochs(
+    	BedHeightAccess access,
+    	int[] ids
+    ) {
         List<BedHeightEpoch> epochs = new ArrayList<BedHeightEpoch>();
 
         for (int id: ids) {
@@ -86,15 +96,14 @@
 
 
     protected CalculationResult buildCalculationResult(
-        MINFOArtifact         artifact,
+    	BedHeightAccess		  access,
         List<BedHeightSingle> singles,
         List<BedHeightEpoch>  epochs
     ) {
         logger.info("MiddleBedHeightCalculation.buildCalculationResult");
 
-        int    size = singles.size() + epochs.size();
-        double kmLo = artifact.getDataAsDouble("ld_from");
-        double kmHi = artifact.getDataAsDouble("ld_to");
+        double kmLo = access.getLowerKM();
+        double kmHi = access.getUpperKM();
 
         List<MiddleBedHeightData> data = new ArrayList<MiddleBedHeightData>();
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FlowVelocityState.java	Tue Jul 03 11:03:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FlowVelocityState.java	Tue Jul 03 12:13:36 2012 +0000
@@ -10,7 +10,7 @@
 import de.intevation.artifacts.CallContext;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
-import de.intevation.flys.artifacts.MINFOArtifact;
+import de.intevation.flys.artifacts.access.FlowVelocityAccess;
 import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
@@ -46,10 +46,12 @@
         logger.debug("FlowVelocityState.computeAdvance");
 
         List<Facet> newFacets = new ArrayList<Facet>();
+        
+        FlowVelocityAccess access = new FlowVelocityAccess(artifact);
 
         CalculationResult res = old instanceof CalculationResult
             ? (CalculationResult) old
-            : new FlowVelocityCalculation().calculate((MINFOArtifact) artifact);
+            : new FlowVelocityCalculation().calculate(access);
 
         if (facets == null || res == null) {
             return res;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MiddleBedHeight.java	Tue Jul 03 11:03:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MiddleBedHeight.java	Tue Jul 03 12:13:36 2012 +0000
@@ -10,7 +10,7 @@
 import de.intevation.artifactdatabase.state.Facet;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
-import de.intevation.flys.artifacts.MINFOArtifact;
+import de.intevation.flys.artifacts.access.BedHeightAccess;
 import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.FacetTypes;
@@ -35,10 +35,12 @@
         logger.debug("MiddleBedHeight.computeAdvance");
 
         List<Facet> newFacets = new ArrayList<Facet>();
+        
+        BedHeightAccess access = new BedHeightAccess(artifact);
 
         CalculationResult res = old instanceof CalculationResult
             ? (CalculationResult) old
-            : new MiddleBedHeightCalculation().calculate((MINFOArtifact) artifact);
+            : new MiddleBedHeightCalculation().calculate(access);
 
         if (facets == null || res == null) {
             return res;

http://dive4elements.wald.intevation.org