diff flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java @ 3556:afc7bfb4800b

Use the new infrastructure to figure out if a facet should be initially active or not. flys-artifacts/trunk@5152 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 29 Jul 2012 11:04:06 +0000
parents 22732713c54d
children c3cd414982fe
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Sat Jul 28 21:48:15 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Sun Jul 29 11:04:06 2012 +0000
@@ -11,6 +11,7 @@
 import de.intevation.artifacts.ArtifactDatabaseException;
 
 import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.artifactdatabase.state.FacetActivity;
 import de.intevation.artifactdatabase.state.Output;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
@@ -90,11 +91,13 @@
      * @return document with merged outputs as described.
      */
     protected CollectionAttribute write() {
+
+        boolean debug = logger.isDebugEnabled();
+
         for (Map.Entry<String, Output> entry: newAttr.entrySet()) {
             String outName = entry.getKey();
             Output a       = entry.getValue();
 
-
             Output exists = attribute.getOutput(outName);
             if (exists == null) {
                 attribute.addOutput(outName, a);
@@ -102,7 +105,7 @@
 
             attribute.clearFacets(outName);
 
-            if (logger.isDebugEnabled()) {
+            if (debug) {
                 logger.debug("Merge Output: " + outName);
                 logger.debug("   old Facets: " + oldFacets.size());
                 logger.debug("   new Facets: " + newFacets.size());
@@ -153,10 +156,10 @@
      * @return true if any facets are written to the out.
      */
     protected boolean writeFacets(
-        String         outputName,
-        List<Facet>    newFacets,
-        List<Facet>    oldFacets,
-        List<String>   compatibleFacets)
+        String        outputName,
+        List<Facet>   newFacets,
+        List<Facet>   oldFacets,
+        List<String>  compatibleFacets)
     throws ArtifactDatabaseException
     {
         if (compatibleFacets == null) {
@@ -171,10 +174,14 @@
         List<ManagedFacet> currentFacets      = new ArrayList<ManagedFacet>();
         List<ManagedFacet> genuinelyNewFacets = new ArrayList<ManagedFacet>();
 
+        boolean debug = logger.isDebugEnabled();
+
         for (int i = 0; i < num; i++) {
             ManagedFacet facet = (ManagedFacet) newFacets.get(i);
 
-            logger.debug("Try to add Facet: " + facet.getName());
+            if (debug) {
+                logger.debug("Try to add Facet: " + facet.getName());
+            }
 
             if (!compatibleFacets.contains(facet.getName())) {
                 //logger.debug("Have incompatible facet, skip: " + facet.getName());
@@ -192,14 +199,20 @@
             }
         }
 
-        // With each genuinely new Facet, ask Artifact whether it comes to live
+        FacetActivity.Registry registry = FacetActivity.Registry.getInstance();
+
+        // With each genuinely new Facet, figure out whether it comes to live
         // in/activate.
         for (ManagedFacet newMF: genuinelyNewFacets) {
-            FLYSArtifact flys = (FLYSArtifact) db.getRawArtifact(newMF.getArtifact());
-            newMF.setActive(flys.getInitialFacetActivity(
-                outputName,
-                newMF.getName(),
-                newMF.getIndex()));
+            FLYSArtifact flys =
+                (FLYSArtifact)db.getRawArtifact(newMF.getArtifact());
+
+            FacetActivity activity = registry.getActivity(flys.getName());
+
+            boolean isActive = activity.isInitialActive(
+                flys, newMF, outputName);
+
+            newMF.setActive(isActive ? 1 : 0);
         }
 
         // For each genuinely new Facet check positional conflicts.
@@ -211,8 +224,12 @@
                 for (ManagedFacet oldMF: currentFacets) {
                     if (newMF.getPosition() == oldMF.getPosition()) {
                         conflicts = true;
-                        logger.debug("Positional conflict while merging " +
-                            "facets, pushing newest facet 1 up (" + newMF.getPosition() + ")");
+                        if (debug) {
+                            logger.debug(
+                                "Positional conflict while merging " +
+                                "facets, pushing newest facet 1 up (" +
+                                newMF.getPosition() + ")");
+                        }
                         newMF.setPosition(newMF.getPosition() + 1);
                         break;
                     }
@@ -224,7 +241,8 @@
         // 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>();
+        Map<Integer, ManagedFacet> mfmap =
+            new HashMap<Integer, ManagedFacet>();
         int max = 0;
         for (ManagedFacet mf: currentFacets) {
             int pos = mf.getPosition();
@@ -250,7 +268,7 @@
             attribute.addFacet(outputName, oldMF);
         }
 
-        return currentFacets.size() > 0;
+        return !currentFacets.isEmpty();
     }
 
 

http://dive4elements.wald.intevation.org