changeset 1810:193a916d1ab5

Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions. flys-artifacts/trunk@3139 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 02 Nov 2011 11:27:04 +0000
parents f6a190f6aaff
children 4ee833095e75
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java
diffstat 2 files changed, 37 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Nov 02 11:21:57 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Nov 02 11:27:04 2011 +0000
@@ -1,3 +1,14 @@
+2011-11-02	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	1) Pass outputs name to artifacts getInitialFacetActivity().
+	2) Do not allow "gaps" in positions of facets in outputs in attributes
+	   of collection (prevent e.g. positions 1,3,5; will become 1,2,3
+	   instead).
+
+	* src/main/java/de/intevation/flys/collections/AttributeWriter.java:
+	  Pass outputname to artifacts getInitialFacetActivity(), prevent
+	  gaps in facets positions in outputs (1,3,10 become 1,2,3).
+
 2011-11-02	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	1) Give Artifacts information about the out when they have to decide
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Wed Nov 02 11:21:57 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Wed Nov 02 11:27:04 2011 +0000
@@ -2,6 +2,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.log4j.Logger;
@@ -162,7 +163,6 @@
         List<String>   compatibleFacets)
     throws ArtifactDatabaseException
     {
-
         if (compatibleFacets == null) {
             logger.warn("No compatible facets, not generating out.");
             return;
@@ -198,6 +198,7 @@
         for (ManagedFacet newMF: genuinelyNewFacets) {
             FLYSArtifact flys = (FLYSArtifact) db.getRawArtifact(newMF.getArtifact());
             newMF.setActive(flys.getInitialFacetActivity(
+                output.getAttribute("name"),
                 newMF.getName(),
                 newMF.getIndex()));
         }
@@ -221,6 +222,30 @@
             currentFacets.add(newMF);
         }
 
+        // Fill/correct "gaps" (e.g. position 1,2,5 are taken, after gap filling
+        // expect positions 1,2,3 [5->3])
+        // Preparations to be able to detect gaps.
+        Map<Integer, ManagedFacet> mfmap = new HashMap<Integer, ManagedFacet>();
+        int max = 0;
+        for (ManagedFacet mf: currentFacets) {
+            int pos = mf.getPosition();
+            mfmap.put(Integer.valueOf(pos), mf);
+            if (pos > max) max = pos;
+        }
+
+        // Finally do gap correction.
+        if (max != currentFacets.size()) {
+            int gap = 0;
+            for (int i = 1; i <= max; i++) {
+                ManagedFacet mf = mfmap.get(Integer.valueOf(i));
+                if (mf == null) {
+                    gap++;
+                    continue;
+                }
+                mf.setPosition(mf.getPosition() - gap);
+            }
+        }
+
         // Now add all facets.
         for (ManagedFacet oldMF: currentFacets) {
             Node node = oldMF.toXML(doc);

http://dive4elements.wald.intevation.org