Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/meta/DataCage.java @ 960:92027887775a
DataCage: Added a recommend() method to generate recommendations for
a given artifact, outs and extra parameters.
flys-artifacts/trunk@2379 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 20 Jul 2011 17:03:00 +0000 |
parents | 22bc87a42a0d |
children | f48cef242e7f |
comparison
equal
deleted
inserted
replaced
959:a2b20ed3d3b4 | 960:92027887775a |
---|---|
1 package de.intevation.flys.artifacts.services.meta; | 1 package de.intevation.flys.artifacts.services.meta; |
2 | |
3 import java.util.Map; | |
4 import java.util.HashMap; | |
2 | 5 |
3 import java.io.InputStream; | 6 import java.io.InputStream; |
4 import java.io.IOException; | 7 import java.io.IOException; |
5 import java.io.File; | 8 import java.io.File; |
6 | 9 |
7 import java.io.FileInputStream; | 10 import java.io.FileInputStream; |
8 | 11 |
12 import java.sql.Connection; | |
13 import java.sql.SQLException; | |
14 | |
9 import org.apache.log4j.Logger; | 15 import org.apache.log4j.Logger; |
10 | 16 |
11 import org.w3c.dom.Document; | 17 import org.w3c.dom.Document; |
12 | 18 |
19 import org.hibernate.Session; | |
20 | |
21 import org.hibernate.jdbc.Work; | |
22 | |
13 import de.intevation.artifacts.common.utils.Config; | 23 import de.intevation.artifacts.common.utils.Config; |
14 import de.intevation.artifacts.common.utils.XMLUtils; | 24 import de.intevation.artifacts.common.utils.XMLUtils; |
25 | |
26 import de.intevation.flys.artifacts.FLYSArtifact; | |
27 | |
28 import de.intevation.flys.backend.SessionHolder; | |
29 | |
30 import de.intevation.artifactdatabase.data.StateData; | |
31 | |
15 | 32 |
16 public class DataCage | 33 public class DataCage |
17 { | 34 { |
18 private static Logger log = Logger.getLogger(DataCage.class); | 35 private static Logger log = Logger.getLogger(DataCage.class); |
19 | 36 |
31 this.builder = builder; | 48 this.builder = builder; |
32 } | 49 } |
33 | 50 |
34 public Builder getBuilder() { | 51 public Builder getBuilder() { |
35 return builder; | 52 return builder; |
53 } | |
54 | |
55 public Document recommend(FLYSArtifact artifact, String [] outs) { | |
56 return recommend(artifact, outs, null); | |
57 } | |
58 | |
59 public Document recommend( | |
60 FLYSArtifact artifact, | |
61 String [] outs, | |
62 Map<String, Object> extraParameters | |
63 ) { | |
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()); | |
71 parameters.put("artifact-outs", outs); | |
72 | |
73 for (StateData sd: artifact.getAllData()) { | |
74 Object value = sd.getValue(); | |
75 if (value == null) { | |
76 continue; | |
77 } | |
78 String key = sd.getName().replace('.', '-'); | |
79 parameters.put(key, value); | |
80 } | |
81 | |
82 return process(parameters); | |
83 } | |
84 | |
85 public Document process(final Map<String, Object> parameters) { | |
86 final Document result = XMLUtils.newDocument(); | |
87 | |
88 if (builder != null) { | |
89 log.error("builder not configured properly."); | |
90 return result; | |
91 } | |
92 | |
93 Session session = SessionHolder.HOLDER.get(); | |
94 | |
95 session.doWork(new Work() { | |
96 @Override | |
97 public void execute(Connection connection) | |
98 throws SQLException | |
99 { | |
100 builder.build(connection, result, parameters); | |
101 } | |
102 }); | |
103 | |
104 return result; | |
36 } | 105 } |
37 | 106 |
38 public static synchronized DataCage getInstance() { | 107 public static synchronized DataCage getInstance() { |
39 if (INSTANCE == null) { | 108 if (INSTANCE == null) { |
40 INSTANCE = createDataCage(); | 109 INSTANCE = createDataCage(); |