changeset 57:f01592cd6419

Funktionalität Feed initial bereitgestellt. gnv-artifacts/trunk@39 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 08 Sep 2009 12:22:00 +0000
parents 737d8bf63701
children f31343d80d53
files gnv-artifacts/Changelog gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java gnv-artifacts/src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultInputData.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/InputData.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/exception/TransitionException.java
diffstat 8 files changed, 207 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/Changelog	Tue Sep 08 10:39:50 2009 +0000
+++ b/gnv-artifacts/Changelog	Tue Sep 08 12:22:00 2009 +0000
@@ -1,10 +1,21 @@
+2009-09-08  Tim Englich  <tim.englich@intevation.de>
+
+    * src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java Edited,
+      src/main/java/de/intevation/gnv/transition/DefaultInputData.java Added,
+      src/main/java/de/intevation/gnv/transition/InputData.java Added,
+      src/main/java/de/intevation/gnv/transition/exception/TransitionException.java Added,
+      src/main/java/de/intevation/gnv/transition/TransitionBase.java Edited, 
+      src/main/java/de/intevation/gnv/transition/Transition.java Edited, 
+      src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Edited:
+      Funktionalität Feed initial bereitgestellt.
+      
 2009-09-08  Tim Englich  <tim.englich@intevation.de>
 
     * src/test/ressources/GNVArtifactsTestCase_Configuration.xml,
       src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java, 
       src/main/java/de/intevation/gnv/transition/TransitionBase.java, 
       src/main/java/de/intevation/gnv/transition/DefaultInputValue.java Edited:
-      Required Inputelements integrated in BAsicArtifact-Descibe-Output
+      Required Inputelements integrated in BasicArtifact-Descibe-Output
       
 2009-09-08  Tim Englich  <tim.englich@intevation.de>
 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Tue Sep 08 10:39:50 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Tue Sep 08 12:22:00 2009 +0000
@@ -3,6 +3,7 @@
  */
 package de.intevation.gnv.artifacts;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -17,9 +18,12 @@
 import de.intevation.artifactdatabase.Config;
 import de.intevation.artifactdatabase.DefaultArtifact;
 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
+import de.intevation.gnv.transition.DefaultInputData;
+import de.intevation.gnv.transition.InputData;
 import de.intevation.gnv.transition.InputValue;
 import de.intevation.gnv.transition.Transition;
 import de.intevation.gnv.transition.TransitionFactory;
+import de.intevation.gnv.transition.exception.TransitionException;
 
 /**
  * @author Tim Englich <tim.englich@intevation.de>
@@ -76,6 +80,24 @@
     }
     
     /**
+     * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document, java.lang.Object)
+     */
+    @Override
+    public Document feed(Document target, Object context) {
+        Document result = super.newDocument();
+        try {
+            if (this.current != null){
+                this.current.putInputData(this.parseInputData(target));
+                // TODO Ergebnisdokument erzeugen.
+            }
+        } catch (TransitionException e) {
+            log.error(e,e);
+            //TODO: Fehlerdokumenterzeugen.
+        }
+        return result;
+    }
+    
+    /**
      * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String, java.lang.Object)
      */
     @Override
@@ -203,5 +225,22 @@
         return node;
     }
     
