changeset 2606:619f6dfec901

#460 Fixed duplicated Outputs in DESCRIBE documents. flys-artifacts/trunk@4186 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 30 Mar 2012 09:38:29 +0000
parents 15a3684c6bce
children 247f3e98a14b
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java
diffstat 3 files changed, 38 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Mar 29 11:09:26 2012 +0000
+++ b/flys-artifacts/ChangeLog	Fri Mar 30 09:38:29 2012 +0000
@@ -1,3 +1,17 @@
+2012-03-30  Ingo Weinzierl <ingo@intevation.de>
+
+	flys/issue460 (W-Differenzen: Frühere Berechnungen aus den Datenkorb werden doppelt geladen)
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: Removed
+	  code to find out all Outputs of this Artifacts. A method getOutputs()
+	  had been implemented some time ago that does exactly this work.
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Heavy
+	  bugfix! Adding the current state id to the list of previous state ids
+	  for temporary usage was no good idea! Now, the list of previous state
+	  ids only modifified in advance(). This solves the problem of having
+	  duplicated Outputs in the Artifact's DESCRIBE document.
+
 2012-03-29  Ingo Weinzierl <ingo@intevation.de>
 
 	flys/issue366 (W-INFO / Abflusskurve, Diagramm: Umbenennen von Themen und Anzeige im Diagramm)
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu Mar 29 11:09:26 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Fri Mar 30 09:38:29 2012 +0000
@@ -264,10 +264,12 @@
         facets           = flys.cloneFacets();
         // Do not clone filter facets!
 
-        List<String> stateIds = getPreviousStateIds();
-        stateIds.add(getCurrentStateId());
+        ArrayList<String> stateIds     = (ArrayList<String>) getPreviousStateIds();
+        ArrayList<String> toInitialize = (ArrayList<String>) stateIds.clone();
 
-        for (String stateId: stateIds) {
+        toInitialize.add(getCurrentStateId());
+
+        for (String stateId: toInitialize) {
             State state = getState(context, stateId);
 
             if (state != null) {
@@ -393,16 +395,19 @@
 
         Element result = ec.create("result");
 
-        String targetState = XMLUtils.xpathString(
+        String currentStateId = getCurrentStateId();
+        String targetState    = XMLUtils.xpathString(
             target, XPATH_ADVANCE_TARGET, ArtifactNamespaceContext.INSTANCE);
 
         logger.info("FLYSArtifact.advance() to '" + targetState + "'");
 
-        if (isStateReachable(targetState, context)) {
+        if (!currentStateId.equals(targetState)
+            && isStateReachable(targetState, context))
+        {
             logger.info("Advance: Step forward");
 
             List<String> prev = getPreviousStateIds();
-            prev.add(getCurrentStateId());
+            prev.add(currentStateId);
 
             setCurrentStateId(targetState);
 
@@ -528,7 +533,9 @@
      * @return #getPreviousStateIds() + #getCurrentStateId()
      */
     public List<String> getStateHistoryIds() {
-        List<String> allIds = getPreviousStateIds();
+        ArrayList<String> prevIds = (ArrayList) getPreviousStateIds();
+        ArrayList<String> allIds  = (ArrayList) prevIds.clone();
+
         allIds.add(getCurrentStateId());
         return allIds;
     }
@@ -1238,13 +1245,15 @@
     public void endOfLife(Object context) {
         logger.info("FLYSArtifact.endOfLife: " + identifier());
 
-        List<String> ids = getPreviousStateIds();
-        ids.add(getCurrentStateId());
+        ArrayList<String> ids       = (ArrayList<String>) getPreviousStateIds();
+        ArrayList<String> toDestroy = (ArrayList<String>) ids.clone();
 
-        destroyStates(ids, context);
+        toDestroy.add(getCurrentStateId());
+
+        destroyStates(toDestroy, context);
     }
-    
-    
+
+
     /**
      * Determines Facets initial disposition regarding activity (think of
      * selection in Client ThemeList GUI). This will be checked one time
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu Mar 29 11:09:26 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Fri Mar 30 09:38:29 2012 +0000
@@ -242,69 +242,10 @@
         CallContext context,
         String      uuid)
     {
-        List<String> stateIds = getPreviousStateIds();
-
-        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
-            doc,
-            ArtifactNamespaceContext.NAMESPACE_URI,
-            ArtifactNamespaceContext.NAMESPACE_PREFIX);
-
-        FLYSContext flysContext = FLYSUtils.getFlysContext(context);
-        StateEngine engine      = (StateEngine) flysContext.get(
-            FLYSContext.STATE_ENGINE_KEY);
-
-        for (String stateId: stateIds) {
-            logger.debug("Append output modes for state: " + stateId);
-            DefaultState state = (DefaultState) engine.getState(stateId);
-
-            List<Output> list = state.getOutputs();
-            if (list == null || list.size() == 0) {
-                logger.debug("-> No output modes for this state.");
-                continue;
-            }
-
-            List<Facet> fs = facets.get(stateId);
-
-            if (fs == null || fs.size() == 0) {
-                logger.debug("No facets for previous state found.");
-                continue;
-            }
-
-            logger.debug("Found " + fs.size() + " facets in previous states.");
+        List<Output> generated = getOutputs(context);
+        logger.debug("This Artifact has " + generated.size() + " Outputs.");
 
-            List<Output> generated = generateOutputs(list, fs);
-
-            ProtocolUtils.appendOutputModes(doc, outs, generated);
-        }
-
-        try {
-            DefaultState cur = (DefaultState) getCurrentState(context);
-            if (cur.validate(this)) {
-                List<Output> list = cur.getOutputs();
-                if (list != null && list.size() > 0) {
-                    logger.debug(
-                        "Append output modes for current state: " + cur.getID());
-
-                    List<Facet> fs = facets.get(cur.getID());
-
-                    if (fs != null && fs.size() > 0) {
-                        List<Output> generated = generateOutputs(list, fs);
-
-                        logger.debug("Found " + fs.size() + " current facets.");
-                        if (!generated.isEmpty()) {
-                            ProtocolUtils.appendOutputModes(
-                                doc, outs, generated);
-                        }
-                    }
-                    else {
-                        logger.debug("No facets found for the current state.");
-                    }
-                }
-            }
-        }
-        catch (IllegalArgumentException iae) {
-            // state is not valid, so we do not append its outputs.
-        }
+        ProtocolUtils.appendOutputModes(doc, outs, generated);
     }
 
 

http://dive4elements.wald.intevation.org