annotate flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java @ 4560:661102336f16

Add css for the project list changes
author Björn Ricks <bjoern.ricks@intevation.de>
date Fri, 16 Nov 2012 14:26:25 +0100
parents b74399bd0960
children 725de57d3774
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
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
10 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
11 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
12
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import de.intevation.artifactdatabase.state.Facet;
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
14 import de.intevation.artifactdatabase.state.FacetActivity;
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 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
16
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
17 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
18 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
19
1634
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
20 /**
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
21 * Create attribute- element of describe document of an ArtifactCollection.
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
22 * 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
23 * facets that are part of the collection.
1634
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
24 */
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 public class AttributeWriter {
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
27 /** 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
28 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
29
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 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
31
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 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
33
1785
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
34 /** List of already seen facets. */
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
35 protected List<Facet> oldFacets;
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
36
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
37 /** List of "new" facets. */
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
38 protected List<Facet> newFacets;
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
39
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
40 /**
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
41 * "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
42 * 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
43 * 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
44 */
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
45 protected Map<String, List<String>> compatibilities;
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
46
1976
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
47
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
48 /** The result of the <i>write()</i> operation.*/
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
49 protected CollectionAttribute attribute;
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
50
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
51
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 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
53
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54
1634
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
55 /**
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
56 * Create a AttributeWriter.
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
57 * 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
58 * @param db Database to fetch artifacts.
1634
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
59 * @param oldAttr "Old" (possibly user-changed) outputs.
1780
b503d92dd709 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1709
diff changeset
60 * @param newAttr "New" (eventually re-read in its original, unchanged
1634
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
61 * form) outputs.
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
62 */
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 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
64 ArtifactDatabase db,
1993
85132c9edd64 Make reuse of the old CollectionAttribute during the describe() operation of FLYSArtifactCollection - remove the old facets only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1984
diff changeset
65 CollectionAttribute attribute,
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 Map<String, Output> oldAttr,
1785
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
67 List<Facet> oldFacets,
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
68 Map<String, Output> newAttr,
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
69 List<Facet> newFacets,
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
70 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
71 {
1785
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
72 this.db = db;
1993
85132c9edd64 Make reuse of the old CollectionAttribute during the describe() operation of FLYSArtifactCollection - remove the old facets only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1984
diff changeset
73 this.attribute = attribute;
1785
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 */
1976
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
93 protected CollectionAttribute write() {
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
94
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
95 boolean debug = logger.isDebugEnabled();
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
96
1995
f114c0d55d19 Little optimisation when writing CollectionAttributes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1993
diff changeset
97 for (Map.Entry<String, Output> entry: newAttr.entrySet()) {
f114c0d55d19 Little optimisation when writing CollectionAttributes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1993
diff changeset
98 String outName = entry.getKey();
f114c0d55d19 Little optimisation when writing CollectionAttributes
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1993
diff changeset
99 Output a = entry.getValue();
1996
c6432e8ea31e Bugfix: add new Outputs during merge process in AttributeWriter.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1995
diff changeset
100
c6432e8ea31e Bugfix: add new Outputs during merge process in AttributeWriter.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1995
diff changeset
101 Output exists = attribute.getOutput(outName);
c6432e8ea31e Bugfix: add new Outputs during merge process in AttributeWriter.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1995
diff changeset
102 if (exists == null) {
c6432e8ea31e Bugfix: add new Outputs during merge process in AttributeWriter.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1995
diff changeset
103 attribute.addOutput(outName, a);
c6432e8ea31e Bugfix: add new Outputs during merge process in AttributeWriter.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1995
diff changeset
104 }
c6432e8ea31e Bugfix: add new Outputs during merge process in AttributeWriter.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1995
diff changeset
105
1993
85132c9edd64 Make reuse of the old CollectionAttribute during the describe() operation of FLYSArtifactCollection - remove the old facets only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1984
diff changeset
106 attribute.clearFacets(outName);
2094
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
107
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
108 if (debug) {
2094
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
109 logger.debug("Merge Output: " + outName);
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
110 logger.debug(" old Facets: " + oldFacets.size());
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
111 logger.debug(" new Facets: " + newFacets.size());
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
112 }
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
113
1976
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
114 writeOutput(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
115 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116
2079
ca6ccf722c24 #447 removed empty Outputs from Collection's attribute.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1996
diff changeset
117 // THIS CALL IS ABSOLUTELY NECESSARY!
ca6ccf722c24 #447 removed empty Outputs from Collection's attribute.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1996
diff changeset
118 attribute.cleanEmptyOutputs();
ca6ccf722c24 #447 removed empty Outputs from Collection's attribute.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1996
diff changeset
119
1976
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
120 return attribute;
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122
1634
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
123
1628
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
124 /**
1785
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
125 * @param outputName the "new" outputs name
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
126 * @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
127 * @param oldOutFacets Facets of the old outputs (can be null)
1628
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
128 */
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 protected void writeOutput(
1976
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
130 String outputName,
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
131 List<Facet> newOutFacets,
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
132 List<Facet> oldOutFacets
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
133 ) {
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
134 List<String> compatFacets = this.compatibilities.get(outputName);
2094
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
135
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
136 if (logger.isDebugEnabled() && compatFacets != null) {
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
137 logger.debug("Compabitle Facets:");
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
138 for (String compatible: compatFacets) {
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
139 logger.debug( "- " + compatible);
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
140 }
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
141 }
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
142
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
143 try {
1976
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
144 writeFacets(outputName, newOutFacets, oldOutFacets, compatFacets);
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
145 }
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
146 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
147 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
148 }
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151
1628
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
152 /**
1785
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
153 * @param newFacets the new facets
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
154 * @param oldFacets the old facets
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
155 * @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
156 * @return true if any facets are written to the out.
1628
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
157 */
1831
490ab097f58c Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1810
diff changeset
158 protected boolean writeFacets(
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
159 String outputName,
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
160 List<Facet> newFacets,
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
161 List<Facet> oldFacets,
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
162 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
163 throws ArtifactDatabaseException
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 {
1788
d5d2bffb26ca Avoid NPE when compatibility matrix is empty for given output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1785
diff changeset
165 if (compatibleFacets == null) {
d5d2bffb26ca Avoid NPE when compatibility matrix is empty for given output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1785
diff changeset
166 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
167 return false;
1788
d5d2bffb26ca Avoid NPE when compatibility matrix is empty for given output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1785
diff changeset
168 }
d5d2bffb26ca Avoid NPE when compatibility matrix is empty for given output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1785
diff changeset
169
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
170 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
171
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
172 // 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
173 // 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
174 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
175 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
176
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
177 boolean debug = logger.isDebugEnabled();
4499
b74399bd0960 Improve debugging while merging outs and facets
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4433
diff changeset
178 if (debug) {
b74399bd0960 Improve debugging while merging outs and facets
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4433
diff changeset
179 logger.debug("Compatible facets are " + compatibleFacets);
b74399bd0960 Improve debugging while merging outs and facets
Björn Ricks <bjoern.ricks@intevation.de>
parents: 4433
diff changeset
180 }
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
181
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 for (int i = 0; i < num; i++) {
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
183 ManagedFacet facet = (ManagedFacet) newFacets.get(i);
2094
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
184
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
185 if (debug) {
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
186 logger.debug("Try to add Facet: " + facet.getName());
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
187 }
2094
22732713c54d Made classes to merge Collection Outs more verbose for better debugging.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2079
diff changeset
188
1785
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
189 if (!compatibleFacets.contains(facet.getName())) {
4025
721d55bdab9e Add warning if no compatible facet is found
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3558
diff changeset
190 logger.warn("Have incompatible facet, skip: " + facet.getName());
1785
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
191 continue;
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
192 }
4025
721d55bdab9e Add warning if no compatible facet is found
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3558
diff changeset
193 else {
721d55bdab9e Add warning if no compatible facet is found
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3558
diff changeset
194 logger.debug("Have compatible facet: " + facet.getName());
721d55bdab9e Add warning if no compatible facet is found
Björn Ricks <bjoern.ricks@intevation.de>
parents: 3558
diff changeset
195 }
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
197 ManagedFacet picked = pickFacet(facet, oldFacets);
1785
661dfad9910a Use compatibility matrix when creating collections output.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
198
1639
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
199 if (facet.equals(picked)) {
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
200 genuinelyNewFacets.add(picked);
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
201 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
202 else {
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
203 currentFacets.add(picked);
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
204 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
205 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
206
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
207 FacetActivity.Registry registry = FacetActivity.Registry.getInstance();
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
208
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
209 // With each genuinely new Facet, figure out whether it comes to live
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
210 // in/activate.
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
211 for (ManagedFacet newMF: genuinelyNewFacets) {
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
212 FLYSArtifact flys =
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
213 (FLYSArtifact)db.getRawArtifact(newMF.getArtifact());
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
214
3558
c3cd414982fe Adjusted to follow the Chain-of-responsibility pattern in figuring out facet activities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3556
diff changeset
215 boolean isActive = registry.isInitialActive(
c3cd414982fe Adjusted to follow the Chain-of-responsibility pattern in figuring out facet activities.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3556
diff changeset
216 flys.getName(), flys, newMF, outputName);
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
217
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
218 newMF.setActive(isActive ? 1 : 0);
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
219 }
1976
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
220
1639
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
221 // 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
222 for (ManagedFacet newMF: genuinelyNewFacets) {
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
223 boolean conflicts = true;
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
224 // 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
225 while (conflicts) {
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
226 conflicts = false;
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
227 for (ManagedFacet oldMF: currentFacets) {
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
228 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
229 conflicts = true;
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
230 if (debug) {
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
231 logger.debug(
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
232 "Positional conflict while merging " +
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
233 "facets, pushing newest facet 1 up (" +
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
234 newMF.getPosition() + ")");
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
235 }
1639
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
236 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
237 break;
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
238 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
239 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
240 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
241 currentFacets.add(newMF);
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
242 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
243
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
244 // 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
245 // 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
246 // Preparations to be able to detect gaps.
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
247 Map<Integer, ManagedFacet> mfmap =
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
248 new HashMap<Integer, ManagedFacet>();
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
249 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
250 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
251 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
252 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
253 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
254 }
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
255
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
256 // 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
257 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
258 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
259 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
260 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
261 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
262 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
263 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
264 }
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
265 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
266 }
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
267 }
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
268
1639
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
269 // Now add all facets.
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
270 for (ManagedFacet oldMF: currentFacets) {
1976
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
271 attribute.addFacet(outputName, oldMF);
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
272 }
1831
490ab097f58c Prevent empty output-nodes in flyscollections attributes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1810
diff changeset
273
3556
afc7bfb4800b Use the new infrastructure to figure out if a facet should
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2094
diff changeset
274 return !currentFacets.isEmpty();
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
275 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
276
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
277
1628
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
278 /**
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
279 * Returns the facet to be added to Document.
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
280 * 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
281 * Return the "old" facet otherwise (user-defined information sticks
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
282 * to it).
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
283 * @param facet the new facet.
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
284 * @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
285 * these.
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
286 * @return facet if genuinely new, matching old facet otherwise.
1628
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
287 */
1976
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
288 protected ManagedFacet pickFacet(ManagedFacet facet, List<Facet> oldFacets)
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
289 {
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
290 if (oldFacets == null) {
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
291 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
292 return facet;
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
293 }
1976
0b466bd4ab24 Introduced a CollectionAttribute class that stores the information provided by the Collection's attribute document.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1831
diff changeset
294
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
295 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
296
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
297 // Compare "new" facet with all old facets.
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
298 // Take oldFacet if that facet was already present (otherwise
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
299 // information is lost, the new one otherwise.
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
300 for (Facet oFacet: oldFacets) {
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
301 ManagedFacet oldFacet = (ManagedFacet) oFacet;
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
302 String oldHash = oldFacet.getName()
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
303 + oldFacet.getIndex()
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
304 + oldFacet.getArtifact();
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
305 if (hash.equals(oldHash)) {
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
306 return oldFacet;
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
307 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
308 }
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
309 return facet;
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
310 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
311 }
705
853dceead0f4 Only generate facets when needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 694
diff changeset
312 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org