Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/collections/OutputParser.java @ 3818:dc18457b1cef
merged flys-artifacts/pre2.7-2012-03-16
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:59 +0200 |
parents | 22732713c54d |
children | 1203e12c97a6 |
comparison
equal
deleted
inserted
replaced
2456:60ab1054069d | 3818:dc18457b1cef |
---|---|
1 package de.intevation.flys.collections; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.HashMap; | |
5 import java.util.List; | |
6 import java.util.Map; | |
7 | |
8 import org.apache.log4j.Logger; | |
9 | |
10 import de.intevation.artifacts.ArtifactDatabase; | |
11 import de.intevation.artifacts.ArtifactDatabaseException; | |
12 import de.intevation.artifacts.CallContext; | |
13 import de.intevation.artifacts.CallMeta; | |
14 | |
15 import de.intevation.artifactdatabase.state.DefaultOutput; | |
16 import de.intevation.artifactdatabase.state.Facet; | |
17 import de.intevation.artifactdatabase.state.Output; | |
18 | |
19 import de.intevation.flys.artifacts.FLYSArtifact; | |
20 import de.intevation.flys.artifacts.model.ManagedFacetAdapter; | |
21 | |
22 | |
23 public class OutputParser { | |
24 | |
25 /** Constant XPath that points to the outputmodes of an artifact. */ | |
26 public static final String XPATH_ARTIFACT_OUTPUTMODES = | |
27 "/art:result/art:outputmodes/art:output"; | |
28 | |
29 private static Logger logger = Logger.getLogger(OutputParser.class); | |
30 | |
31 protected ArtifactDatabase db; | |
32 protected CallMeta meta; | |
33 protected CallContext context; | |
34 | |
35 /** Map outputs name to Output. */ | |
36 protected Map<String, Output> outs; | |
37 | |
38 /** Map facets name to list of Facets. */ | |
39 protected List<Facet> facets; | |
40 | |
41 | |
42 /** | |
43 * @param db Database used to fetch artifacts, outputs and facets. | |
44 */ | |
45 public OutputParser(ArtifactDatabase db, CallContext context) { | |
46 this.db = db; | |
47 this.meta = context.getMeta(); | |
48 this.context = context; | |
49 this.outs = new HashMap<String, Output>(); | |
50 this.facets = new ArrayList<Facet>(); | |
51 } | |
52 | |
53 | |
54 /** | |
55 * Gets raw artifact with given id and sorts outputs in mapping. | |
56 * Converts Facets to ManagedFacets on the way. | |
57 * @param uuid uuid of artifact to load from database. | |
58 */ | |
59 public void parse(String uuid) | |
60 throws ArtifactDatabaseException | |
61 { | |
62 logger.debug("OutputParser.parse: " + uuid); | |
63 | |
64 FLYSArtifact flys = (FLYSArtifact) db.getRawArtifact(uuid); | |
65 | |
66 List<Output> outList = flys.getOutputs(context); | |
67 | |
68 logger.debug(" has " + outList.size() + " Outputs."); | |
69 | |
70 for (Output out: outList) { | |
71 String name = out.getName(); | |
72 logger.debug("Process Output '" + name + "'"); | |
73 | |
74 Output o = outs.get(name); | |
75 int pos = 1; | |
76 | |
77 if (o == null) { | |
78 o = new DefaultOutput( | |
79 out.getName(), | |
80 out.getDescription(), | |
81 out.getMimeType(), | |
82 new ArrayList<Facet>(), | |
83 out.getType()); | |
84 outs.put(name, o); | |
85 } | |
86 else { | |
87 logger.debug("OutputParser.parse: Use 'old' Output"); | |
88 pos = o.getFacets().size() + 1; | |
89 } | |
90 | |
91 List<Facet> mfacets = facet2ManagedFacet(uuid, out.getFacets(), pos); | |
92 o.addFacets(mfacets); | |
93 this.facets.addAll(mfacets); | |
94 } | |
95 } | |
96 | |
97 | |
98 /** | |
99 * Access mapping of Outputname to Output. | |
100 */ | |
101 public Map<String, Output> getOuts() { | |
102 return outs; | |
103 } | |
104 | |
105 | |
106 /** | |
107 * Access all facets. | |
108 */ | |
109 public List<Facet> getFacets() { | |
110 return this.facets; | |
111 } | |
112 | |
113 | |
114 /** | |
115 * Creates a list of ManagedFacets from list of Facets. | |
116 * @param pos Position of first facet (for each other the positions | |
117 * will be increased). | |
118 */ | |
119 protected List<Facet> facet2ManagedFacet( | |
120 String uuid, | |
121 List<Facet> old, | |
122 int pos) | |
123 { | |
124 List<Facet> newFacets = new ArrayList<Facet>(old.size()); | |
125 | |
126 logger.debug("There are " + old.size() + " Facets for this Output."); | |
127 | |
128 for (Facet f: old) { | |
129 newFacets.add(new ManagedFacetAdapter(f, uuid, pos++, 1, 1)); | |
130 } | |
131 | |
132 return newFacets; | |
133 } | |
134 } | |
135 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |