annotate flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java @ 1709:f643ea084213

Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering). flys-artifacts/trunk@2969 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 14 Oct 2011 08:52:44 +0000
parents 12235a2ace21
children b503d92dd709
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;
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 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
6
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 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
8
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 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
10 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
11 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
12
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
13 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
14 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
15 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
16
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 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
18 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
19
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 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
21 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
22
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
23 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
24 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
25
1634
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
26 /**
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
27 * Create attribute- element of describe document of an ArtifactCollection.
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
28 * The attribute-element contains the merged output of all outputmodes and
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
29 * facets that are part of the collection.
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
30 */
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 public class AttributeWriter {
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
33 /** 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
34 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
35
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 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
37
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 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
39
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 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
41
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
1634
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
43 /**
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
44 * Create a AttributeWriter.
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
45 * 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
46 * @param db Database to fetch artifacts.
1634
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
47 * @param oldAttr "Old" (possibly user-changed) outputs.
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
48 * @param newAttr "New" (eventually re-read in its original, unchagnged
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
49 * form) outputs.
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
50 */
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 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
52 ArtifactDatabase db,
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 Map<String, Output> oldAttr,
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 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
55 {
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
56 this.db = db;
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 this.oldAttr = oldAttr;
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 this.newAttr = newAttr;
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61
1628
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
62 /**
1634
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
63 * Create document by merging outputs given in
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
64 * constructor.
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
65 * The "new" set rules about existance of attributes, so anything not
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
66 * present in it will not be included in the resulting document.
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
67 * 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
68 * are recorded here and not in the new set).
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
69 * @return document with merged outputs as described.
1628
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
70 */
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 protected Document write() {
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 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
73
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 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
75 doc,
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 ArtifactNamespaceContext.NAMESPACE_URI,
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 ArtifactNamespaceContext.NAMESPACE_PREFIX);
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78
638
9c565eb46f06 Fixed the process of creating and storing the attribute of a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 353
diff changeset
79 Element attribute = cr.create("attribute");
705
853dceead0f4 Only generate facets when needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 694
diff changeset
80 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
81
9c565eb46f06 Fixed the process of creating and storing the attribute of a collection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 353
diff changeset
82 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
83 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
84
705
853dceead0f4 Only generate facets when needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 694
diff changeset
85 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
86
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 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
88 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
89
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
90 writeOutput(doc, outs, cr, a, b);
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 return doc;
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95
1634
cc47828a1390 Added documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1628
diff changeset
96
1628
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
97 /**
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
98 * @param doc Document to add output nodes to
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
99 * @param outs Node in Document to add output nodes to
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
100 * @param a the new output
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
101 * @param b the old output
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
102 */
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 protected void writeOutput(
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 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
105 Node outs,
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 ElementCreator cr,
1171
a3108f0a2fe7 Bugfix: merge facets for the Collection's attribute only if the new and old facet's name and owner artifact are equal.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 945
diff changeset
107 Output a, /* new output */
a3108f0a2fe7 Bugfix: merge facets for the Collection's attribute only if the new and old facet's name and owner artifact are equal.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 945
diff changeset
108 Output b) /* old output */
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 {
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 Element output = cr.create("output");
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 cr.addAttr(output, "name", a.getName());
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112
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
113 outs.appendChild(output);
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 List<Facet> facetsA = a.getFacets();
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 List<Facet> facetsB = null;
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 if (b != null) {
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 facetsB = b.getFacets();
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
122
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
123 try {
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
124 writeFacets(doc, cr, output, facetsA, facetsB);
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
125 }
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
126 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
127 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
128 }
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131
1628
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
132 /**
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
133 * @param doc Document to add facet nodes to
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
134 * @param output Node in Document to add facet nodes to
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
135 * @param a the new facets
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
136 * @param b the old facets
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
137 */
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 protected void writeFacets(
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 Document doc,
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 ElementCreator cr,
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141 Element output,
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
142 List<Facet> newFacets,
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
143 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
144 throws ArtifactDatabaseException
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 {
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
146 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
147
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
148 // 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
149 // 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
150 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
151 List<ManagedFacet> genuinelyNewFacets = new ArrayList<ManagedFacet>();
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 for (int i = 0; i < num; i++) {
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
153 ManagedFacet facet = (ManagedFacet) newFacets.get(i);
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
155 ManagedFacet picked = pickFacet(facet, oldFacets);
1639
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
156 if (facet.equals(picked)) {
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
157 genuinelyNewFacets.add(picked);
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
158 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
159 else {
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
160 currentFacets.add(picked);
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
161 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
162 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
163
1709
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
164 // 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
165 // in/activate.
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
166 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
167 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
168 newMF.setActive(flys.getInitialFacetActivity(
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
169 newMF.getName(),
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
170 newMF.getIndex()));
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
171 }
f643ea084213 Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1639
diff changeset
172
1639
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
173 // 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
174 for (ManagedFacet newMF: genuinelyNewFacets) {
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
175 boolean conflicts = true;
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
176 // 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
177 while (conflicts) {
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
178 conflicts = false;
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
179 for (ManagedFacet oldMF: currentFacets) {
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
180 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
181 conflicts = true;
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
182 logger.debug("Positional conflict while merging " +
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
183 "facets, pushing newest facet 1 up ("+newMF.getPosition()+")");
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
184 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
185 break;
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
186 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
187 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
188 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
189 currentFacets.add(newMF);
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
190 }
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
191
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
192 // Now add all facets.
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
193 for (ManagedFacet oldMF: currentFacets) {
12235a2ace21 Add positional-conflict-awareness when merging Facets in attribute
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1635
diff changeset
194 Node node = oldMF.toXML(doc);
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
195 if (node != null) {
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
196 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
197 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201
1628
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
202 /**
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
203 * Returns the facet to be added to Document.
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
204 * 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
205 * Return the "old" facet otherwise (user-defined information sticks
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
206 * to it).
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
207 * @param facet the new facet.
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
208 * @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
209 * these.
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
210 * @return facet if genuinely new, matching old facet otherwise.
1628
16c74ca3586e Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1171
diff changeset
211 */
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
212 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
213 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
214 {
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
215 if (oldFacets == null) {
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
216 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
217 return facet;
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
218 }
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
219
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
220 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
221
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
222 // Compare "new" facet with all old facets.
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
223 // Take oldFacet if that facet was already present (otherwise
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
224 // information is lost, the new one otherwise.
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
225 for (Facet oFacet: oldFacets) {
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
226 ManagedFacet oldFacet = (ManagedFacet) oFacet;
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
227 String oldHash = oldFacet.getName()
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
228 + oldFacet.getIndex()
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
229 + oldFacet.getArtifact();
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
230 if (hash.equals(oldHash)) {
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
231 return oldFacet;
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
232 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
233 }
1635
1b5204203e18 Minor refactoring, documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1634
diff changeset
234 return facet;
346
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
235 }
16161de47662 The Attributes of a collection are written into its DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
236 }
705
853dceead0f4 Only generate facets when needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 694
diff changeset
237 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org