Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java @ 1911:a80d33a3bcca
Added a Facet attribute for WMSLayerFacets that determines if a facet (WMS layer) is queryable via WMS GetFeatureInfo request.
flys-artifacts/trunk@3271 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 16 Nov 2011 15:28:29 +0000 |
parents | 490ab097f58c |
children | 0b466bd4ab24 |
rev | line source |
---|---|
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.collections; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
1639
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
3 import java.util.ArrayList; |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import java.util.List; |
1810
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
5 import java.util.HashMap; |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import java.util.Map; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import org.apache.log4j.Logger; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import org.w3c.dom.Document; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import org.w3c.dom.Element; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import org.w3c.dom.Node; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 |
1709
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
14 import de.intevation.artifacts.ArtifactDatabase; |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
15 import de.intevation.artifacts.ArtifactDatabaseException; |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.artifacts.ArtifactNamespaceContext; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 import de.intevation.artifactdatabase.state.Facet; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.artifactdatabase.state.Output; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.artifacts.common.utils.XMLUtils; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
1709
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
24 import de.intevation.flys.artifacts.FLYSArtifact; |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 import de.intevation.flys.artifacts.model.ManagedFacet; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
1634
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
27 /** |
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
28 * Create attribute- element of describe document of an ArtifactCollection. |
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
29 * The attribute-element contains the merged output of all outputmodes and |
1780
b503d92dd709
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1709
diff
changeset
|
30 * facets that are part of the collection. |
1634
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
31 */ |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 public class AttributeWriter { |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 |
1709
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
34 /** ArtifactDatabase used to fetch Artifacts. */ |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
35 protected ArtifactDatabase db = null; |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
36 |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 protected Map<String, Output> oldAttr; |
1709
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
38 |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 protected Map<String, Output> newAttr; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
41 /** List of already seen facets. */ |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
42 protected List<Facet> oldFacets; |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
43 |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
44 /** List of "new" facets. */ |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
45 protected List<Facet> newFacets; |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
46 |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
47 /** |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
48 * "Compatibility matrix", mapws list of facet names to output names. |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
49 * Any facet that is not found in the list for a specific output will |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
50 * not be added to the resulting document. |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
51 */ |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
52 protected Map<String, List<String>> compatibilities; |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
53 |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 private static Logger logger = Logger.getLogger(AttributeWriter.class); |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 |
1634
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
57 /** |
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
58 * Create a AttributeWriter. |
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
59 * Attributes not present in newAttr will not be included in the document. |
1709
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
60 * @param db Database to fetch artifacts. |
1634
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
61 * @param oldAttr "Old" (possibly user-changed) outputs. |
1780
b503d92dd709
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1709
diff
changeset
|
62 * @param newAttr "New" (eventually re-read in its original, unchanged |
1634
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
63 * form) outputs. |
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
64 */ |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 public AttributeWriter( |
1709
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
66 ArtifactDatabase db, |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 Map<String, Output> oldAttr, |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
68 List<Facet> oldFacets, |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
69 Map<String, Output> newAttr, |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
70 List<Facet> newFacets, |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
71 Map<String, List<String>> matrix) |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 { |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
73 this.db = db; |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
74 this.oldAttr = oldAttr; |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
75 this.newAttr = newAttr; |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
76 this.oldFacets = oldFacets; |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
77 this.newFacets = newFacets; |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
78 this.compatibilities = matrix; |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 } |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 |
1628
16c74ca3586e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1171
diff
changeset
|
82 /** |
1634
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
83 * Create document by merging outputs given in |
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
84 * constructor. |
1780
b503d92dd709
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1709
diff
changeset
|
85 * |
1634
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
86 * The "new" set rules about existance of attributes, so anything not |
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
87 * present in it will not be included in the resulting document. |
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
88 * The "old" set rules about the content of attributes (as user changes |
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
89 * are recorded here and not in the new set). |
1780
b503d92dd709
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1709
diff
changeset
|
90 * |
1634
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
91 * @return document with merged outputs as described. |
1628
16c74ca3586e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1171
diff
changeset
|
92 */ |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 protected Document write() { |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 Document doc = XMLUtils.newDocument(); |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 ElementCreator cr = new ElementCreator( |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 doc, |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 ArtifactNamespaceContext.NAMESPACE_URI, |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 |
638
9c565eb46f06
Fixed the process of creating and storing the attribute of a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
353
diff
changeset
|
101 Element attribute = cr.create("attribute"); |
705
853dceead0f4
Only generate facets when needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
694
diff
changeset
|
102 Element outs = cr.create("outputs"); |
638
9c565eb46f06
Fixed the process of creating and storing the attribute of a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
353
diff
changeset
|
103 |
9c565eb46f06
Fixed the process of creating and storing the attribute of a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
353
diff
changeset
|
104 attribute.appendChild(outs); |
9c565eb46f06
Fixed the process of creating and storing the attribute of a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
353
diff
changeset
|
105 doc.appendChild(attribute); |
353
8378683fa07a
Bugfix: The outputs of a Collection's attribute document are stored in an outputs node now instead of being stored toplevel in the document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
346
diff
changeset
|
106 |
705
853dceead0f4
Only generate facets when needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
694
diff
changeset
|
107 for (String outName: newAttr.keySet()) { |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 Output a = newAttr.get(outName); |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
109 Output b = oldAttr.get(outName); |
945
59ae2a823e73
Use the Facet.toXML() method to write facet elements into the DESCRIBE document of the Collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
705
diff
changeset
|
110 |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
111 writeOutput(doc, outs, cr, a.getName(), newFacets, oldFacets); |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
112 } |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
113 |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 return doc; |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
115 } |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 |
1634
cc47828a1390
Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1628
diff
changeset
|
117 |
1628
16c74ca3586e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1171
diff
changeset
|
118 /** |
16c74ca3586e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1171
diff
changeset
|
119 * @param doc Document to add output nodes to |
16c74ca3586e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1171
diff
changeset
|
120 * @param outs Node in Document to add output nodes to |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
121 * @param cr ElementCreator in use to modify doc/outs |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
122 * @param outputName the "new" outputs name |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
123 * @param newOutFacets Facets of the new outputs |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
124 * @param oldOutFacets Facets of the old outputs (can be null) |
1628
16c74ca3586e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1171
diff
changeset
|
125 */ |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
126 protected void writeOutput( |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
127 Document doc, |
353
8378683fa07a
Bugfix: The outputs of a Collection's attribute document are stored in an outputs node now instead of being stored toplevel in the document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
346
diff
changeset
|
128 Node outs, |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
129 ElementCreator cr, |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
130 String outputName, |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
131 List<Facet> newOutFacets, |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
132 List<Facet> oldOutFacets) |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
133 { |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
134 Element output = cr.create("output"); |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
135 cr.addAttr(output, "name", outputName); |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
136 |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
137 |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
138 List<String> compatibleFacets = this.compatibilities.get(outputName); |
1709
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
139 try { |
1831
490ab097f58c
Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1810
diff
changeset
|
140 if (writeFacets( |
490ab097f58c
Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1810
diff
changeset
|
141 doc, cr, output, newOutFacets, oldOutFacets, |
490ab097f58c
Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1810
diff
changeset
|
142 compatibleFacets)) |
490ab097f58c
Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1810
diff
changeset
|
143 { |
490ab097f58c
Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1810
diff
changeset
|
144 // Add output element only if it contains facets. |
490ab097f58c
Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1810
diff
changeset
|
145 outs.appendChild(output); |
490ab097f58c
Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1810
diff
changeset
|
146 } |
1709
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
147 } |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
148 catch (ArtifactDatabaseException ade) { |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
149 logger.error(ade, ade); |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
150 } |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
151 } |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
152 |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
153 |
1628
16c74ca3586e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1171
diff
changeset
|
154 /** |
16c74ca3586e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1171
diff
changeset
|
155 * @param doc Document to add facet nodes to |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
156 * @param cr ElementCreator to use with output/doc |
1628
16c74ca3586e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1171
diff
changeset
|
157 * @param output Node in Document to add facet nodes to |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
158 * @param newFacets the new facets |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
159 * @param oldFacets the old facets |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
160 * @param compatibleFacets List of facets to accept |
1831
490ab097f58c
Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1810
diff
changeset
|
161 * @return true if any facets are written to the out. |
1628
16c74ca3586e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1171
diff
changeset
|
162 */ |
1831
490ab097f58c
Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1810
diff
changeset
|
163 protected boolean writeFacets( |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
164 Document doc, |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
165 ElementCreator cr, |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
166 Element output, |
1635
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
167 List<Facet> newFacets, |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
168 List<Facet> oldFacets, |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
169 List<String> compatibleFacets) |
1709
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
170 throws ArtifactDatabaseException |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
171 { |
1788
d5d2bffb26ca
Avoid NPE when compatibility matrix is empty for given output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1785
diff
changeset
|
172 if (compatibleFacets == null) { |
d5d2bffb26ca
Avoid NPE when compatibility matrix is empty for given output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1785
diff
changeset
|
173 logger.warn("No compatible facets, not generating out."); |
1831
490ab097f58c
Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1810
diff
changeset
|
174 return false; |
1788
d5d2bffb26ca
Avoid NPE when compatibility matrix is empty for given output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1785
diff
changeset
|
175 } |
d5d2bffb26ca
Avoid NPE when compatibility matrix is empty for given output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1785
diff
changeset
|
176 |
1635
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
177 int num = newFacets.size(); |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
178 |
1635
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
179 // Add all new Facets either in their old state or (if really |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
180 // new) as they are. |
1639
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
181 List<ManagedFacet> currentFacets = new ArrayList<ManagedFacet>(); |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
182 List<ManagedFacet> genuinelyNewFacets = new ArrayList<ManagedFacet>(); |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
183 |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
184 for (int i = 0; i < num; i++) { |
1635
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
185 ManagedFacet facet = (ManagedFacet) newFacets.get(i); |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
186 if (!compatibleFacets.contains(facet.getName())) { |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
187 //logger.debug("Have incompatible facet, skip: " + facet.getName()); |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
188 continue; |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
189 } |
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
190 //else logger.debug("Have compatible facet: " + facet.getName()); |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
191 |
1635
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
192 ManagedFacet picked = pickFacet(facet, oldFacets); |
1785
661dfad9910a
Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1780
diff
changeset
|
193 |
1639
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
194 if (facet.equals(picked)) { |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
195 genuinelyNewFacets.add(picked); |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
196 } |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
197 else { |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
198 currentFacets.add(picked); |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
199 } |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
200 } |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
201 |
1709
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
202 // With each genuinely new Facet, ask Artifact whether it comes to live |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
203 // in/activate. |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
204 for (ManagedFacet newMF: genuinelyNewFacets) { |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
205 FLYSArtifact flys = (FLYSArtifact) db.getRawArtifact(newMF.getArtifact()); |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
206 newMF.setActive(flys.getInitialFacetActivity( |
1810
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
207 output.getAttribute("name"), |
1709
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
208 newMF.getName(), |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
209 newMF.getIndex())); |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
210 } |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
211 |
1639
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
212 // For each genuinely new Facet check positional conflicts. |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
213 for (ManagedFacet newMF: genuinelyNewFacets) { |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
214 boolean conflicts = true; |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
215 // Loop until all conflicts resolved. |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
216 while (conflicts) { |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
217 conflicts = false; |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
218 for (ManagedFacet oldMF: currentFacets) { |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
219 if (newMF.getPosition() == oldMF.getPosition()) { |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
220 conflicts = true; |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
221 logger.debug("Positional conflict while merging " + |
1780
b503d92dd709
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1709
diff
changeset
|
222 "facets, pushing newest facet 1 up (" + newMF.getPosition() + ")"); |
1639
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
223 newMF.setPosition(newMF.getPosition() + 1); |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
224 break; |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
225 } |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
226 } |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
227 } |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
228 currentFacets.add(newMF); |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
229 } |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
230 |
1810
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
231 // Fill/correct "gaps" (e.g. position 1,2,5 are taken, after gap filling |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
232 // expect positions 1,2,3 [5->3]) |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
233 // Preparations to be able to detect gaps. |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
234 Map<Integer, ManagedFacet> mfmap = new HashMap<Integer, ManagedFacet>(); |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
235 int max = 0; |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
236 for (ManagedFacet mf: currentFacets) { |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
237 int pos = mf.getPosition(); |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
238 mfmap.put(Integer.valueOf(pos), mf); |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
239 if (pos > max) max = pos; |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
240 } |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
241 |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
242 // Finally do gap correction. |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
243 if (max != currentFacets.size()) { |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
244 int gap = 0; |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
245 for (int i = 1; i <= max; i++) { |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
246 ManagedFacet mf = mfmap.get(Integer.valueOf(i)); |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
247 if (mf == null) { |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
248 gap++; |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
249 continue; |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
250 } |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
251 mf.setPosition(mf.getPosition() - gap); |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
252 } |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
253 } |
193a916d1ab5
Pass output name to artifacts getInitialFacetActivity, prevent gaps in collection attributes outputs facets positions.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1788
diff
changeset
|
254 |
1639
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
255 // Now add all facets. |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
256 for (ManagedFacet oldMF: currentFacets) { |
12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1635
diff
changeset
|
257 Node node = oldMF.toXML(doc); |
1635
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
258 if (node != null) { |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
259 output.appendChild(node); |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
260 } |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
261 } |
1831
490ab097f58c
Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1810
diff
changeset
|
262 |
490ab097f58c
Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1810
diff
changeset
|
263 return currentFacets.size() > 0; |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
264 } |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
265 |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
266 |
1628
16c74ca3586e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1171
diff
changeset
|
267 /** |
1635
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
268 * Returns the facet to be added to Document. |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
269 * Return the new facet only if the "same" facet was not present before. |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
270 * Return the "old" facet otherwise (user-defined information sticks |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
271 * to it). |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
272 * @param facet the new facet. |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
273 * @param oldFacets the old facets, new facet is compared against each of |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
274 * these. |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
275 * @return facet if genuinely new, matching old facet otherwise. |
1628
16c74ca3586e
Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1171
diff
changeset
|
276 */ |
1635
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
277 protected ManagedFacet pickFacet(ManagedFacet facet, |
1709
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
278 List<Facet> oldFacets) |
f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1639
diff
changeset
|
279 { |
1635
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
280 if (oldFacets == null) { |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
281 logger.debug("No old facets to compare a new to found."); |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
282 return facet; |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
283 } |
1635
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
284 |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
285 String hash = facet.getName() + facet.getIndex() + facet.getArtifact(); |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
286 |
1635
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
287 // Compare "new" facet with all old facets. |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
288 // Take oldFacet if that facet was already present (otherwise |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
289 // information is lost, the new one otherwise. |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
290 for (Facet oFacet: oldFacets) { |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
291 ManagedFacet oldFacet = (ManagedFacet) oFacet; |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
292 String oldHash = oldFacet.getName() |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
293 + oldFacet.getIndex() |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
294 + oldFacet.getArtifact(); |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
295 if (hash.equals(oldHash)) { |
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
296 return oldFacet; |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
297 } |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
298 } |
1635
1b5204203e18
Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1634
diff
changeset
|
299 return facet; |
346
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
300 } |
16161de47662
The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
301 } |
705
853dceead0f4
Only generate facets when needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
694
diff
changeset
|
302 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |