changeset 9:a4cb6d175a6e

Support for Initial DescribeCall to ArtifactDatabase implemented gnv/trunk@85 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 14 Sep 2009 15:29:38 +0000
parents 65ff6fcfee0c
children e6c47838eee6
files gnv/Changelog gnv/src/main/java/de/intevation/gnv/action/SelectArtifactFactoryAction.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/Artifact.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/ArtifactDescription.java
diffstat 6 files changed, 234 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/gnv/Changelog	Mon Sep 14 13:56:03 2009 +0000
+++ b/gnv/Changelog	Mon Sep 14 15:29:38 2009 +0000
@@ -1,3 +1,12 @@
+2009-09-14  Tim Englich  <tim.englich@intevation.de>
+
+    * src/main/java/de/intevation/gnv/artifactdatabase/objects/ArtifactDescription.java,
+      src/main/java/de/intevation/gnv/artifactdatabase/objects/Artifact.java, 
+      src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java, 
+      src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java, 
+      src/main/java/de/intevation/gnv/action/SelectArtifactFactoryAction.java:
+      Support for Initial DescribeCall to ArtifactDatabase implemented
+       
 2009-09-14  Tim Englich  <tim.englich@intevation.de>
 
     * src/main/webapp/WEB-INF/config/struts-config.xml: 
--- a/gnv/src/main/java/de/intevation/gnv/action/SelectArtifactFactoryAction.java	Mon Sep 14 13:56:03 2009 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/action/SelectArtifactFactoryAction.java	Mon Sep 14 15:29:38 2009 +0000
@@ -15,6 +15,7 @@
 import de.intevation.gnv.action.sessionmodel.SessionModelFactory;
 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient;
 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory;
+import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription;
 import de.intevation.gnv.artifactdatabase.objects.ArtifactObject;
 
 /**
@@ -45,6 +46,8 @@
         ArtifactObject artifact = adc.createNewArtifact(sm.getSelectedArtifactFactory());
         sm.setCurrentArtifact(artifact);
         
+        ArtifactDescription artifactdescription = adc.getCurrentStepDescription(sm.getSelectedArtifactFactory(), artifact);
+        
         // TODO Initiales Describe Abrufen
         
         
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java	Mon Sep 14 13:56:03 2009 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java	Mon Sep 14 15:29:38 2009 +0000
@@ -6,6 +6,8 @@
 import java.util.Collection;
 
 import de.intevation.gnv.artifactdatabase.client.exception.ArtifactDatabaseClientException;
+import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription;
+import de.intevation.gnv.artifactdatabase.objects.ArtifactFactory;
 import de.intevation.gnv.artifactdatabase.objects.ArtifactObject;
 
 /**
@@ -23,12 +25,18 @@
     public Collection<ArtifactObject> getArtifactFactories() throws ArtifactDatabaseClientException;
 
     /**
-     * b
+     * 
      * @param artifactFactory
-     * @return
+     * @return the new Artifact
      * @throws ArtifactDatabaseClientException
      */
     public ArtifactObject createNewArtifact(ArtifactObject artifactFactory) throws ArtifactDatabaseClientException;
 
-
+    /**
+     * 
+     * @param currentArtifact
+     * @return the Current Artifact
+     * @throws ArtifactDatabaseClientException
+     */
+    public ArtifactDescription getCurrentStepDescription(ArtifactObject artifactFactory, ArtifactObject currentArtifact) throws ArtifactDatabaseClientException;
 }
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java	Mon Sep 14 13:56:03 2009 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java	Mon Sep 14 15:29:38 2009 +0000
@@ -38,6 +38,7 @@
 
 import de.intevation.gnv.artifactdatabase.client.exception.ArtifactDatabaseClientException;
 import de.intevation.gnv.artifactdatabase.objects.Artifact;
+import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription;
 import de.intevation.gnv.artifactdatabase.objects.ArtifactFactory;
 import de.intevation.gnv.artifactdatabase.objects.ArtifactObject;
 import de.intevation.gnv.util.XMLUtils;
