annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java @ 5669:dc731d2937f9

Added basedata and old calculations to middle bedheight dc and added new macros.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 12 Apr 2013 09:41:56 +0200
parents cf4cc385e7c6
children ebec12def170
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;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
3391
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 /**
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
42 * Also accessible as Singleton with getInstance().
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
43 */
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 public class Recommendations
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 {
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
46 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
47 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
48 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
49
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 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
51
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 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
53
1030
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
54 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
55 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
56
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
57 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
58 "/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
59
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
60 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
61 "${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
62
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 private static Recommendations INSTANCE;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
1030
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
65 public static class BuilderProvider
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
66 {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
67 protected Builder builder;
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
68
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
69 public BuilderProvider() {
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
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
72 public BuilderProvider(Builder builder) {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
73 this.builder = builder;
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
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
76 public Builder getBuilder() {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
77 return builder;
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
78 }
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
79 } // class BuilderProvider
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
80
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
81 public static class FileBuilderProvider
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
82 extends BuilderProvider
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
83 {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
84 protected File file;
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
85 protected long lastModified;
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
86
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
87 public FileBuilderProvider() {
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
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
90 public FileBuilderProvider(File file) {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
91 this.file = file;
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
92 lastModified = Long.MIN_VALUE;
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
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
95 @Override
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
96 public synchronized Builder getBuilder() {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
97 long modified = file.lastModified();
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
98 if (modified > lastModified) {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
99 lastModified = modified;
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
100 try {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
101 Document template = loadTemplate(file);
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
102 builder = new Builder(template);
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
103 }
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
104 catch (IOException ioe) {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
105 log.error(ioe);
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 }
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
108 return builder;
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
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
111 public BuilderProvider toStaticProvider() {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
112 return new BuilderProvider(builder);
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
113 }
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
114 } // class BuilderProvider
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
115
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
116 protected BuilderProvider builderProvider;
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 public Recommendations() {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
121 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
122 this.builderProvider = builderProvider;
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
125 public Builder getBuilder() {
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
126 return builderProvider.getBuilder();
1015
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
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 protected static void artifactToParameters(
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
130 FLYSArtifact artifact,
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 Map<String, Object> parameters
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132 ) {
1716
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1046
diff changeset
133 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
134 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
135
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 for (StateData sd: artifact.getAllData()) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137 Object value = sd.getValue();
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 if (value == null) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 continue;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140 }
1716
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1046
diff changeset
141 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
142 parameters.put(key, value);
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 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145
4528
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 /**
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
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
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 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
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 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
277 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
278 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
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 }
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 }
3391
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
282
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
283 /** Get singleton instance. */
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
284 public static synchronized Recommendations getInstance() {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
285 if (INSTANCE == null) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
286 INSTANCE = createRecommendations();
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
287 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
288 return INSTANCE;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
289 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
290
3391
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
291
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
292 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
293 InputStream in = null;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
294
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
295 try {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
296 in = new FileInputStream(file);
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 Document template = XMLUtils.parseDocument(in);
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
299
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
300 if (template == null) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
301 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
302 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
303 return template;
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 finally {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
306 if (in != null) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
307 try {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
308 in.close();
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
309 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
310 catch (IOException ioe) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
311 log.error(ioe);
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
312 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
313 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
314 }
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
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
317 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
318 log.debug("Recommendations.createBuilder");
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 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
321 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
322 return null;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
323 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
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 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
326
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
327 if (fbp.getBuilder() == null) {
1030
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
328 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
329 return null;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
330 }
1030
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
331
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
332 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
333 ? fbp
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
334 : fbp.toStaticProvider();
1030
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
335
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
336 return new Recommendations(bp);
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
337 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
338
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
339 protected static Recommendations createRecommendations() {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
340 log.debug("Recommendations.createRecommendations");
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
341
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
342 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
343
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
344 if (path == null) {
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
345 path = DEFAULT_TEMPLATE_PATH;
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
346 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
347
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
348 path = Config.replaceConfigDir(path);
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
349
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
350 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
351
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
352 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
353 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
354 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
355 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org