changeset 88:1b12021905b9

Some CodeCleanup done. ExceptionDocument will now be returned gnv-artifacts/trunk@125 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Thu, 24 Sep 2009 10:45:24 +0000
parents ce398a7a99fc
children cde042a0a395
files gnv-artifacts/Changelog gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java
diffstat 6 files changed, 77 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/Changelog	Thu Sep 24 10:05:07 2009 +0000
+++ b/gnv-artifacts/Changelog	Thu Sep 24 10:45:24 2009 +0000
@@ -1,3 +1,14 @@
+2009-09-24  Tim Englich  <tim.englich@intevation.de>
+
+    * src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java Edited:
+     Obsolet TODOs removed 
+    * src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Edited, 
+      src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java Edited, 
+      src/main/java/de/intevation/gnv/transition/TransitionBase.java Edited:
+      Create Exception Report added 
+    * src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java (createExceptionReport) Edited:
+      Method for creating Exceptionreports added. 
+      
 2009-09-24  Tim Englich  <tim.englich@intevation.de>
 
     * src/test/ressources/queries.properties Edited:
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Thu Sep 24 10:05:07 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java	Thu Sep 24 10:45:24 2009 +0000
@@ -92,39 +92,47 @@
     @Override
     public Document advance(Document target, CallContext context) {
         Document result = XMLUtils.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());
-                        nextStep.putInputData(this.current.getInputData());
-                        // 4. Umschalten auf neue Transistion
-                        this.current = nextStep;
-                    } catch (TransitionException e) {
-                        log.error(e,e);
-                        // TODO: Errormmessage senden.
+        try {
+            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());
+                            nextStep.putInputData(this.current.getInputData());
+                            // 4. Umschalten auf neue Transistion
+                            this.current = nextStep;
+                        } catch (TransitionException e) {
+                            log.error(e,e);
+                            result = new ArtifactXMLUtilities().createExceptionReport(e.getLocalizedMessage(), XMLUtils.newDocument());
+                        }
+                        
+                    }else{
+                        String msg = "Advance nicht möglich, da die Bedingungen für den Übergang " +
+                                    "in den neuen Zustand noch nicht gegeben ist.";
+                        log.error(msg);
+                        result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument());
                     }
                     
                 }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.
+                    String msg = "Transitionsübergang wird nicht unterstützt.";
+                    log.error(msg);
+                    result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument());
                 }
-                
             }else{
-                log.error("Transitionsübergang wird nicht unterstützt.");
-                // TODO: Errormmessage senden.
+                String msg = "Kein Transitionsschritt aktiviert.";
+                log.error(msg);
+                result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument());
             }
-        }else{
-            log.error("Kein Transitionsschritt aktiviert.");
-            // TODO: Errormmessage senden.
+        } catch (Exception e) {
+            log.error(e,e);
+            result = new ArtifactXMLUtilities().createExceptionReport(e.getLocalizedMessage(), XMLUtils.newDocument());
         }
         return result;
     }
@@ -154,7 +162,7 @@
             }
         } catch (TransitionException e) {
             log.error(e,e);
-            //TODO: Fehlerdokumenterzeugen.
+            return new ArtifactXMLUtilities().createExceptionReport(e.getLocalizedMessage(), XMLUtils.newDocument());
         }
         return result;
     }
@@ -196,14 +204,13 @@
     protected Document createDescibeOutput(){
         log.debug("GNVArtifactBase.createDescibeOutput");
         Document document = XMLUtils.newDocument();
-        Element rootNode = this.createRootNode(document);
+         Element rootNode = this.createRootNode(document);
         this.createHeader(rootNode, document, "describe");
         this.createOutputs(rootNode, document);
         this.createCurrentState(rootNode, document);
         this.createReachableStates(rootNode, document);
         this.createModel(rootNode, document);
         this.createUserInterface(rootNode, document);
-        
         return document;
     }
     
@@ -236,6 +243,7 @@
                 String value = states.next();
                 Element currentNode = xmlUtilities.createArtifactElement(document,"state");
                 currentNode.setAttribute("name", value);
+                log.debug("Reachable State: "+value);
                 currentNode.setAttribute("description", transitions.get(value).getDescription());
                 stateNode.appendChild(currentNode);
             }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java	Thu Sep 24 10:05:07 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java	Thu Sep 24 10:45:24 2009 +0000