+    protected Collection<InputData> parseInputData(Document document){
+        log.debug("GNVArtifactBase.parseInputData");
+        Collection<InputData> returnValue = null;
+        
+        NodeList inputElemets = Config.getNodeSetXPath(document, "action/data/input");
+        if(inputElemets != null){
+            returnValue = new ArrayList<InputData>(inputElemets.getLength());
+            for (int i = 0; i < inputElemets.getLength(); i++){
+                Node inputDataNode = inputElemets.item(i);
+                InputData inputData = new DefaultInputData(Config.getStringXPath(inputDataNode,"@name"), Config.getStringXPath(inputDataNode,"@value"));
+                log.debug(inputData.toString());
+                returnValue.add(inputData);
+            }
+        }
+        return returnValue;
+    }
+    
 
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java	Tue Sep 08 10:39:50 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java	Tue Sep 08 12:22:00 2009 +0000
@@ -45,15 +45,6 @@
     }
 
     /**
-     * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document, java.lang.Object)
-     */
-    @Override
-    public Document feed(Document target, Object context) {
-        log.debug("TimeSfeederiesArtifact.feed");
-        return super.feed(target, context);
-    }
-
-    /**
      * @see de.intevation.artifactdatabase.DefaultArtifact#out(org.w3c.dom.Document, java.lang.Object)
      */
     @Override
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultInputData.java	Tue Sep 08 12:22:00 2009 +0000
@@ -0,0 +1,44 @@
+/**
+ *
+ */
+package de.intevation.gnv.transition;
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class DefaultInputData implements InputData {
+
+    
+    private String name = null;
+    private String value = null;
+    /**
+     * Constructor
+     */
+    public DefaultInputData(String name , String value ) {
+        this.name = name;
+        this.value = value;
+    }
+
+    /**
+     * @see de.intevation.gnv.transition.InputData#getName()
+     */
+    public String getName() {
+        return this.name;
+    }
+
+    /**
+     * @see de.intevation.gnv.transition.InputData#getValue()
+     */
+    public String getValue() {
+        return this.value;
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return this.name + "==> "+ this.value;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/InputData.java	Tue Sep 08 12:22:00 2009 +0000
@@ -0,0 +1,13 @@
+/**
+ *
+ */
+package de.intevation.gnv.transition;
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public interface InputData {
+
+    public String getName();
+    public String getValue();
+}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java	Tue Sep 08 10:39:50 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java	Tue Sep 08 12:22:00 2009 +0000
@@ -8,6 +8,8 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
+import de.intevation.gnv.transition.exception.TransitionException;
+
 /**
  * @author Tim Englich <tim.englich@intevation.de>
  *
@@ -31,5 +33,8 @@
     public Transition getParent();
     
     public Collection<InputValue> getRequiredInputValues();
+    
+    public void putInputData(Collection<InputData> inputData) throws TransitionException;
+    
 
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Tue Sep 08 10:39:50 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Tue Sep 08 12:22:00 2009 +0000
@@ -5,6 +5,9 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
@@ -13,6 +16,7 @@
 
 import de.intevation.artifactdatabase.Config;
 import de.intevation.gnv.artifacts.GNVArtifactBase;
+import de.intevation.gnv.transition.exception.TransitionException;
 
 /**
  * @author Tim Englich <tim.englich@intevation.de>
@@ -34,9 +38,13 @@
     
     private Collection<String> reachableTransitions = null;
     
-    private Collection<InputValue> inputValues = null;
+    private Collection<String> inputValueNames = null;
+    
+    private Map<String,InputValue> inputValues = null;
     
     private Transition parent = null;
+    
+    private Collection<InputData> inputData = null;
     /**
      * Constructor
      */
@@ -69,7 +77,7 @@
      * @see de.intevation.gnv.transition.Transition#getRequiredInputValues()
      */
     public Collection<InputValue> getRequiredInputValues() {
-        return this.inputValues;
+        return this.inputValues.values();
     }
 
     /**
@@ -91,16 +99,18 @@
         }
         
         NodeList inputValuesNodes = Config.getNodeSetXPath(configuration,"inputvalues/inputvalue");
-        this.inputValues = new ArrayList<InputValue>(inputValuesNodes.getLength());
+        this.inputValues = new HashMap<String,InputValue>(inputValuesNodes.getLength());
+        this.inputValueNames = new ArrayList<String>(inputValuesNodes.getLength());
         for (int i = 0 ; i < inputValuesNodes.getLength(); i++){
             Node inputValueNode = inputValuesNodes.item(i);
             InputValue inputValue = new DefaultInputValue(Config.getStringXPath(inputValueNode,"@name"), Config.getStringXPath(inputValueNode,"@type"));
             log.debug(inputValue.toString());
-            this.inputValues.add(inputValue);
+            this.inputValues.put(inputValue.getName(),inputValue);
+            this.inputValueNames.add(inputValue.getName());
         }
         
         this.queryID = Config.getStringXPath(configuration,"queryID");
-        log.info("QueryID ==>"+ this.queryID);
+        log.info("QueryID ==> "+ this.queryID);
         
     }
 
@@ -117,4 +127,35 @@
     public void setParent(Transition transition) {
         this.parent = transition;
     }
+
+    /**
+     * @see de.intevation.gnv.transition.Transition#putInputData(java.util.Collection)
+     */
+    public void putInputData(Collection<InputData> inputData) throws TransitionException {
+        log.debug("TransitionBase.putInputData");
+        if (inputData != null){
+            Iterator<InputData> it = inputData.iterator();
+            while(it.hasNext()){
+                InputData tmpItem = it.next();
+                InputValue inputValue = this.inputValues.get(tmpItem.getName());
+                if (inputValue != null){
+                    if (this.inputData == null){
+                        this.inputData = new ArrayList<InputData>(inputData.size());
+                        // TODO validate Value;
+                        this.inputData.add(tmpItem);
+                    }
+                    
+                }else{
+                    String errMsg = "No Inputvalue given for Inputdata "+ tmpItem.getName();
+                    log.warn(errMsg+ "Value will be ignored");
+                    throw new TransitionException(errMsg);
+                    
+                }
+            }
+        }else{
+            log.warn("No Inputdata given");
+        }
+    
+    }
+    
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/exception/TransitionException.java	Tue Sep 08 12:22:00 2009 +0000
@@ -0,0 +1,48 @@
+/**
+ *
+ */
+package de.intevation.gnv.transition.exception;
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public class TransitionException extends Exception {
+
+    /**
+     * The UID of the Class
+     */
+    private static final long serialVersionUID = -1635921702746050244L;
+
+    /**
+     * Constructor
+     */
+    public TransitionException() {
+        super();
+    }
+
+    /**
+     * Constructor
+     * @param message
+     */
+    public TransitionException(String message) {
+        super(message);
+    }
+
+    /**
+     * Constructor
+     * @param cause
+     */
+    public TransitionException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * Constructor
+     * @param message
+     * @param cause
+     */
+    public TransitionException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+}

http://dive4elements.wald.intevation.org