Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java @ 1020:a776afdf1ec5
Cosmetic: Replaced usage of legacy java.util.Stack with java.util.Deque.
flys-artifacts/trunk@2475 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 09 Aug 2011 10:23:04 +0000 |
parents | d42fa223be48 |
children | 930a9ce24294 |
rev | line source |
---|---|
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.datacage; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.util.Map; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import java.util.HashMap; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.util.List; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import java.util.ArrayList; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import java.io.InputStream; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import java.io.IOException; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import java.io.File; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import java.io.FileInputStream; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import java.sql.Connection; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import java.sql.SQLException; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import javax.sql.DataSource; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 import org.apache.log4j.Logger; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 import org.w3c.dom.Document; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 import org.w3c.dom.Node; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 import org.hibernate.Session; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 import org.hibernate.jdbc.Work; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 import de.intevation.artifacts.common.utils.Config; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 import de.intevation.artifacts.common.utils.XMLUtils; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 import de.intevation.flys.artifacts.FLYSArtifact; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 import de.intevation.flys.backend.SessionHolder; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 import de.intevation.artifactdatabase.data.StateData; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 import de.intevation.flys.artifacts.datacage.templating.Builder; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 public class Recommendations |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 private static Logger log = Logger.getLogger(Recommendations.class); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 public static final String XPATH_SYSTEM_TEMPLATE = |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 "/artifact-database/metadata/system/@template"; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 public static final String XPATH_USER_TEMPLATE = |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 "/artifact-database/metadata/user/@template"; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 private static Recommendations INSTANCE; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 protected Builder systemBuilder; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 protected Builder userBuilder; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 public Recommendations() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 public Recommendations(Builder systemBuilder, Builder userBuilder) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 this.systemBuilder = systemBuilder; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 this.userBuilder = userBuilder; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 public Builder getUserBuilder() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 return userBuilder; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 public Builder getSystemBuilder() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 return systemBuilder; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 protected static void artifactToParameters( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 FLYSArtifact artifact, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 Map<String, Object> parameters |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 ) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 parameters.put("current-state-id", artifact.getCurrentStateId()); |
1018
d42fa223be48
Datacage: added first user specific config for cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1015
diff
changeset
|
75 parameters.put("artifact-id", artifact.identifier()); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 for (StateData sd: artifact.getAllData()) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 Object value = sd.getValue(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 if (value == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 continue; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 String key = sd.getName().replace('.', '-'); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 parameters.put(key, value); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 public void recommend( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 FLYSArtifact artifact, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 String userId, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 String [] outs, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 Map<String, Object> extraParameters, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 Node result |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 ) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 Map<String, Object> parameters = new HashMap<String, Object>(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 if (extraParameters != null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 parameters.putAll(extraParameters); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 if (userId != null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 parameters.put("user-id", userId); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 if (artifact != null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 artifactToParameters(artifact, parameters); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 parameters.put("artifact-outs", outs); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 parameters.put("parameters", parameters); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 recommend(parameters, userId, result); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 public void recommend( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 Map<String, Object> parameters, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 String userId, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 Node result |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 ) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 recommend(parameters, userId, result, SessionHolder.HOLDER.get()); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 public void recommend( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 final Map<String, Object> parameters, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 final String userId, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 final Node result, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 Session session |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 ) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 if (systemBuilder == null || userBuilder == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 log.error("builder not configured properly."); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 return; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 session.doWork(new Work() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 @Override |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 public void execute(Connection systemConnection) |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 throws SQLException |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 List<Builder.NamedConnection> connections = |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 new ArrayList<Builder.NamedConnection>(2); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 if (userId != null) { // system and user templates |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 // get connection to datacage db |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 DataSource dataSource = DBConfig |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 .getInstance() |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 .getDBConnection() |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 .getDataSource(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 Connection userConnection = dataSource.getConnection(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 try { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 connections.add(new Builder.NamedConnection( |
1018
d42fa223be48
Datacage: added first user specific config for cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1015
diff
changeset
|
152 Builder.CONNECTION_USER, userConnection)); |
d42fa223be48
Datacage: added first user specific config for cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1015
diff
changeset
|
153 |
d42fa223be48
Datacage: added first user specific config for cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1015
diff
changeset
|
154 connections.add(new Builder.NamedConnection( |
d42fa223be48
Datacage: added first user specific config for cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1015
diff
changeset
|
155 Builder.CONNECTION_SYSTEM, systemConnection, false)); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 userBuilder.build(connections, result, parameters); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 finally { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 userConnection.close(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 else { // system template only |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 connections.add(new Builder.NamedConnection( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 Builder.CONNECTION_SYSTEM, systemConnection)); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 systemBuilder.build(connections, result, parameters); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 }); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 public static synchronized Recommendations getInstance() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 if (INSTANCE == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 INSTANCE = createRecommendations(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 return INSTANCE; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 protected static Document loadTemplate(File file) throws IOException { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 InputStream in = null; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 try { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 in = new FileInputStream(file); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 Document template = XMLUtils.parseDocument(in); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 if (template == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 throw new IOException("cannot load template"); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 return template; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 finally { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 if (in != null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 try { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 in.close(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 catch (IOException ioe) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 log.error(ioe); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 public static Recommendations createRecommendations( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 File systemFile, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 File userFile |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 ) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 log.debug("Recommendations.createBuilder"); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 if (!systemFile.isFile() || !systemFile.canRead()) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 log.error("Cannot open template file '" + systemFile + "'"); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 return null; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 if (!userFile.isFile() || !userFile.canRead()) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 log.error("Cannot open template file '" + userFile + "'"); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 return null; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 try { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 Document systemTemplate = loadTemplate(systemFile); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 Document userTemplate = loadTemplate(userFile); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 return new Recommendations( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 new Builder(systemTemplate), |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 new Builder(userTemplate)); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 catch (IOException ioe) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 log.error(ioe); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 return null; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 protected static Recommendations createRecommendations() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 log.debug("Recommendations.createRecommendations"); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 String systemPath = Config.getStringXPath(XPATH_SYSTEM_TEMPLATE); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 String userPath = Config.getStringXPath(XPATH_USER_TEMPLATE); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 if (systemPath == null || userPath == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 log.error("no path to template file given"); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 return null; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 systemPath = Config.replaceConfigDir(systemPath); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 userPath = Config.replaceConfigDir(userPath); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 return createRecommendations( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 new File(systemPath), |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 new File(userPath)); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |