Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java @ 5589:1827798ca53f
Added tag 2.9.17 for changeset 3e8f7b4bdf20
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 08 Apr 2013 11:24:39 +0200 |
parents | 3e8f7b4bdf20 |
children | b75005269a6c |
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 org.apache.log4j.Logger; |
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.w3c.dom.Document; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 import org.w3c.dom.Node; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 import org.hibernate.Session; |
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.jdbc.Work; |
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 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
|
27 import de.intevation.artifacts.common.utils.XMLUtils; |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
28 import de.intevation.artifacts.common.utils.StringUtils; |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 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
|
31 |
5531
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
32 import de.intevation.flys.backend.SedDBSessionHolder; |
1015
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 |
3391
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
39 |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
40 /** |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
41 * Also accessible as Singleton with getInstance(). |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
42 */ |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 public class Recommendations |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 { |
5531
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
45 public static final String CONNECTION_USER = "user"; |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
46 public static final String CONNECTION_SYSTEM = "system"; |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
47 public static final String CONNECTION_SEDDB = "seddb"; |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
48 |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
49 public static final String DEFAULT_CONNECTION_NAME = CONNECTION_SYSTEM; |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
50 |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 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
|
52 |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
53 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
|
54 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
|
55 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
56 public static final String XPATH_TEMPLATE = |
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
57 "/artifact-database/metadata/template/text()"; |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
59 public static final String DEFAULT_TEMPLATE_PATH = |
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
60 "${artifacts.config.dir}/meta-data.xml"; |
1015
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 private static Recommendations INSTANCE; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
64 public static class BuilderProvider |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
65 { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
66 protected Builder 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 public 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 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
71 public BuilderProvider(Builder builder) { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
72 this.builder = builder; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
73 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
74 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
75 public Builder getBuilder() { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
76 return builder; |
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 } // class BuilderProvider |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
79 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
80 public static class FileBuilderProvider |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
81 extends BuilderProvider |
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 protected File file; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
84 protected long lastModified; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
85 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
86 public FileBuilderProvider() { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
87 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
88 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
89 public FileBuilderProvider(File file) { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
90 this.file = file; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
91 lastModified = Long.MIN_VALUE; |
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 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
94 @Override |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
95 public synchronized Builder getBuilder() { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
96 long modified = file.lastModified(); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
97 if (modified > lastModified) { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
98 lastModified = modified; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
99 try { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
100 Document template = loadTemplate(file); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
101 builder = new Builder(template); |
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 catch (IOException ioe) { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
104 log.error(ioe); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
105 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
106 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
107 return builder; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
108 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
109 |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
110 public BuilderProvider toStaticProvider() { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
111 return new BuilderProvider(builder); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
112 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
113 } // class BuilderProvider |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
114 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
115 protected BuilderProvider builderProvider; |
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 public Recommendations() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
120 public Recommendations(BuilderProvider builderProvider) { |
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
121 this.builderProvider = builderProvider; |
1015
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 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
124 public Builder getBuilder() { |
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
125 return builderProvider.getBuilder(); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 protected static void artifactToParameters( |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1716
diff
changeset
|
129 FLYSArtifact artifact, |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 Map<String, Object> parameters |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 ) { |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
132 parameters.put("CURRENT-STATE-ID", artifact.getCurrentStateId()); |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
133 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
|
134 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 for (StateData sd: artifact.getAllData()) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 Object value = sd.getValue(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 if (value == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 continue; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 } |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
140 String key = sd.getName().replace('.', '-').toUpperCase(); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 parameters.put(key, value); |
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 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 |
4528
cbd0fafcb26b
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3391
diff
changeset
|
145 |
cbd0fafcb26b
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3391
diff
changeset
|
146 /** |
cbd0fafcb26b
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3391
diff
changeset
|
147 * Put Key/Values from \param src to \param dst, but uppercase |
cbd0fafcb26b
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3391
diff
changeset
|
148 * both Keys and Values. |
cbd0fafcb26b
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3391
diff
changeset
|
149 */ |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
150 public static void convertKeysToUpperCase( |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
151 Map<String, Object> src, |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
152 Map<String, Object> dst |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
153 ) { |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
154 for (Map.Entry<String, Object> entry: src.entrySet()) { |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
155 dst.put(entry.getKey().toUpperCase(), entry.getValue()); |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
156 } |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
157 } |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
158 |
3391
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
159 |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
160 /** |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
161 * Append recommendations to \param result. |
4528
cbd0fafcb26b
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3391
diff
changeset
|
162 * @param extraParameters parameters (typicall example: 'recommended') |
3391
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
163 */ |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 public void recommend( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 FLYSArtifact artifact, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 String userId, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 String [] outs, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 Map<String, Object> extraParameters, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 Node result |
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 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
|
172 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 if (extraParameters != null) { |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
174 convertKeysToUpperCase(extraParameters, parameters); |
1015
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 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 if (userId != null) { |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
178 parameters.put("USER-ID", userId); |
1015
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 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 if (artifact != null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 artifactToParameters(artifact, parameters); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
185 parameters.put("ARTIFACT-OUTS", StringUtils.toUpperCase(outs)); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
187 parameters.put("PARAMETERS", parameters); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 recommend(parameters, userId, result); |
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 |
3391
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
192 |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
193 /** |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
194 * Append recommendations to \param result. |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
195 */ |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 public void recommend( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 Map<String, Object> parameters, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 String userId, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 Node result |
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 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
|
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 public void recommend( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 final Map<String, Object> parameters, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 final String userId, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 final Node result, |
5531
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
208 Session systemSession |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 ) { |
5531
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
210 systemSession.doWork(new Work() { |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 @Override |
5531
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
212 public void execute(final Connection systemConnection) |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 throws SQLException |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 { |
5588
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
215 recommend( |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
216 parameters, userId, result, |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
217 systemConnection, |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
218 (Connection)null); |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
219 } |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
220 }); |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
221 /* |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
222 systemSession.doWork(new Work() { |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
223 @Override |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
224 public void execute(final Connection systemConnection) |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
225 throws SQLException |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
226 { |
5531
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
227 SedDBSessionHolder.HOLDER.get().doWork(new Work() { |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
228 @Override |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
229 public void execute(Connection sedDBConnection) |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
230 throws SQLException |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
231 { |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
232 recommend( |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
233 parameters, userId, result, |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
234 systemConnection, |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
235 sedDBConnection); |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
236 } |
5531
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
237 }); |
1015
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 }); |
5588
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
240 */ |
1015
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 |
5531
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
243 public void recommend( |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
244 Map<String, Object> parameters, |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
245 String userId, |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
246 Node result, |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
247 Connection systemConnection, |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
248 Connection seddbConnection |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
249 ) throws SQLException |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
250 { |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
251 List<Builder.NamedConnection> connections = |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
252 new ArrayList<Builder.NamedConnection>(3); |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
253 |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
254 Connection userConnection = userId != null |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
255 ? DBConfig |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
256 .getInstance() |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
257 .getDBConnection() |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
258 .getDataSource() |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
259 .getConnection() |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
260 : null; |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
261 |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
262 try { |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
263 connections.add(new Builder.NamedConnection( |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
264 CONNECTION_SYSTEM, systemConnection, true)); |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
265 |
5588
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
266 if (seddbConnection != null) { |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
267 connections.add(new Builder.NamedConnection( |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
268 CONNECTION_SEDDB, seddbConnection, true)); |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
269 } |
5531
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
270 |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
271 if (userConnection != null) { |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
272 connections.add(new Builder.NamedConnection( |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
273 CONNECTION_USER, userConnection, false)); |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
274 } |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
275 |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
276 |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
277 getBuilder().build(connections, result, parameters); |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
278 } |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
279 finally { |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
280 if (userConnection != null) { |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
281 userConnection.close(); |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
282 } |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
283 } |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
284 } |
3391
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
285 |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
286 /** Get singleton instance. */ |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
287 public static synchronized Recommendations getInstance() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
288 if (INSTANCE == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
289 INSTANCE = createRecommendations(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
290 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
291 return INSTANCE; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
292 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
293 |
3391
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
294 |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
295 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
|
296 InputStream in = null; |
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 try { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
299 in = new FileInputStream(file); |
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 Document template = XMLUtils.parseDocument(in); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
302 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
303 if (template == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
304 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
|
305 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
306 return template; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
307 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
308 finally { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
309 if (in != null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
310 try { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
311 in.close(); |
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 catch (IOException ioe) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
314 log.error(ioe); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
315 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
316 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
317 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
318 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
319 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
320 public static Recommendations createRecommendations(File file) { |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
321 log.debug("Recommendations.createBuilder"); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
322 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
323 if (!file.isFile() || !file.canRead()) { |
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
324 log.error("Cannot open template file '" + file + "'"); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
325 return null; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
326 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
327 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
328 FileBuilderProvider fbp = new FileBuilderProvider(file); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
329 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
330 if (fbp.getBuilder() == null) { |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
331 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
|
332 return null; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
333 } |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
334 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
335 BuilderProvider bp = DEVELOPMENT_MODE |
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
336 ? fbp |
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
337 : fbp.toStaticProvider(); |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
338 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
339 return new Recommendations(bp); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
340 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
341 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
342 protected static Recommendations createRecommendations() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
343 log.debug("Recommendations.createRecommendations"); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
344 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
345 String path = Config.getStringXPath(XPATH_TEMPLATE); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
346 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
347 if (path == null) { |
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
348 path = DEFAULT_TEMPLATE_PATH; |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
349 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
350 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
351 path = Config.replaceConfigDir(path); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
352 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
353 log.info("Meta data template: " + path); |
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
354 |
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
355 return createRecommendations(new File(path)); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
356 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
357 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
358 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |