changeset 693:af393c5eb2c8 facets-slt

Write computed facets into artifacts describe document. flys-artifacts/branches/facets-slt@2133 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 16 Jun 2011 13:24:00 +0000
parents 22e4bffbe240
children 68c6c75a6f7c
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java
diffstat 4 files changed, 72 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu Jun 16 10:05:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu Jun 16 13:24:00 2011 +0000
@@ -246,6 +246,9 @@
 
             setCurrentStateId(targetState);
 
+            logger.debug("Compute data for state: " + targetState);
+            compute(context, ComputeType.ADVANCE);
+
             return describe(target, context);
         }
         else if (isPreviousState(targetState, context)) {
@@ -264,8 +267,6 @@
 
             setCurrentStateId(targetState);
 
-            compute(context, ComputeType.ADVANCE);
-
             return describe(target, context);
         }
 
@@ -1071,9 +1072,9 @@
      * @return the computed data.
      */
     public Object compute(CallContext context, String hash, ComputeType type) {
-        String calc = (String) getData(CalculationSelect.FIELD_MODE).getValue();
+        DefaultState current = (DefaultState) getCurrentState(context);
 
-        DefaultState current = (DefaultState) getCurrentState(context);
+        logger.debug("Create ComputeCallback for state: " + current.getID());
 
         ComputeCallback callback = current.createComputeCallback(hash(), this);
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu Jun 16 10:05:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu Jun 16 13:24:00 2011 +0000
@@ -1,7 +1,10 @@
 package de.intevation.flys.artifacts;
 
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -13,6 +16,8 @@
 import de.intevation.artifacts.CallContext;
 
 import de.intevation.artifactdatabase.ProtocolUtils;
+import de.intevation.artifactdatabase.state.DefaultOutput;
+import de.intevation.artifactdatabase.state.Facet;
 import de.intevation.artifactdatabase.state.Output;
 import de.intevation.artifactdatabase.state.State;
 import de.intevation.artifactdatabase.state.StateEngine;
@@ -180,7 +185,7 @@
 
         for (String stateId: stateIds) {
             logger.debug("Append output modes for state: " + stateId);
-            State state = engine.getState(stateId);
+            DefaultState state = (DefaultState) engine.getState(stateId);
 
             List<Output> list = state.getOutputs();
             if (list == null || list.size() == 0) {
@@ -188,7 +193,17 @@
                 continue;
             }
 
-            ProtocolUtils.appendOutputModes(creator, outs, list);
+            List<Facet>  fs = facets.get(stateId);
+            if (fs == null || fs.size() == 0) {
+                logger.debug("No facets found.");
+                continue;
+            }
+
+            logger.debug("Found " + fs.size() + " facets.");
+
+            List<Output> generated = generateOutputs(list, fs);
+
+            ProtocolUtils.appendOutputModes(creator, outs, generated);
         }
 
         try {
@@ -199,7 +214,19 @@
                     logger.debug(
                         "Append output modes for state: " + cur.getID());
 
-                    ProtocolUtils.appendOutputModes(creator, outs, list);
+                    List<Facet>  fs = facets.get(cur.getID());
+                    if (fs != null && fs.size() > 0) {
+                        List<Output> generated = generateOutputs(list, fs);
+
+                        logger.debug("Found " + fs.size() + " facets.");
+
+                        ProtocolUtils.appendOutputModes(
+                            creator, outs, generated);
+                    }
+                    else {
+                        logger.debug("No facets found for the current state.");
+                    }
+
                 }
             }
         }
@@ -209,6 +236,36 @@
     }
 
 
+    protected List<Output> generateOutputs(List<Output> list, List<Facet> fs) {
+        List<Output> generated = new ArrayList<Output>();
+
+        for (Output out: list) {
+            Output o = new DefaultOutput(
+                out.getName(),
+                out.getDescription(),
+                out.getMimeType());
+
+            Set<String> outtype = new HashSet<String>();
+
+            for (Facet f: out.getFacets()) {
+                outtype.add(f.getName());
+            }
+
+            for (Facet f: fs) {
+                String type = f.getName();
+
+                if(outtype.contains(type)) {
+                    o.addFacet(f);
+                }
+            }
+
+            generated.add(o);
+        }
+
+        return generated;
+    }
+
+
     /**
      * This method appends the static data - that has already been inserted by
      * the user - to the static node of the DESCRIBE document.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Thu Jun 16 10:05:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Thu Jun 16 13:24:00 2011 +0000
@@ -6,8 +6,8 @@
     String DISCHARGE_LONGITUDINAL_Q = "discharge_longitudinal_section.q";
     String DISCHARGE_LONGITUDINAL_C = "discharge_longitudinal_section.c";
 
-    String LONGITUDINAL_W = "facet.longitudinal_section.w";
-    String LONGITUDINAL_Q = "facet.longitudinal_section.q";
+    String LONGITUDINAL_W = "longitudinal_section.w";
+    String LONGITUDINAL_Q = "longitudinal_section.q";
 
     String COMPUTED_DISCHARGE_Q = "computed_discharge_curve.q";
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Thu Jun 16 10:05:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Thu Jun 16 13:24:00 2011 +0000
@@ -45,6 +45,8 @@
     public ComputeCallback createComputeCallback(
         String hash, FLYSArtifact flys)
     {
+        logger.debug("Create waterlevel ComputeCallback.");
+
         final WINFOArtifact winfo = (WINFOArtifact) flys;
 
         return new ComputeCallbackAdapter() {
@@ -74,6 +76,9 @@
                         nameQ = "Q(" + nameQ + ")";
                     }
 
+                    logger.debug("Create facet: " + nameW);
+                    logger.debug("Create facet: " + nameQ);
+
                     Facet w = new DefaultFacet(i, LONGITUDINAL_W, nameW);
                     Facet q = new DefaultFacet(i, LONGITUDINAL_Q, nameQ);
 

http://dive4elements.wald.intevation.org