@@ -89,9 +90,7 @@
             while (it.hasNext()){
                 String server = it.next();
                 String url =  server+ "/factories";
-                InputStream inputStream = this.doGetRequest(url);
-                Document document = xmlUtils.readDocument(inputStream);
-                log.debug(xmlUtils.writeDocument2String(document));
+                Document document = this.doGetRequest(url);
                 if (resultValues == null){
                     resultValues = this.getArtifactFactories(document,server);
                 }else{
@@ -123,12 +122,14 @@
     /**
      * @throws IOException
      */
-    private InputStream doGetRequest(String requestUrl) throws IOException {
+    private Document doGetRequest(String requestUrl) throws IOException {
+        XMLUtils xmlUtils = new XMLUtils();
         Client client = new Client(Protocol.HTTP);
-        Request request = new Request(Method.GET, requestUrl);  
-        Response response = client.handle(request);
+        Response response = client.get(requestUrl);
         Representation output = response.getEntity();
-        return output.getStream();
+        Document document = xmlUtils.readDocument(output.getStream());
+        log.debug(xmlUtils.writeDocument2String(document));
+        return document;
     }
     
     /**
@@ -161,13 +162,8 @@
             throws ArtifactDatabaseClientException {
         
         try {
-            XMLUtils xmlUtils = new XMLUtils();
             Document request = this.createCreateRequestBody(artifactFactory.getId());
-            String url = ((ArtifactFactory)artifactFactory).getDataBaseUrl();
-            InputStream is = this.doPostRequest(url+"/create", request);
-            Document result = xmlUtils.readDocument(is);
-            // TODO: Fehleranalyse des Dokumentes
-            log.debug(xmlUtils.writeDocument2String(result));
+            Document result = doPostRequest(artifactFactory, request, "create");
             return this.getArtifact(result);
         } catch (IOException e) {
             log.error(e,e);
@@ -216,5 +212,86 @@
         node.setPrefix(NAMESPACE_PREFIX);
         return node;
     }
+
+/**
+ * @param artifactFactory
+ * @param xmlUtils
+ * @param request
+ * @throws IOException
+ */
+private Document doPostRequest(ArtifactObject artifactFactory,
+        Document request, String suburl) throws IOException {
+    XMLUtils xmlUtils = new XMLUtils();
+    String url = ((ArtifactFactory)artifactFactory).getDataBaseUrl();
+    InputStream is = this.doPostRequest(url+"/"+suburl, request);
+    Document result = xmlUtils.readDocument(is);
+    // TODO: Fehleranalyse des Dokumentes
+    log.debug(xmlUtils.writeDocument2String(result));
+    return result;
+}
+    
+    private Document createDescribeRequestBody(ArtifactObject currentArtifact){
+        Document document = new XMLUtils().newDocument();
+        Node rootNode  = this.createRootNode(document);
+        Element typeNode = this.createArtifactElement(document, "type");
+        typeNode.setAttribute("name", "describe");
+        rootNode.appendChild(typeNode);
+             
+        Element uuidNode = this.createArtifactElement(document, "uuid");
+        uuidNode.setAttribute("value", currentArtifact.getId());
+        rootNode.appendChild(uuidNode);
+        
+        Element hashNode = this.createArtifactElement(document, "hash");
+        hashNode.setAttribute("value", currentArtifact.getHash());
+        rootNode.appendChild(hashNode);
+        
+        return document;
+    }
+
+    /**
+     * @see de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient#getCurrentStepDescription(de.intevation.gnv.artifactdatabase.objects.ArtifactFactory, de.intevation.gnv.artifactdatabase.objects.ArtifactObject)
+     */
+    public ArtifactDescription getCurrentStepDescription(ArtifactObject artifactFactory,
+            ArtifactObject currentArtifact)
+            throws ArtifactDatabaseClientException {
+        try {
+            
+            Document request = this.createDescribeRequestBody(currentArtifact);
+            String url = ((ArtifactFactory)artifactFactory).getDataBaseUrl()+"/artifact/"+ currentArtifact.getId();
+            Document result = this.doGetRequest(url);
+            return this.readDescription(result,currentArtifact);
+        } catch (IOException e) {
+            log.error(e,e);
+            throw new ArtifactDatabaseClientException(e);
+        }
+    }
+    
+    private ArtifactDescription readDescription(Document document, ArtifactObject artifact) throws ArtifactDatabaseClientException{
+        XMLUtils xmlUtils = new XMLUtils();
+        if (artifact instanceof ArtifactDescription){
+            ArtifactDescription ad = (ArtifactDescription)artifact;
+            Node uiNode =  xmlUtils.getNodeXPath(document, "/result/ui");
+            Node outputNode = xmlUtils.getNodeXPath(document, "/result/outputs");
+            String currentState = xmlUtils.getStringXPath(document, "/result/state/@name");
+            NodeList statesList = xmlUtils.getNodeSetXPath(document, "/result/reachable-states/state/@name");
+            Collection<String> reachableStates = new ArrayList<String>(statesList.getLength());
+            for (int i = 0; i < statesList.getLength(); i++){
+                reachableStates.add(statesList.item(i).getNodeValue());
+            }
+            
+            ad.setCurrentOut(outputNode);
+            ad.setCurrentUI(uiNode);
+            ad.setCurrentState(currentState);
+            ad.setReachableStates(reachableStates);
+            return ad;
+        }else{
+            log.error("Artifact must be Instance of ArtifactDescription");
+            throw new ArtifactDatabaseClientException("Artifact must be Instance of ArtifactDescription");
+        }
+       
+        
+    }
+    
+    
    
 }
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/Artifact.java	Mon Sep 14 13:56:03 2009 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/Artifact.java	Mon Sep 14 15:29:38 2009 +0000
@@ -2,15 +2,84 @@
  *
  */
 package de.intevation.gnv.artifactdatabase.objects;
+
+import java.util.Collection;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
 /**
  * @author Tim Englich <tim.englich@intevation.de>
  *
  */
-public class Artifact implements ArtifactObject {
+public class Artifact implements ArtifactObject, ArtifactDescription {
 
     private String id = null;
     private String hash = null;
     private boolean selected = false;
+    
+    private Node currentUI = null;
+    private Node currentOut = null;
+    
+    private Collection<String> reachableStates;
+    private String currentState = null;
+    
+    /**
+     * @see de.intevation.gnv.artifactdatabase.objects.ArtifactDescription#getCurrentUI()
+     */
+    public Node getCurrentUI() {
+        return currentUI;
+    }
+
+    /**
+     * @see de.intevation.gnv.artifactdatabase.objects.ArtifactDescription#setCurrentUI(org.w3c.dom.Node)
+     */
+    public void setCurrentUI(Node currentUI) {
+        this.currentUI = currentUI;
+    }
+
+    /**
+     * @return the currentOut
+     */
+    public Node getCurrentOut() {
+        return currentOut;
+    }
+
+    /**
+     * @see de.intevation.gnv.artifactdatabase.objects.ArtifactDescription#setCurrentOut(org.w3c.dom.Node)
+     */
+    public void setCurrentOut(Node currentOut) {
+        this.currentOut = currentOut;
+    }
+
+    /**
+     * @see de.intevation.gnv.artifactdatabase.objects.ArtifactDescription#getReachableStates()
+     */
+    public Collection<String> getReachableStates() {
+        return reachableStates;
+    }
+
+    /**
+     * @see de.intevation.gnv.artifactdatabase.objects.ArtifactDescription#setReachableStates(java.util.Collection)
+     */
+    public void setReachableStates(Collection<String> reachableStates) {
+        this.reachableStates = reachableStates;
+    }
+
+    /**
+     * @see de.intevation.gnv.artifactdatabase.objects.ArtifactDescription#getCurrentState()
+     */
+    public String getCurrentState() {
+        return currentState;
+    }
+
+    /**
+     * @see de.intevation.gnv.artifactdatabase.objects.ArtifactDescription#setCurrentState(java.lang.String)
+     */
+    public void setCurrentState(String currentState) {
+        this.currentState = currentState;
+    }
+
     /**
      * Constructor
      */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/objects/ArtifactDescription.java	Mon Sep 14 15:29:38 2009 +0000
@@ -0,0 +1,51 @@
+/**
+ *
+ */
+package de.intevation.gnv.artifactdatabase.objects;
+
+import java.util.Collection;
+
+import org.w3c.dom.Node;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ *
+ */
+public interface ArtifactDescription {
+
+    /**
+     * @return the currentUI
+     */
+    public abstract Node getCurrentUI();
+
+    /**
+      @param currentUI the currentUI to set
+     */
+    public abstract void setCurrentUI(Node currentUI);
+
+    /**
+      @param currentOut the currentOut to set
+     */
+    public abstract void setCurrentOut(Node currentOut);
+
+    /**
+     * @return the reachableStates
+     */
+    public abstract Collection<String> getReachableStates();
+
+    /**
+      @param reachableStates the reachableStates to set
+     */
+    public abstract void setReachableStates(Collection<String> reachableStates);
+
+    /**
+     * @return the currentState
+     */
+    public abstract String getCurrentState();
+
+    /**
+      @param currentState the currentState to set
+     */
+    public abstract void setCurrentState(String currentState);
+
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org