changeset 58:f31343d80d53

Artifact.advance initial implementiert gnv-artifacts/trunk@40 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 08 Sep 2009 14:07:59 +0000
parents f01592cd6419
children 2c5d8f5bced1
files gnv-artifacts/Changelog gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.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/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java gnv-artifacts/src/test/ressources/GNVArtifactsTestCase_Configuration.xml gnv-artifacts/src/test/ressources/timeseries/timeseries_step_01_advance.xml gnv-artifacts/src/test/ressources/timeseries/timeseries_step_01_feed.xml
diffstat 8 files changed, 180 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/Changelog	Tue Sep 08 12:22:00 2009 +0000
+++ b/gnv-artifacts/Changelog	Tue Sep 08 14:07:59 2009 +0000
@@ -1,3 +1,14 @@
+2009-09-08  Tim Englich  <tim.englich@intevation.de>
+
+    * 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,
+      src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java Edited,
+      src/test/ressources/GNVArtifactsTestCase_Configuration.xml Edited,
+      src/test/ressources/timeseries/timeseries_step_01_feed.xml Added , 
+      src/test/ressources/timeseries/timeseries_step_01_advance.xml Added :
+      Artifact.advance initial implementiert
+      
 2009-09-08  Tim Englich  <tim.englich@intevation.de>
 
     * src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java Edited,
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Tue Sep 08 12:22:00 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Tue Sep 08 14:07:59 2009 +0000
@@ -72,6 +72,53 @@
         super();
     }
     
+    /**
+     * @see de.intevation.artifactdatabase.DefaultArtifact#advance(org.w3c.dom.Document, java.lang.Object)
+     */
+    @Override
+    public Document advance(Document target, Object context) {
+        Document result = super.newDocument();
+        if (this.current != null){
+            String transitionName = this.readTransitionName(target);
+            if (this.current.isTransitionReachable(transitionName)){
+                // 1. Prüfung ob Transition valide ist
+                if (this.current.validate()){
+                    
+                    try {
+                        Transition nextStep = this.transitions.get(transitionName);
+                        // 2.Ergebnisse Berechnen
+                        this.current.advance();
+                        // 3. Ergebnisse übergeben
+                        nextStep.setDescibeData(this.current.getDescibeData());
+                        // 4. Umschalten auf neue Transistion
+                        this.current = nextStep;
+                    } catch (TransitionException e) {
+                        log.error(e,e);
+                        // TODO: Errormmessage senden.
+                    }
+                    
+                }else{
+                    log.error("Advance nicht möglich, da die Bedingungen für den Übergang " +
+                                "in den neuen Zustand noch nicht gegeben ist.");
+                    // TODO: Errormmessage senden.
+                }
+                
+            }else{
+                log.error("Transitionsübergang wird nicht unterstützt.");
+                // TODO: Errormmessage senden.
+            }
+        }else{
+            log.error("Kein Transitionsschritt aktiviert.");
+            // TODO: Errormmessage senden.
+        }
+        return result;
+    }
+
+    protected String readTransitionName(Document document) {
+        String returnValue = Config.getStringXPath(document, "action/target/@name");
+        return returnValue;
+    }
+
     protected Node getConfigurationFragment(Document document){
         log.debug("GNVArtifactBase.getConfigurationFragment");
         String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll(XPATH_IDENTIFIER_REPLACE, this.name);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java	Tue Sep 08 12:22:00 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java	Tue Sep 08 14:07:59 2009 +0000
@@ -20,6 +20,8 @@
     
     public Collection<String> reachableTransitions();
     
+    public boolean isTransitionReachable(String transitionID);
+    
     public String getID();
     
     public String getDescription();
@@ -36,5 +38,12 @@
     
     public void putInputData(Collection<InputData> inputData) throws TransitionException;
     
+    public void advance() throws TransitionException;
+    
+    
+    public Collection<Object> getDescibeData();
+    
+    public void setDescibeData(Collection<Object> descibeData);
+    
 
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Tue Sep 08 12:22:00 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Tue Sep 08 14:07:59 2009 +0000
@@ -16,6 +16,10 @@
 
 import de.intevation.artifactdatabase.Config;
 import de.intevation.gnv.artifacts.GNVArtifactBase;
+import de.intevation.gnv.geobackend.base.Result;
+import de.intevation.gnv.geobackend.base.query.QueryExecutor;
+import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
+import de.intevation.gnv.geobackend.base.query.exception.QueryException;
 import de.intevation.gnv.transition.exception.TransitionException;
 
 /**
@@ -44,7 +48,9 @@
     
     private Transition parent = null;
     
-    private Collection<InputData> inputData = null;
+    private Map<String,InputData> inputData = null;
+    
+    private Collection<Object> descibeData = null;
     /**
      * Constructor
      */
@@ -140,9 +146,9 @@
                 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);
+                        this.inputData = new HashMap<String,InputData>(inputData.size());
+                        // TODO validate Value; und Valueconcatenieren
+                        this.inputData.put(tmpItem.getName(),tmpItem);
                     }
                     
                 }else{
@@ -157,5 +163,60 @@
         }
     
     }
