Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/CollectionMonitor.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java@a929d9a9fa1e |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.artifacts; | |
2 | |
3 import java.util.HashMap; | |
4 import java.util.List; | |
5 import java.util.Map; | |
6 | |
7 import javax.xml.xpath.XPathConstants; | |
8 | |
9 import org.w3c.dom.Document; | |
10 import org.w3c.dom.Element; | |
11 import org.w3c.dom.Node; | |
12 | |
13 import org.dive4elements.artifacts.Artifact; | |
14 import org.dive4elements.artifacts.ArtifactNamespaceContext; | |
15 import org.dive4elements.artifacts.CallContext; | |
16 import org.dive4elements.artifacts.Hook; | |
17 | |
18 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
19 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; | |
20 | |
21 import org.dive4elements.artifactdatabase.state.Output; | |
22 | |
23 import org.dive4elements.river.artifacts.datacage.Recommendations; | |
24 | |
25 /** Monitors collection changes. */ | |
26 public class CollectionMonitor implements Hook { | |
27 | |
28 public static final String XPATH_RESULT = "/art:result"; | |
29 | |
30 | |
31 @Override | |
32 public void setup(Node cfg) { | |
33 } | |
34 | |
35 | |
36 @Override | |
37 public void execute(Artifact artifact, CallContext context, Document doc) { | |
38 FLYSArtifact flys = (FLYSArtifact) artifact; | |
39 | |
40 Element result = (Element) XMLUtils.xpath( | |
41 doc, | |
42 XPATH_RESULT, | |
43 XPathConstants.NODE, | |
44 ArtifactNamespaceContext.INSTANCE); | |
45 | |
46 ElementCreator creator = new ElementCreator( | |
47 doc, | |
48 ArtifactNamespaceContext.NAMESPACE_URI, | |
49 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
50 | |
51 Element recommended = creator.create("recommended-artifacts"); | |
52 result.appendChild(recommended); | |
53 | |
54 String[] outs = extractOutputNames(flys, context); | |
55 Map<String, Object> params = getNoneUserSpecificParameters(flys, context); | |
56 | |
57 Recommendations rec = Recommendations.getInstance(); | |
58 | |
59 // TODO For newer official-lines recommendations we actually | |
60 // need user-id (null here). | |
61 rec.recommend(flys, null, outs, params, recommended); | |
62 } | |
63 | |
64 | |
65 /** | |
66 * Get outputnames from current state (only the ones for which | |
67 * facets exist). | |
68 */ | |
69 public static String[] extractOutputNames( | |
70 FLYSArtifact flys, | |
71 CallContext context) | |
72 { | |
73 if (flys instanceof ChartArtifact) { | |
74 return new String[0]; | |
75 } | |
76 | |
77 List<Output> outs = flys.getCurrentOutputs(context); | |
78 | |
79 int num = outs == null ? 0 : outs.size(); | |
80 | |
81 String[] names = new String[num]; | |
82 | |
83 for (int i = 0; i < num; i++) { | |
84 names[i] = outs.get(i).getName(); | |
85 } | |
86 | |
87 return names; | |
88 } | |
89 | |
90 | |
91 /** | |
92 * Creates Map from Strings "recommended" to "true". | |
93 */ | |
94 protected Map<String, Object> getNoneUserSpecificParameters( | |
95 FLYSArtifact flys, | |
96 CallContext context) | |
97 { | |
98 Map<String, Object> params = new HashMap<String, Object>(1); | |
99 params.put("recommended", "true"); | |
100 | |
101 return params; | |
102 } | |
103 } | |
104 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |