annotate artifacts/src/main/java/org/dive4elements/river/exports/OutputHelper.java @ 5863:4897a58c8746

River artifacts: Added new copyright headers.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 14:40:59 +0200
parents 5aa05a7a34b7
children 9a6741ccf6d4
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
9 package org.dive4elements.river.exports;
3295
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import java.io.IOException;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 import java.util.ArrayList;
4255
670e98f5a441 Fixed leak while merging facets.
Ingo Weinzierl <weinzierl.ingo@googlemail.com>
parents: 4049
diff changeset
13 import java.util.Collections;
3295
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import java.util.HashMap;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import java.util.List;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16 import java.util.Map;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 import javax.xml.xpath.XPathConstants;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 import org.apache.log4j.Logger;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 import org.w3c.dom.Document;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 import org.w3c.dom.Element;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 import org.w3c.dom.Node;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 import org.w3c.dom.NodeList;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
26 import org.dive4elements.artifactdatabase.Backend;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
27 import org.dive4elements.artifactdatabase.Backend.PersistentArtifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
28 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
29 import org.dive4elements.artifacts.Artifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
30 import org.dive4elements.artifacts.ArtifactDatabase;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
31 import org.dive4elements.artifacts.ArtifactDatabaseException;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
32 import org.dive4elements.artifacts.CallContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
33 import org.dive4elements.artifacts.CallMeta;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
34 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
35 import org.dive4elements.artifacts.common.utils.ClientProtocolUtils;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
36 import org.dive4elements.artifacts.common.utils.XMLUtils;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
37 import org.dive4elements.river.artifacts.FLYSArtifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
38 import org.dive4elements.river.artifacts.context.FLYSContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
39 import org.dive4elements.river.artifacts.model.ManagedDomFacet;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
40 import org.dive4elements.river.artifacts.model.ManagedFacet;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
41 import org.dive4elements.river.themes.Theme;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4433
diff changeset
42 import org.dive4elements.river.themes.ThemeFactory;
3295
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 public class OutputHelper {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 /** The logger used in this class. */
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 private static Logger log = Logger.getLogger(OutputHelper.class);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 protected String identifier;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50 public OutputHelper(String identifier) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 this.identifier = identifier;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 /**
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 * Creates a concrete output.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 *
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 * @param generator The OutGenerator that creates the output.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 * @param outputName The name of the requested output.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 * @param attributes The collection's attributes for this concrete output
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 * type.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 * @param context The context object.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 */
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 public void doOut(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 OutGenerator generator,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 String outName,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 String facet,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 Document attributes,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 CallContext context)
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 throws IOException
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69 {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70 boolean debug = log.isDebugEnabled();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 if (debug) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 log.debug("FLYSArtifactCollection.doOut: " + outName);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 ThemeList themeList = new ThemeList(attributes);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 int size = themeList.size();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 if (debug) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 log.debug("Output will contain " + size + " elements.");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
83 List<ArtifactAndFacet> dataProviders =
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
84 doBlackboardPass(themeList, context);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86 try {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
87 for (int i = 0; i < size; i++) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
88 ManagedFacet theme = themeList.get(i);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
89
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
90 if (theme == null) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
91 log.debug("Theme is empty - no output is generated.");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
92 continue;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
93 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
94
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
95 String art = theme.getArtifact();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
96 String facetName = theme.getName();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
97
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
98 if (debug) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
99 log.debug("Do output for...");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
100 log.debug("... artifact: " + art);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
101 log.debug("... facet: " + facetName);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
102 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104 if (outName.equals("export") && !facetName.equals(facet)) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 continue;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
106 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
107
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
108 // Skip invisible themes.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
109 if (theme.getVisible() == 0) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
110 continue;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
111 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 if (outName.equals("sq_overview")) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
114 generator.doOut(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
115 dataProviders.get(i),
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
116 attributes,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
117 theme.getActive() == 1);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
118 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
119 else {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
120 generator.doOut(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
121 dataProviders.get(i),
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
122 getFacetThemeFromAttribute(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
123 art,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
124 outName,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
125 facetName,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
126 theme.getDescription(),
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
127 theme.getIndex(),
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
128 context),
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
129 theme.getActive() == 1);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
130 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
131 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
132 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
133 catch (ArtifactDatabaseException ade) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
134 log.error(ade, ade);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
135 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
136 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
137 /**
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
138 * Returns the attribute that belongs to an artifact and facet stored in
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
139 * this collection.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
140 *
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
141 * @param uuid The Artifact's uuid.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
142 * @param outname The name of the requested output.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
143 * @param facet The name of the requested facet.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
144 * @param context The CallContext.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
145 *
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
146 * @return an attribute in form of a document.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
147 */
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
148 protected Document getFacetThemeFromAttribute(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
149 String uuid,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
150 String outName,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
151 String facet,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
152 String pattern,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
153 int index,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
154 CallContext context)
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
155 throws ArtifactDatabaseException
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
156 {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
157 boolean debug = log.isDebugEnabled();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
158
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
159 if (debug) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
160 log.debug(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
161 "FLYSArtifactCollection.getFacetThemeFromAttribute(facet="
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
162 + facet + ", index=" + index + ")");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
163 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
164
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
165 ArtifactDatabase db = context.getDatabase();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
166 CallMeta meta = context.getMeta();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
167
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
168 Document attr = db.getCollectionItemAttribute(identifier, uuid, meta);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
169
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
170 if (attr == null) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
171 attr = initItemAttribute(uuid, facet, pattern, index, outName, context);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
172
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
173 if (attr == null) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
174 return null;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
175 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
176 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
177
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
178 if (debug) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
179 log.debug("Search attribute of collection item: " + uuid);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
180 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
181
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
182 Node tmp = (Node) XMLUtils.xpath(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
183 attr,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
184 "/art:attribute",
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
185 XPathConstants.NODE,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
186 ArtifactNamespaceContext.INSTANCE);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
187
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
188 if (tmp == null) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
189 log.warn("No attribute found. Operation failed.");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
190 return null;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
191 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
192
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
193 if (debug) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
194 log.debug("Search theme for facet '" + facet + "' in attribute.");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
195 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
196
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
197 Map<String, String> vars = new HashMap<String, String>();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
198 vars.put("facet", facet);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
199 vars.put("index", String.valueOf(index));
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
200
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
201 Node theme = (Node) XMLUtils.xpath(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
202 tmp,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
203 "art:themes/theme[@facet=$facet and @index=$index]",
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
204 XPathConstants.NODE,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
205 ArtifactNamespaceContext.INSTANCE,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
206 vars);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
207
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
208 if (theme == null) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
209 log.warn("Could not find the theme in attribute of: " + facet + " " + uuid);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
210
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
211 Theme t = getThemeForFacet(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
212 uuid, facet, pattern, index, outName, context);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
213
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
214 if (t == null) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
215 log.warn("No theme found for facet: " + facet);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
216 return null;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
217 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
218
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
219 addThemeToAttribute(uuid, attr, t, context);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
220 theme = t.toXML().getFirstChild();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
221 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
222
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
223 Document doc = XMLUtils.newDocument();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
224 doc.appendChild(doc.importNode(theme, true));
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
225
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
226 return doc;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
227 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
228 /**
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
229 * Adds the theme of a facet to a CollectionItem's attribute.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
230 *
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
231 * @param uuid The uuid of the artifact.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
232 * @param attr The current attribute of an artifact.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
233 * @param t The theme to add.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
234 * @param context The CallContext.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
235 */
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
236 protected void addThemeToAttribute(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
237 String uuid,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
238 Document attr,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
239 Theme t,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
240 CallContext context)
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
241 {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
242 log.debug("FLYSArtifactCollection.addThemeToAttribute: " + uuid);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
243
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
244 if (t == null) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
245 log.warn("Theme is empty - cancel adding it to attribute!");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
246 return;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
247 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
248
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
249 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
250 attr,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
251 ArtifactNamespaceContext.NAMESPACE_URI,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
252 ArtifactNamespaceContext.NAMESPACE_PREFIX);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
253
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
254 Node tmp = (Node) XMLUtils.xpath(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
255 attr,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
256 "/art:attribute",
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
257 XPathConstants.NODE,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
258 ArtifactNamespaceContext.INSTANCE);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
259
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
260 if (tmp == null) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
261 tmp = ec.create("attribute");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
262 attr.appendChild(tmp);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
263 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
264
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
265 Node themes = (Node) XMLUtils.xpath(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
266 tmp,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
267 "art:themes",
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
268 XPathConstants.NODE,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
269 ArtifactNamespaceContext.INSTANCE);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
270
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
271 if (themes == null) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
272 themes = ec.create("themes");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
273 tmp.appendChild(themes);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
274 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
275
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
276 themes.appendChild(attr.importNode(t.toXML().getFirstChild(), true));
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
277
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
278 try {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
279 setCollectionItemAttribute(uuid, attr, context);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
280 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
281 catch (ArtifactDatabaseException e) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
282 // do nothing
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
283 log.warn("Cannot set attribute of item: " + uuid);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
284 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
285 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
286
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
287 /**
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
288 * Sets the attribute of a CollectionItem specified by <i>uuid</i> to a new
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
289 * value <i>attr</i>.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
290 *
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
291 * @param uuid The uuid of the CollectionItem.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
292 * @param attr The new attribute for the CollectionItem.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
293 * @param context The CallContext.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
294 */
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
295 public void setCollectionItemAttribute(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
296 String uuid,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
297 Document attr,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
298 CallContext context)
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
299 throws ArtifactDatabaseException
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
300 {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
301 Document doc = ClientProtocolUtils.newSetItemAttributeDocument(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
302 uuid,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
303 attr);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
304
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
305 if (doc == null) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
306 log.warn("Cannot set item attribute: No attribute found.");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
307 return;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
308 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
309
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
310 ArtifactDatabase db = context.getDatabase();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
311 CallMeta meta = context.getMeta();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
312
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
313 db.setCollectionItemAttribute(identifier, uuid, doc, meta);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
314 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
315
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
316
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
317 /**
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
318 * Show blackboard (context) to each facet and create a list of
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
319 * ArtifactAndFacets on the fly (with the same ordering as the passed
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
320 * ThemeList).
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
321 * @param themeList ThemeList to create a ArtifactAndFacetList along.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
322 * @param context The "Blackboard".
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
323 */
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
324 protected List<ArtifactAndFacet> doBlackboardPass(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
325 ThemeList themeList, CallContext context
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
326 ) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
327 ArrayList<ArtifactAndFacet> dataProviders =
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
328 new ArrayList<ArtifactAndFacet>();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
329 int size = themeList.size();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
330
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
331 try {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
332 // Collect all ArtifactAndFacets for blackboard pass.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
333 for (int i = 0; i < size; i++) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
334 ManagedFacet theme = themeList.get(i);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
335 if (theme == null) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
336 log.warn("A ManagedFacet in ThemeList is null.");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
337 continue;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
338 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
339 String uuid = theme.getArtifact();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
340 Artifact artifact = getArtifact(uuid, context);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
341 FLYSArtifact flys = (FLYSArtifact) artifact;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
342
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
343 ArtifactAndFacet artifactAndFacet = new ArtifactAndFacet(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
344 artifact,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
345 flys.getNativeFacet(theme));
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
346
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
347 // XXX HELP ME PLEASE
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
348 artifactAndFacet.setFacetDescription(theme.getDescription());
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
349
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
350 // Show blackboard to facet.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
351 artifactAndFacet.register(context);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
352
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
353 // Add to themes.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
354 dataProviders.add(i, artifactAndFacet);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
355 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
356 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
357 catch (ArtifactDatabaseException ade) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
358 log.error("ArtifactDatabaseException!", ade);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
359 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
360
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
361 return dataProviders;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
362 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
363 /**
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
364 * Returns a concrete Artifact of this collection specified by its uuid.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
365 *
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
366 * @param uuid The Artifact's uuid.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
367 * @param context The CallContext.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
368 *
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
369 * @return an Artifact.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
370 */
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
371 protected Artifact getArtifact(String uuid, CallContext context)
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
372 throws ArtifactDatabaseException
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
373 {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
374 log.debug("FLYSArtifactCollection.getArtifact");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
375
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
376 Backend backend = Backend.getInstance();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
377 PersistentArtifact persistent = backend.getArtifact(uuid);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
378
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
379 return persistent != null ? persistent.getArtifact() : null;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
380 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
381
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
382 /**
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
383 * Initializes the attribute of an collection item with the theme of a
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
384 * specific facet.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
385 *
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
386 * @param uuid The uuid of an artifact.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
387 * @param facet The name of a facet.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
388 * @param context The CallContext.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
389 *
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
390 * @param the new attribute.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
391 */
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
392 protected Document initItemAttribute(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
393 String uuid,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
394 String facet,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
395 String pattern,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
396 int index,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
397 String outName,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
398 CallContext context)
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
399 {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
400 boolean debug = log.isDebugEnabled();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
401
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
402 if (debug) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
403 log.debug("FLYSArtifactCollection.initItemAttribute");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
404 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
405
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
406 Theme t = getThemeForFacet(uuid, facet, pattern, index, outName, context);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
407
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
408 if (t == null) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
409 log.info("Could not find theme for facet. Cancel initialization.");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
410 return null;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
411 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
412
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
413 Document attr = XMLUtils.newDocument();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
414 addThemeToAttribute(uuid, attr, t, context);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
415
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
416 if (debug) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
417 log.debug("initItemAttribute for facet " + facet + ": "
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
418 + XMLUtils.toString(attr));
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
419 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
420
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
421 return attr;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
422 }
3299
d76a889bc30d Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3295
diff changeset
423
3295
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
424 /**
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
425 * Returns the theme of a specific facet.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
426 *
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
427 * @param uuid The uuid of an artifact.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
428 * @param facet The name of the facet.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
429 * @param context The CallContext object.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
430 *
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
431 * @return the desired theme.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
432 */
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
433 protected Theme getThemeForFacet(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
434 String uuid,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
435 String facet,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
436 String pattern,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
437 int index,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
438 String outName,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
439 CallContext context)
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
440 {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
441 log.info("FLYSArtifactCollection.getThemeForFacet: " + facet);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
442
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
443 FLYSContext flysContext = context instanceof FLYSContext
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
444 ? (FLYSContext) context
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
445 : (FLYSContext) context.globalContext();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
446
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
447 // Push artifact in flysContext.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
448 ArtifactDatabase db = context.getDatabase();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
449 try {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
450 FLYSArtifact artifact = (FLYSArtifact) db.getRawArtifact(uuid);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
451 log.debug("Got raw artifact");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
452 flysContext.put(FLYSContext.ARTIFACT_KEY, artifact);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
453 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
454 catch (ArtifactDatabaseException dbe) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
455 log.error("Exception caught when trying to get art.", dbe);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
456 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
457
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
458 Theme t = ThemeFactory.getTheme(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
459 flysContext,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
460 facet,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
461 pattern,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
462 outName,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
463 "default");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
464
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
465 if (t != null) {
3781
8e713e9bb4d7 Defined colors for bed quality themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3304
diff changeset
466 log.debug("found theme for facet '" + facet + "'");
3295
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
467 t.setFacet(facet);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
468 t.setIndex(index);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
469 }
3781
8e713e9bb4d7 Defined colors for bed quality themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3304
diff changeset
470 else {
8e713e9bb4d7 Defined colors for bed quality themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3304
diff changeset
471 log.warn("unable to find theme for facet '" + facet + "'");
8e713e9bb4d7 Defined colors for bed quality themes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3304
diff changeset
472 }
3295
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
473
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
474 return t;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
475 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
476
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
477 /**
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
478 * Inner class to structure/order the themes of a chart.
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
479 */
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
480 private static class ThemeList {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
481 private Logger logger = Logger.getLogger(ThemeList.class);
4255
670e98f5a441 Fixed leak while merging facets.
Ingo Weinzierl <weinzierl.ingo@googlemail.com>
parents: 4049
diff changeset
482 protected List<ManagedFacet> themes;
3295
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
483
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
484 public ThemeList(Document output) {
4255
670e98f5a441 Fixed leak while merging facets.
Ingo Weinzierl <weinzierl.ingo@googlemail.com>
parents: 4049
diff changeset
485 themes = new ArrayList<ManagedFacet>();
3295
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
486 parse(output);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
487 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
488
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
489 protected void parse(Document output) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
490 NodeList themeList = (NodeList) XMLUtils.xpath(
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
491 output,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
492 "art:output/art:facet",
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
493 XPathConstants.NODESET,
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
494 ArtifactNamespaceContext.INSTANCE);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
495
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
496 int num = themeList != null ? themeList.getLength() : 0;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
497
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
498 logger.debug("Output has " + num + " elements.");
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
499
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
500 if (num == 0) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
501 return;
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
502 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
503
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
504 for (int i = 0; i < num; i++) {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
505 Element theme = (Element) themeList.item(i);
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
506
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
507 ManagedDomFacet facet = new ManagedDomFacet(theme);
4255
670e98f5a441 Fixed leak while merging facets.
Ingo Weinzierl <weinzierl.ingo@googlemail.com>
parents: 4049
diff changeset
508 themes.add(facet);
3295
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
509 }
4255
670e98f5a441 Fixed leak while merging facets.
Ingo Weinzierl <weinzierl.ingo@googlemail.com>
parents: 4049
diff changeset
510
670e98f5a441 Fixed leak while merging facets.
Ingo Weinzierl <weinzierl.ingo@googlemail.com>
parents: 4049
diff changeset
511 Collections.sort(themes);
3295
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
512 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
513
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
514 public ManagedFacet get(int idx) {
4255
670e98f5a441 Fixed leak while merging facets.
Ingo Weinzierl <weinzierl.ingo@googlemail.com>
parents: 4049
diff changeset
515 return themes.get(idx);
3295
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
516 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
517
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
518 public int size() {
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
519 return themes.size();
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
520 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
521 }
4fc442f1b4f6 Refactored FLYSArtifactCollection.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
522 }
3304
02d5731b43a2 SQ relation: Build a valid SQResult.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3299
diff changeset
523 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org