comparison artifacts/src/main/java/org/dive4elements/river/artifacts/CollectionMonitor.java @ 7464:f16dce7a2407

Simplified recommendattion monitor code a bit.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 30 Oct 2013 11:57:04 +0100
parents 505b05e223b1
children fff862f4ef76
comparison
equal deleted inserted replaced
7463:52c364813cb1 7464:f16dce7a2407
10 10
11 import java.util.HashMap; 11 import java.util.HashMap;
12 import java.util.List; 12 import java.util.List;
13 import java.util.Map; 13 import java.util.Map;
14 14
15 import javax.xml.xpath.XPathConstants;
16
17 import org.w3c.dom.Document; 15 import org.w3c.dom.Document;
18 import org.w3c.dom.Element; 16 import org.w3c.dom.Element;
19 import org.w3c.dom.Node; 17 import org.w3c.dom.Node;
18 import org.w3c.dom.NodeList;
20 19
21 import org.dive4elements.artifacts.Artifact; 20 import org.dive4elements.artifacts.Artifact;
22 import org.dive4elements.artifacts.ArtifactNamespaceContext; 21 import org.dive4elements.artifacts.ArtifactNamespaceContext;
23 import org.dive4elements.artifacts.CallContext; 22 import org.dive4elements.artifacts.CallContext;
24 import org.dive4elements.artifacts.Hook; 23 import org.dive4elements.artifacts.Hook;
25 24
26 import org.dive4elements.artifacts.common.utils.XMLUtils;
27 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; 25 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
28 26
29 import org.dive4elements.artifactdatabase.state.Output; 27 import org.dive4elements.artifactdatabase.state.Output;
30 28
31 import org.dive4elements.river.artifacts.datacage.Recommendations; 29 import org.dive4elements.river.artifacts.datacage.Recommendations;
32 30
33 /** Monitors collection changes. */ 31 /** Monitors collection changes. */
34 public class CollectionMonitor implements Hook { 32 public class CollectionMonitor implements Hook {
35
36 public static final String XPATH_RESULT = "/art:result";
37
38 33
39 @Override 34 @Override
40 public void setup(Node cfg) { 35 public void setup(Node cfg) {
41 } 36 }
42 37
49 String out = flys.getBoundToOut(); 44 String out = flys.getBoundToOut();
50 if (out != null && !out.isEmpty()) { 45 if (out != null && !out.isEmpty()) {
51 return; 46 return;
52 } 47 }
53 48
54 Element result = (Element) XMLUtils.xpath( 49 NodeList results = doc.getElementsByTagNameNS(
55 doc, 50 ArtifactNamespaceContext.NAMESPACE_URI, "result");
56 XPATH_RESULT, 51
57 XPathConstants.NODE, 52 if (results.getLength() < 1) {
58 ArtifactNamespaceContext.INSTANCE); 53 return;
54 }
55
56 Element result = (Element)results.item(0);
59 57
60 ElementCreator creator = new ElementCreator( 58 ElementCreator creator = new ElementCreator(
61 doc, 59 doc,
62 ArtifactNamespaceContext.NAMESPACE_URI, 60 ArtifactNamespaceContext.NAMESPACE_URI,
63 ArtifactNamespaceContext.NAMESPACE_PREFIX); 61 ArtifactNamespaceContext.NAMESPACE_PREFIX);
64 62
65 Element recommended = creator.create("recommended-artifacts"); 63 Element recommended = creator.create("recommended-artifacts");
66 result.appendChild(recommended);
67 64
68 String[] outs = extractOutputNames(flys, context); 65 String[] outs = extractOutputNames(flys, context);
69 Map<String, Object> params = getNoneUserSpecificParameters(flys, context); 66 Map<String, Object> params = getNoneUserSpecificParameters(flys, context);
70 67
71 Recommendations rec = Recommendations.getInstance(); 68 Recommendations rec = Recommendations.getInstance();
72 69
73 // TODO For newer official-lines recommendations we actually 70 // TODO For newer official-lines recommendations we actually
74 // need user-id (null here). 71 // need user-id (null here).
75 rec.recommend(flys, null, outs, params, recommended); 72 rec.recommend(flys, null, outs, params, recommended);
73
74 result.appendChild(recommended);
76 } 75 }
77 76
78 77
79 /** 78 /**
80 * Get outputnames from current state (only the ones for which 79 * Get outputnames from current state (only the ones for which

http://dive4elements.wald.intevation.org