# HG changeset patch # User Felix Wolfsteller # Date 1317043075 0 # Node ID 12235a2ace21e55f3fcfbd3fe66c40193cc8325a # Parent f45bbc80bd3d02bc232c03b1646bafb99669ba9a Add positional-conflict-awareness when merging Facets in attribute of a collection. Apply "first come first serve"-rule. flys-artifacts/trunk@2824 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r f45bbc80bd3d -r 12235a2ace21 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon Sep 26 13:10:40 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon Sep 26 13:17:55 2011 +0000 @@ -1,3 +1,14 @@ +2011-09-26 Felix Wolfsteller + + Add positional-conflict-awareness when merging Facets for a + FLYSArtifactCollection. First come first serve. + + * src/main/java/de/intevation/flys/collections/AttributeWriter.java: + (writeFacets): First, sort incoming facets into 2 groups: + "genuinely new" and "already there", then for each new check + whether the position is already taken. If so, push "up" (position++) + until no conflict exists anymore. + 2011-09-26 Ingo Weinzierl flys/issue296 (Karte: Bezeichnungen verbessern) @@ -11,7 +22,7 @@ src/main/resources/messages_de.properties: Added strings for the wsplgen and barriers WMS layers. -2011-09-23 Felix Wolfsteller +2011-09-26 Felix Wolfsteller Fix (revert) access to position in ManagedDomFacet. diff -r f45bbc80bd3d -r 12235a2ace21 flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java --- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java Mon Sep 26 13:10:40 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java Mon Sep 26 13:17:55 2011 +0000 @@ -1,5 +1,6 @@ package de.intevation.flys.collections; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -129,11 +130,42 @@ // Add all new Facets either in their old state or (if really // new) as they are. + List currentFacets = new ArrayList(); + List genuinelyNewFacets = new ArrayList(); for (int i = 0; i < num; i++) { ManagedFacet facet = (ManagedFacet) newFacets.get(i); ManagedFacet picked = pickFacet(facet, oldFacets); - Node node = picked.toXML(doc); + if (facet.equals(picked)) { + genuinelyNewFacets.add(picked); + } + else { + currentFacets.add(picked); + } + } + + // For each genuinely new Facet check positional conflicts. + for (ManagedFacet newMF: genuinelyNewFacets) { + boolean conflicts = true; + // Loop until all conflicts resolved. + while (conflicts) { + conflicts = false; + 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()+")"); + newMF.setPosition(newMF.getPosition() + 1); + break; + } + } + } + currentFacets.add(newMF); + } + + // Now add all facets. + for (ManagedFacet oldMF: currentFacets) { + Node node = oldMF.toXML(doc); if (node != null) { output.appendChild(node); }