comparison 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
comparison
equal deleted inserted replaced
1809:f6a190f6aaff 1810:193a916d1ab5
1 package de.intevation.flys.collections; 1 package de.intevation.flys.collections;
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.List; 4 import java.util.List;
5 import java.util.HashMap;
5 import java.util.Map; 6 import java.util.Map;
6 7
7 import org.apache.log4j.Logger; 8 import org.apache.log4j.Logger;
8 9
9 import org.w3c.dom.Document; 10 import org.w3c.dom.Document;
160 List<Facet> newFacets, 161 List<Facet> newFacets,
161 List<Facet> oldFacets, 162 List<Facet> oldFacets,
162 List<String> compatibleFacets) 163 List<String> compatibleFacets)
163 throws ArtifactDatabaseException 164 throws ArtifactDatabaseException
164 { 165 {
165
166 if (compatibleFacets == null) { 166 if (compatibleFacets == null) {
167 logger.warn("No compatible facets, not generating out."); 167 logger.warn("No compatible facets, not generating out.");
168 return; 168 return;
169 } 169 }
170 170
196 // With each genuinely new Facet, ask Artifact whether it comes to live 196 // With each genuinely new Facet, ask Artifact whether it comes to live
197 // in/activate. 197 // in/activate.
198 for (ManagedFacet newMF: genuinelyNewFacets) { 198 for (ManagedFacet newMF: genuinelyNewFacets) {
199 FLYSArtifact flys = (FLYSArtifact) db.getRawArtifact(newMF.getArtifact()); 199 FLYSArtifact flys = (FLYSArtifact) db.getRawArtifact(newMF.getArtifact());
200 newMF.setActive(flys.getInitialFacetActivity( 200 newMF.setActive(flys.getInitialFacetActivity(
201 output.getAttribute("name"),
201 newMF.getName(), 202 newMF.getName(),
202 newMF.getIndex())); 203 newMF.getIndex()));
203 } 204 }
204 205
205 // For each genuinely new Facet check positional conflicts. 206 // For each genuinely new Facet check positional conflicts.
219 } 220 }
220 } 221 }
221 currentFacets.add(newMF); 222 currentFacets.add(newMF);
222 } 223 }
223 224
225 // Fill/correct "gaps" (e.g. position 1,2,5 are taken, after gap filling
226 // expect positions 1,2,3 [5->3])
227 // Preparations to be able to detect gaps.
228 Map<Integer, ManagedFacet> mfmap = new HashMap<Integer, ManagedFacet>();
229 int max = 0;
230 for (ManagedFacet mf: currentFacets) {
231 int pos = mf.getPosition();
232 mfmap.put(Integer.valueOf(pos), mf);
233 if (pos > max) max = pos;
234 }
235
236 // Finally do gap correction.
237 if (max != currentFacets.size()) {
238 int gap = 0;
239 for (int i = 1; i <= max; i++) {
240 ManagedFacet mf = mfmap.get(Integer.valueOf(i));
241 if (mf == null) {
242 gap++;
243 continue;
244 }
245 mf.setPosition(mf.getPosition() - gap);
246 }
247 }
248
224 // Now add all facets. 249 // Now add all facets.
225 for (ManagedFacet oldMF: currentFacets) { 250 for (ManagedFacet oldMF: currentFacets) {
226 Node node = oldMF.toXML(doc); 251 Node node = oldMF.toXML(doc);
227 if (node != null) { 252 if (node != null) {
228 output.appendChild(node); 253 output.appendChild(node);

http://dive4elements.wald.intevation.org