diff flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java @ 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 d5d2bffb26ca
children 490ab097f58c
line wrap: on
line diff
--- 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