@@ -79,10 +79,12 @@
      */
     @Override
     public Document advance(Document target, CallContext context) {
+        
+        Document result = null;
         if (this.productArtifact == null){
             if (this.current != null){
-                try {
-                    String uuid = Config.getStringXPath(target, "action/uuid/@value"); // TODO: müssen wir für das subartifact eine veränderte uuid führen?
+                
+                    String uuid = Config.getStringXPath(target, "action/uuid/@value");
                     String hash = Config.getStringXPath(target, "action/hash/@value");
                     this.productArtifact = this.current.getArtifactFactory().createArtifact(uuid, context);
                     Document feedDocument =  xmlUtilities.reInitDocument(this.createFeedProductArtifactDocument(uuid, hash));
@@ -93,18 +95,16 @@
                     String targetName =  Config.getStringXPath(descibeDocument, "result/reachable-states/state/@name");
                     Document advanceDocument = xmlUtilities.reInitDocument(this.createAdvanceProductArtifactDocument(uuid, hash, targetName));
                     log.debug("Advance ==> "+this.xmlUtilities.writeDocument2String(advanceDocument));
-                    return this.productArtifact.advance(advanceDocument, context);
-                } catch (RuntimeException e) {
-                    log.error(e,e);
-                }
+                    result =  this.productArtifact.advance(advanceDocument, context);
             }else{
-                log.warn("Artifact is not configured properly. Call feed first.");
-                // TODO Fehlerdokument erzeugen.
+                String msg = "Artifact is not configured properly. Call feed first.";
+                log.error(msg);
+                result =  new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument());
             }
-            return null;
         }else{
-            return this.productArtifact.advance(target, context);
+            result = this.productArtifact.advance(target, context);
         }
+        return result;
     }
     private Document createAdvanceProductArtifactDocument(String uuid, String hash, String targetName){
         Document document = XMLUtils.newDocument();
@@ -193,11 +193,13 @@
             String productName = Config.getStringXPath(target, "action/data/input[@name='product']/@value");
             if (this.products.containsKey(productName)) {
                 this.current = this.products.get(productName);
+                // TODO : success-Dokument erzeugen
+                return null;
             }else{
-                log.error("Product does not exists for "+productName);
-                // TODO: Fehlerdokument erzeugen.
+                String msg = "Product does not exists for "+productName;
+                log.error(msg);
+                return new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument());
             }
-            return null;
         }else{
             return this.productArtifact.feed(target, context);
         }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java	Thu Sep 24 10:05:07 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/VerticalProfileChartFactory.java	Thu Sep 24 10:45:24 2009 +0000
@@ -325,7 +325,7 @@
         Iterator<KeyValueDescibeData> it = values.iterator();
     	while(it.hasNext()){
     	    KeyValueDescibeData data = it.next();
-    		if (id  ==Integer.parseInt(data.getKey())){ // TODO just a hack
+    		if (id  ==Integer.parseInt(data.getKey())){
     		    return data.getValue();
     		}
     	}
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Thu Sep 24 10:05:07 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java	Thu Sep 24 10:45:24 2009 +0000
@@ -334,7 +334,8 @@
                 if (newValue.length() > 0){
                     newValue= newValue + " , ";
                 }
-                newValue = newValue + "to_date('"+values[i].trim()+"', 'YYYY.MM.DD HH24:MI:SS')"; // TODO JUST HACK FIND A BETTER RESOLUTION
+               // TODO JUST HACK FIND A BETTER RESOLUTION
+                newValue = newValue + "to_date('"+values[i].trim()+"', 'YYYY.MM.DD HH24:MI:SS')"; 
             }
             return newValue;
         }
@@ -391,8 +392,6 @@
                 
                 Object o = it.next();
                 if (o instanceof Collection<?>){
-                        // TODO: HACK:
-                        // BESSERE LÖSUNG FINDEN
                         String name = null;
                         boolean multiselect = false;
                         if (o instanceof NamedCollection<?>){
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java	Thu Sep 24 10:05:07 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java	Thu Sep 24 10:45:24 2009 +0000
@@ -119,5 +119,15 @@
         return node;
     }
     
+    public Document createExceptionReport(String message, Document document){
+        log.debug("ArtifactXMLUtilities.createExceptionReport");
+        Element exceptionReportNode = this.createArtifactElement(document, "exceptionreport");
+        document.appendChild(exceptionReportNode);
+        Element exceptionNode = this.createArtifactElement(document, "exception");
+        exceptionNode.setTextContent(message);
+        exceptionReportNode.appendChild(exceptionNode);
+        return document;
+    }
+    
 
 }

http://dive4elements.wald.intevation.org