-    
+
+    /**
+     * @see de.intevation.gnv.transition.Transition#isTransitionReachable(java.lang.String)
+     */
+    public boolean isTransitionReachable(String transitionID) {
+        log.debug("TransitionBase.isTransitionReachable");
+        boolean returnValue = false;
+        Iterator<String> transitions = reachableTransitions.iterator();
+        while (transitions.hasNext()){
+            if(transitions.next().equals(transitionID)){
+                log.debug("Transition "+transitionID+" wird unterstützt.");
+                returnValue = true;
+                break;
+            }
+        }
+        return returnValue;
+    }
+
+    /**
+     * @see de.intevation.gnv.transition.Transition#advance()
+     */
+    public void advance() throws TransitionException {
+        log.debug("TransitionBase.advance");
+        try {
+            String[] filterValues = new String[this.inputValueNames.size()];
+            Iterator<String> it = this.inputValueNames.iterator();
+            int i = 0;
+            while (it.hasNext()){
+                filterValues[i++] = this.inputData.get(it.next()).getValue();
+            }
+            QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor();
+            Collection<Result> result = queryExecutor.executeQuery(this.queryID, filterValues);
+            if (this.descibeData == null){
+                this.descibeData = new ArrayList<Object>();
+            }
+            this.descibeData.add(result);
+        } catch (QueryException e) {
+            log.error(e,e);
+            throw new TransitionException(e);
+        }
+    }
+
+    /**
+     * @see de.intevation.gnv.transition.Transition#getDescibeData()
+     */
+    public Collection<Object> getDescibeData() {
+        return this.descibeData;
+    }
+
+    /**
+     * @see de.intevation.gnv.transition.Transition#setDescibeData(java.util.Collection)
+     */
+    public void setDescibeData(Collection<Object> descibeData) {
+        this.descibeData = descibeData;
+        
+    }
 }
--- a/gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java	Tue Sep 08 12:22:00 2009 +0000
+++ b/gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java	Tue Sep 08 14:07:59 2009 +0000
@@ -3,8 +3,11 @@
  */
 package de.intevation.gnv.artifacts;
 
+import java.io.File;
+import java.io.IOException;
 import java.io.StringWriter;
 
+import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.Transformer;
@@ -18,6 +21,7 @@
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
 
 import de.intevation.artifactdatabase.Config;
 import de.intevation.artifactdatabase.FactoryBootstrap;
@@ -77,15 +81,15 @@
         assertNotNull(artifact);
         log.debug("TimeSeries-Artifact is available");
         
-        Document indata = this.getDocument();
-        Document outData = this.createOutputDocument();
+
         Document outputData = artifact.describe(bootstrap.getContext());
         this.writeDocument2Log(outputData);
         
-        artifact.feed(indata, bootstrap.getContext());
-        artifact.advance(outData, bootstrap.getContext());
+        artifact.feed(this.readDocument("src/test/ressources/timeseries/timeseries_step_01_feed.xml"), bootstrap.getContext());
+        outputData = artifact.advance(this.readDocument("src/test/ressources/timeseries/timeseries_step_01_advance.xml"), bootstrap.getContext());
+        this.writeDocument2Log(outputData);
         outputData = artifact.describe(bootstrap.getContext());
-        
+        this.writeDocument2Log(outputData);
         
         
     }
@@ -139,5 +143,22 @@
         }
     }
     
+    
+    protected Document readDocument(String fileName){
+        Document returnValue = null;
+        try {
+            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+            returnValue = docBuilder.parse (new File(fileName));
+        } catch (ParserConfigurationException e) {
+            log.error(e,e);
+        } catch (SAXException e) {
+            log.error(e,e);
+        } catch (IOException e) {
+            log.error(e,e);
+        }
+        return returnValue;
+    }
+    
 
 }
--- a/gnv-artifacts/src/test/ressources/GNVArtifactsTestCase_Configuration.xml	Tue Sep 08 12:22:00 2009 +0000
+++ b/gnv-artifacts/src/test/ressources/GNVArtifactsTestCase_Configuration.xml	Tue Sep 08 14:07:59 2009 +0000
@@ -12,17 +12,17 @@
         <artifact name="timeSeries">
             <transitions>
                 
-                <transition id="timeSeries.start" description="timeSeries.start.description" transition="de.intevation.gnv.transition.DefaultTransition">
+                <transition id="timeseries.step.1" description="timeSeries.start.description" transition="de.intevation.gnv.transition.DefaultTransition">
                     <queryID>mesh</queryID>
                     <reachableTransitions>
-                        <transition>timeSeries.end</transition>
+                        <transition>timeseries.step.2</transition>
                     </reachableTransitions>
                     <inputvalues>
                         <inputvalue name="meshid" type="Integer"/>
                     </inputvalues>
                 </transition>
                 
-                <transition id="timeSeries.end" description="timeSeries.end.description" transition="de.intevation.gnv.transition.DefaultTransition">
+                <transition id="timeseries.step.2" description="timeSeries.end.description" transition="de.intevation.gnv.transition.DefaultTransition">
                     <queryID>mesh</queryID>
                 </transition>
             </transitions>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/test/ressources/timeseries/timeseries_step_01_advance.xml	Tue Sep 08 14:07:59 2009 +0000
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<art:action
+     xmlns:art="http://www.intevation.de/2009/artifacts">
+     <art:type name="advance"/>
+     <art:uuid value="dd87ce50-9bbe-11de-8a39-0800200c9a66"/>
+     <art:hash value="8392d409b5518044465ac8e9b7daf5ef"/>
+     <art:target name="timeseries.step.2"/>
+</art:action>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/test/ressources/timeseries/timeseries_step_01_feed.xml	Tue Sep 08 14:07:59 2009 +0000
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<art:action
+     xmlns:art="http://www.intevation.de/2009/artifacts">
+     <art:type name="feed"/>
+     <art:uuid value="dd87ce50-9bbe-11de-8a39-0800200c9a66"/>
+     <art:hash value="8392d409b5518044465ac8e9b7daf5ef"/>
+     <art:data>
+        <art:input name="meshid" value="2"/>
+     </art:data>
+</art:action>
\ No newline at end of file

http://dive4elements.wald.intevation.org