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

http://dive4elements.wald.intevation.org