Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java @ 5827:e308d4ecd35a
Fixed pom for etl process.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 11:48:36 +0200 |
parents | ebec12def170 |
children |
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; |
5590
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
23 import org.hibernate.SessionFactory; |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 import org.hibernate.jdbc.Work; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
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.Config; |
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.XMLUtils; |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
29 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
|
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 |
5590
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
33 import de.intevation.flys.backend.SessionFactoryProvider; |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 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
|
35 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 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
|
37 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 import de.intevation.flys.artifacts.datacage.templating.Builder; |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
39 import de.intevation.flys.artifacts.datacage.templating.BuilderPool; |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 |
3391
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
41 |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
42 /** |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
43 * Also accessible as Singleton with getInstance(). |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
44 */ |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 public class Recommendations |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 { |
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
|
47 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
|
48 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
|
49 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
|
50 |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
51 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
|
52 |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 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
|
54 |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
55 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
|
56 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
|
57 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
58 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
|
59 "/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
|
60 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
61 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
|
62 "${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
|
63 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 private static Recommendations INSTANCE; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
66 public static class BuilderPoolProvider |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
67 { |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
68 protected BuilderPool builderPool; |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
69 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
70 public BuilderPoolProvider() { |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
71 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
72 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
73 public BuilderPoolProvider(BuilderPool builderPool) { |
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
74 this.builderPool = builderPool; |
1030
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 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
77 public BuilderPool getBuilderPool() { |
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
78 return builderPool; |
1030
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 } // class BuilderProvider |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
81 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
82 public static class FileBuilderPoolProvider |
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
83 extends BuilderPoolProvider |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
84 { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
85 protected File file; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
86 protected long lastModified; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
87 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
88 public FileBuilderPoolProvider() { |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
89 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
90 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
91 public FileBuilderPoolProvider(File file) { |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
92 this.file = file; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
93 lastModified = Long.MIN_VALUE; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
94 } |
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 @Override |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
97 public synchronized BuilderPool getBuilderPool() { |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
98 long modified = file.lastModified(); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
99 if (modified > lastModified) { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
100 lastModified = modified; |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
101 try { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
102 Document template = loadTemplate(file); |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
103 builderPool = new BuilderPool(template); |
1030
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 catch (IOException ioe) { |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
106 log.error(ioe); |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
107 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
108 } |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
109 return builderPool; |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
110 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
111 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
112 public BuilderPoolProvider toStaticProvider() { |
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
113 return new BuilderPoolProvider(builderPool); |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
114 } |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
115 } // class BuilderProvider |
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
116 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
117 protected BuilderPoolProvider builderPoolProvider; |
1015
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 public Recommendations() { |
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 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
122 public Recommendations(BuilderPoolProvider builderPoolProvider) { |
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
123 this.builderPoolProvider = builderPoolProvider; |
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 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
126 public BuilderPool getBuilderPool() { |
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
127 return builderPoolProvider.getBuilderPool(); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 protected static void artifactToParameters( |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1716
diff
changeset
|
131 FLYSArtifact artifact, |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 Map<String, Object> parameters |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 ) { |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
134 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
|
135 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
|
136 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 for (StateData sd: artifact.getAllData()) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 Object value = sd.getValue(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 if (value == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 continue; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 } |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
142 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
|
143 parameters.put(key, value); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 |
4528
cbd0fafcb26b
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3391
diff
changeset
|
147 /** |
cbd0fafcb26b
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3391
diff
changeset
|
148 * Put Key/Values from \param src to \param dst, but uppercase |
cbd0fafcb26b
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3391
diff
changeset
|
149 * both Keys and Values. |
cbd0fafcb26b
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3391
diff
changeset
|
150 */ |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 ) { |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
155 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
|
156 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
|
157 } |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
158 } |
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
159 |
3391
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 /** |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
162 * Append recommendations to \param result. |
4528
cbd0fafcb26b
Documentation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3391
diff
changeset
|
163 * @param extraParameters parameters (typicall example: 'recommended') |
3391
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
164 */ |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 public void recommend( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 FLYSArtifact artifact, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 String userId, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 String [] outs, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 Map<String, Object> extraParameters, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 Node result |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 ) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 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
|
173 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 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
|
175 convertKeysToUpperCase(extraParameters, parameters); |
1015
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 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 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
|
179 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
|
180 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 if (artifact != null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 artifactToParameters(artifact, parameters); |
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 |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
186 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
|
187 |
1716
3ca999f507b7
flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1046
diff
changeset
|
188 parameters.put("PARAMETERS", parameters); |
1015
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 recommend(parameters, userId, result); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 |
3391
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 /** |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
195 * Append recommendations to \param result. |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
196 */ |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 public void recommend( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 Map<String, Object> parameters, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 String userId, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 Node result |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 ) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 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
|
203 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 public void recommend( |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 final Map<String, Object> parameters, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 final String userId, |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 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
|
209 Session systemSession |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 ) { |
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
|
211 systemSession.doWork(new Work() { |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 @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
|
213 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
|
214 throws SQLException |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 { |
5590
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
216 SessionFactory sedDBFactory = |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
217 SessionFactoryProvider.getSedDBSessionFactory(); |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
218 |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
219 Session sedDBSession = sedDBFactory.openSession(); |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
220 try { |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
221 sedDBSession.doWork(new Work() { |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
222 @Override |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
223 public void execute(Connection sedDBConnection) |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
224 throws SQLException |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
225 { |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
226 recommend( |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
227 parameters, userId, result, |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
228 systemConnection, |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
229 sedDBConnection); |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
230 } |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
231 }); |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
232 } |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
233 finally { |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
234 sedDBSession.close(); |
b75005269a6c
Datacage: Fix potential connection leak to SedDB.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5588
diff
changeset
|
235 } |
1015
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 }); |
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 |
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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 ) 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
|
247 { |
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 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
|
249 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
|
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 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
|
252 ? 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
|
253 .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
|
254 .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
|
255 .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
|
256 .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
|
257 : 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
|
258 |
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 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
|
260 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
|
261 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
|
262 |
5588
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
263 if (seddbConnection != null) { |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
264 connections.add(new Builder.NamedConnection( |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
265 CONNECTION_SEDDB, seddbConnection, true)); |
3e8f7b4bdf20
Don't use SedDB in Datacage (temp fix)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5531
diff
changeset
|
266 } |
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
|
267 |
ac48ab9e1715
Datacage: Added connection to SedDB. Use <dc:context connection="seddb"> to use it.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4528
diff
changeset
|
268 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
|
269 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
|
270 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
|
271 } |
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 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
273 getBuilderPool().build(connections, result, parameters); |
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
|
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 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
|
276 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
|
277 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
|
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 } |
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 } |
3391
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
281 |
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
282 /** Get singleton instance. */ |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
283 public static synchronized Recommendations getInstance() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
284 if (INSTANCE == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
285 INSTANCE = createRecommendations(); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
286 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
287 return INSTANCE; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
288 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
289 |
3391
2b3c4abe034f
Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
3076
diff
changeset
|
290 |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
291 protected static Document loadTemplate(File file) throws IOException { |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
292 InputStream in = new FileInputStream(file); |
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 try { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
295 Document template = XMLUtils.parseDocument(in); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
296 if (template == null) { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
297 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
|
298 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
299 return 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 finally { |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
302 in.close(); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
303 } |
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 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
306 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
|
307 log.debug("Recommendations.createBuilder"); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
308 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
309 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
|
310 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
|
311 return null; |
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 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
314 FileBuilderPoolProvider fbp = new FileBuilderPoolProvider(file); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
315 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
316 if (fbp.getBuilderPool() == null) { |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
317 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
|
318 return null; |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
319 } |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
320 |
5779
ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5593
diff
changeset
|
321 BuilderPoolProvider bp = DEVELOPMENT_MODE |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
322 ? fbp |
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
323 : fbp.toStaticProvider(); |
1030
c586b6220f35
Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1029
diff
changeset
|
324 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
325 return new Recommendations(bp); |
1015
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 |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
328 protected static Recommendations createRecommendations() { |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
329 log.debug("Recommendations.createRecommendations"); |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
330 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
331 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
|
332 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
333 if (path == null) { |
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
334 path = DEFAULT_TEMPLATE_PATH; |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
335 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
336 |
1046
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
337 path = Config.replaceConfigDir(path); |
1015
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
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 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
|
340 |
0a5eff5511b1
Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1030
diff
changeset
|
341 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
|
342 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
343 } |
9a1a3080ad98
Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
344 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |