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