comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/DataCage.java @ 963:f48cef242e7f

Datacage: recommendation mechanism now accepts nodes to append results. flys-artifacts/trunk@2382 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 20 Jul 2011 22:03:50 +0000
parents 92027887775a
children ff6ce301c472
comparison
equal deleted inserted replaced
962:2de1808503be 963:f48cef242e7f
13 import java.sql.SQLException; 13 import java.sql.SQLException;
14 14
15 import org.apache.log4j.Logger; 15 import org.apache.log4j.Logger;
16 16
17 import org.w3c.dom.Document; 17 import org.w3c.dom.Document;
18 import org.w3c.dom.Node;
18 19
19 import org.hibernate.Session; 20 import org.hibernate.Session;
20 21
21 import org.hibernate.jdbc.Work; 22 import org.hibernate.jdbc.Work;
22 23
50 51
51 public Builder getBuilder() { 52 public Builder getBuilder() {
52 return builder; 53 return builder;
53 } 54 }
54 55
55 public Document recommend(FLYSArtifact artifact, String [] outs) { 56 protected static void artifactToParameters(
56 return recommend(artifact, outs, null); 57 FLYSArtifact artifact,
57 } 58 Map<String, Object> parameters
58
59 public Document recommend(
60 FLYSArtifact artifact,
61 String [] outs,
62 Map<String, Object> extraParameters
63 ) { 59 ) {
64 Map<String, Object> parameters = new HashMap<String, Object>();
65
66 if (extraParameters != null) {
67 parameters.putAll(extraParameters);
68 }
69
70 parameters.put("current-state-id", artifact.getCurrentStateId()); 60 parameters.put("current-state-id", artifact.getCurrentStateId());
71 parameters.put("artifact-outs", outs);
72 61
73 for (StateData sd: artifact.getAllData()) { 62 for (StateData sd: artifact.getAllData()) {
74 Object value = sd.getValue(); 63 Object value = sd.getValue();
75 if (value == null) { 64 if (value == null) {
76 continue; 65 continue;
77 } 66 }
78 String key = sd.getName().replace('.', '-'); 67 String key = sd.getName().replace('.', '-');
79 parameters.put(key, value); 68 parameters.put(key, value);
80 } 69 }
81
82 return process(parameters);
83 } 70 }
84 71
85 public Document process(final Map<String, Object> parameters) { 72 public void recommend(
86 final Document result = XMLUtils.newDocument(); 73 FLYSArtifact artifact,
74 String [] outs,
75 Map<String, Object> extraParameters,
76 Node result
77 ) {
78 Map<String, Object> parameters = new HashMap<String, Object>();
87 79
80 if (extraParameters != null) {
81 parameters.putAll(extraParameters);
82 }
83
84 artifactToParameters(artifact, parameters);
85
86 parameters.put("artifact-outs", outs);
87
88 recommend(parameters, result);
89 }
90
91 public void recommend(
92 final Map<String, Object> parameters,
93 final Node result
94 ) {
88 if (builder != null) { 95 if (builder != null) {
89 log.error("builder not configured properly."); 96 log.error("builder not configured properly.");
90 return result; 97 return;
91 } 98 }
92 99
93 Session session = SessionHolder.HOLDER.get(); 100 Session session = SessionHolder.HOLDER.get();
94 101
95 session.doWork(new Work() { 102 session.doWork(new Work() {
98 throws SQLException 105 throws SQLException
99 { 106 {
100 builder.build(connection, result, parameters); 107 builder.build(connection, result, parameters);
101 } 108 }
102 }); 109 });
103
104 return result;
105 } 110 }
106 111
107 public static synchronized DataCage getInstance() { 112 public static synchronized DataCage getInstance() {
108 if (INSTANCE == null) { 113 if (INSTANCE == null) {
109 INSTANCE = createDataCage(); 114 INSTANCE = createDataCage();

http://dive4elements.wald.intevation.org