Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java @ 1043:9c0f981cd22d
Datacage user template: Removed state filter because it was broken. Simplified by joining two contexts.
flys-artifacts/trunk@2504 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 18 Aug 2011 14:13:35 +0000 |
parents | c586b6220f35 |
children | 0a5eff5511b1 |
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 |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
43 private static final boolean DEVELOPMENT_MODE = |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
44 Boolean.getBoolean("flys.datacage.recommendations.development"); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
45 |
1015
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_SYSTEM_TEMPLATE = |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 "/artifact-database/metadata/system/@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 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
|
50 "/artifact-database/metadata/user/@template"; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 private static Recommendations INSTANCE; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
54 public static class BuilderProvider |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
55 { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
56 protected Builder builder; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
57 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
58 public BuilderProvider() { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
59 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
60 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
61 public BuilderProvider(Builder builder) { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
62 this.builder = builder; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
63 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
64 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
65 public Builder getBuilder() { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
66 return builder; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
67 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
68 } // class BuilderProvider |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
69 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
70 public static class FileBuilderProvider |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
71 extends BuilderProvider |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
72 { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
73 protected File file; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
74 protected long lastModified; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
75 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
76 public FileBuilderProvider() { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
77 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
78 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
79 public FileBuilderProvider(File file) { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
80 this.file = file; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
81 lastModified = Long.MIN_VALUE; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
82 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
83 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
84 @Override |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
85 public synchronized Builder getBuilder() { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
86 long modified = file.lastModified(); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
87 if (modified > lastModified) { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
88 lastModified = modified; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
89 try { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
90 Document template = loadTemplate(file); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
91 builder = new Builder(template); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
92 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
93 catch (IOException ioe) { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
94 log.error(ioe); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
95 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
96 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
97 return builder; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
98 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
99 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
100 public BuilderProvider toStaticProvider() { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
101 return new BuilderProvider(builder); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
102 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
103 } // class BuilderProvider |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
104 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
105 protected BuilderProvider systemBuilderProvider; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
106 protected BuilderProvider userBuilderProvider; |
1015
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 public Recommendations() { |
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 |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
111 public Recommendations( |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
112 BuilderProvider systemBuilderProvider, |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
113 BuilderProvider userBuilderProvider) { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
114 this.systemBuilderProvider = systemBuilderProvider; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
115 this.userBuilderProvider = userBuilderProvider; |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 public Builder getUserBuilder() { |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
119 return userBuilderProvider.getBuilder(); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 } |
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 public Builder getSystemBuilder() { |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
123 return systemBuilderProvider.getBuilder(); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 protected static void artifactToParameters( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 FLYSArtifact artifact, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 Map<String, Object> parameters |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 ) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 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
|
131 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
|
132 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 for (StateData sd: artifact.getAllData()) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 Object value = sd.getValue(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 if (value == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 continue; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 String key = sd.getName().replace('.', '-'); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 parameters.put(key, value); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 } |
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 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 public void recommend( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 FLYSArtifact artifact, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 String userId, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 String [] outs, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 Map<String, Object> extraParameters, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 Node result |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 ) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 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
|
151 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 if (extraParameters != null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 parameters.putAll(extraParameters); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 if (userId != null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 parameters.put("user-id", userId); |
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 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 if (artifact != null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 artifactToParameters(artifact, parameters); |
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 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 parameters.put("artifact-outs", outs); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 parameters.put("parameters", parameters); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 recommend(parameters, userId, result); |
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 public void recommend( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 Map<String, Object> parameters, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 String userId, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 Node result |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 ) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 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
|
177 } |
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 public void recommend( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 final Map<String, Object> parameters, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 final String userId, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 final Node result, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 Session session |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 ) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 session.doWork(new Work() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 @Override |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 public void execute(Connection systemConnection) |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 throws SQLException |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 List<Builder.NamedConnection> connections = |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 new ArrayList<Builder.NamedConnection>(2); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 |
1029
3f3988bb6284
Picky Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1022
diff
changeset
|
193 if (userId != null) { // Use system and user templates. |
3f3988bb6284
Picky Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1022
diff
changeset
|
194 // Get connection to datacage db. |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 DataSource dataSource = DBConfig |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 .getInstance() |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 .getDBConnection() |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 .getDataSource(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 Connection userConnection = dataSource.getConnection(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 try { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 connections.add(new Builder.NamedConnection( |
1022
930a9ce24294
Datacage: Fixed caching issue leading to incorrect results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1018
diff
changeset
|
203 Builder.CONNECTION_USER, userConnection, false)); |
1018
d42fa223be48
Datacage: added first user specific config for cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1015
diff
changeset
|
204 |
d42fa223be48
Datacage: added first user specific config for cross sections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1015
diff
changeset
|
205 connections.add(new Builder.NamedConnection( |
1022
930a9ce24294
Datacage: Fixed caching issue leading to incorrect results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1018
diff
changeset
|
206 Builder.CONNECTION_SYSTEM, systemConnection, true)); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
208 getUserBuilder().build(connections, result, parameters); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 finally { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 userConnection.close(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 } |
1029
3f3988bb6284
Picky Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1022
diff
changeset
|
214 else { // Use system template only. |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 connections.add(new Builder.NamedConnection( |
1022
930a9ce24294
Datacage: Fixed caching issue leading to incorrect results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1018
diff
changeset
|
216 Builder.CONNECTION_SYSTEM, systemConnection, true)); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
218 getSystemBuilder().build(connections, result, parameters); |
1015
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 }); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 public static synchronized Recommendations getInstance() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 if (INSTANCE == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 INSTANCE = createRecommendations(); |
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 return INSTANCE; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 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
|
232 InputStream in = null; |
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 try { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 in = new FileInputStream(file); |
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 Document template = XMLUtils.parseDocument(in); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 if (template == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 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
|
241 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 return template; |
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 finally { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 if (in != null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 try { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 in.close(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 catch (IOException ioe) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 log.error(ioe); |
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 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 public static Recommendations createRecommendations( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
257 File systemFile, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 File userFile |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 ) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 log.debug("Recommendations.createBuilder"); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 if (!systemFile.isFile() || !systemFile.canRead()) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 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
|
264 return null; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 if (!userFile.isFile() || !userFile.canRead()) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 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
|
269 return null; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
272 FileBuilderProvider ufbp = new FileBuilderProvider(userFile); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
273 FileBuilderProvider sfbp = new FileBuilderProvider(systemFile); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
274 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
275 if (ufbp.getBuilder() == null || sfbp.getBuilder() == null) { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
276 log.error("failed loading builder"); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
277 return null; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
278 } |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
279 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
280 BuilderProvider ubp; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
281 BuilderProvider sbp; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
282 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
283 if (DEVELOPMENT_MODE) { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
284 ubp = ufbp; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
285 sbp = sfbp; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
286 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
287 else { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
288 ubp = ufbp.toStaticProvider(); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
289 sbp = sfbp.toStaticProvider(); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
290 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
291 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
292 return new Recommendations(sbp, ubp); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
293 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
294 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
295 protected static Recommendations createRecommendations() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
296 log.debug("Recommendations.createRecommendations"); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
297 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
298 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
|
299 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
|
300 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
301 if (systemPath == null || userPath == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
302 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
|
303 return null; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
304 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
305 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
306 systemPath = Config.replaceConfigDir(systemPath); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
307 userPath = Config.replaceConfigDir(userPath); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
308 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
309 return createRecommendations( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
310 new File(systemPath), |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
311 new File(userPath)); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
312 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
313 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
314 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |