annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/Recommendations.java @ 3572:b8b1280606c2

Removed superfluous imports. flys-artifacts/trunk@5179 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 09 Aug 2012 08:04:06 +0000
parents 2b3c4abe034f
children cbd0fafcb26b
rev   line source
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.datacage;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.util.Map;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import java.util.HashMap;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import java.util.List;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.util.ArrayList;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import java.io.InputStream;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 import java.io.IOException;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import java.io.File;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import java.io.FileInputStream;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 import java.sql.Connection;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import java.sql.SQLException;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 import org.apache.log4j.Logger;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 import org.w3c.dom.Document;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 import org.w3c.dom.Node;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 import org.hibernate.Session;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 import org.hibernate.jdbc.Work;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 import de.intevation.artifacts.common.utils.Config;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 import de.intevation.artifacts.common.utils.XMLUtils;
1716
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1046
diff changeset
28 import de.intevation.artifacts.common.utils.StringUtils;
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 import de.intevation.flys.artifacts.FLYSArtifact;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 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
33
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 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
35
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 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
37
3391
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
38
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
39 /**
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
40 * Also accessible as Singleton with getInstance().
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
41 */
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 public class Recommendations
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 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
45
1030
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
46 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
47 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
48
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
49 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
50 "/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
51
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
52 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
53 "${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
54
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 private static Recommendations INSTANCE;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
1030
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
57 public static class BuilderProvider
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
58 {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
59 protected Builder builder;
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
60
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
61 public BuilderProvider() {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
62 }
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
63
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
64 public BuilderProvider(Builder builder) {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
65 this.builder = builder;
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
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
68 public Builder getBuilder() {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
69 return builder;
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 } // class BuilderProvider
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
72
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
73 public static class FileBuilderProvider
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
74 extends BuilderProvider
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 protected File file;
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
77 protected long lastModified;
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
78
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
79 public FileBuilderProvider() {
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
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
82 public FileBuilderProvider(File file) {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
83 this.file = file;
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
84 lastModified = Long.MIN_VALUE;
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
85 }
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
86
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
87 @Override
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
88 public synchronized Builder getBuilder() {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
89 long modified = file.lastModified();
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
90 if (modified > lastModified) {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
91 lastModified = modified;
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
92 try {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
93 Document template = loadTemplate(file);
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
94 builder = new Builder(template);
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 catch (IOException ioe) {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
97 log.error(ioe);
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
98 }
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
99 }
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
100 return builder;
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
101 }
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
102
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
103 public BuilderProvider toStaticProvider() {
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
104 return new BuilderProvider(builder);
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
105 }
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
106 } // class BuilderProvider
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
107
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
108 protected BuilderProvider builderProvider;
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 public Recommendations() {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
113 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
114 this.builderProvider = builderProvider;
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
117 public Builder getBuilder() {
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
118 return builderProvider.getBuilder();
1015
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
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121 protected static void artifactToParameters(
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1716
diff changeset
122 FLYSArtifact artifact,
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 Map<String, Object> parameters
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 ) {
1716
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1046
diff changeset
125 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
126 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
127
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128 for (StateData sd: artifact.getAllData()) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 Object value = sd.getValue();
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130 if (value == null) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 continue;
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 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
134 parameters.put(key, value);
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 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137
1716
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1046
diff changeset
138 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
139 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
140 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
141 ) {
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1046
diff changeset
142 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
143 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
144 }
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1046
diff changeset
145 }
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1046
diff changeset
146
3391
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
147
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
148 /**
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
149 * Append recommendations to \param result.
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
150 */
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 public void recommend(
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 FLYSArtifact artifact,
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 String userId,
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 String [] outs,
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 Map<String, Object> extraParameters,
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 Node result
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 ) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 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
159
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 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
161 convertKeysToUpperCase(extraParameters, parameters);
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 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
165 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
166 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 if (artifact != null) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169 artifactToParameters(artifact, parameters);
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171
1716
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1046
diff changeset
172 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
173
1716
3ca999f507b7 flys/issue314: Variables in datacage are now case insensitive.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1046
diff changeset
174 parameters.put("PARAMETERS", parameters);
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 recommend(parameters, userId, result);
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
3391
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
179
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
180 /**
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
181 * Append recommendations to \param result.
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
182 */
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 public void recommend(
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 Map<String, Object> parameters,
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 String userId,
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 Node result
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 ) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188 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
189 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191 public void recommend(
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 final Map<String, Object> parameters,
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
193 final String userId,
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
194 final Node result,
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195 Session session
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 ) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 session.doWork(new Work() {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198 @Override
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
199 public void execute(Connection systemConnection)
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
200 throws SQLException
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 List<Builder.NamedConnection> connections =
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
203 new ArrayList<Builder.NamedConnection>(2);
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
204
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
205 Connection userConnection = userId != null
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
206 ? DBConfig
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
207 .getInstance()
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
208 .getDBConnection()
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
209 .getDataSource()
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
210 .getConnection()
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
211 : null;
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
212
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
213 try {
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
214 if (userConnection != null) {
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
215 connections.add(new Builder.NamedConnection(
1022
930a9ce24294 Datacage: Fixed caching issue leading to incorrect results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1018
diff changeset
216 Builder.CONNECTION_USER, userConnection, false));
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
217 }
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
218
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
219 connections.add(new Builder.NamedConnection(
1022
930a9ce24294 Datacage: Fixed caching issue leading to incorrect results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1018
diff changeset
220 Builder.CONNECTION_SYSTEM, systemConnection, true));
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
221
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
222 getBuilder().build(connections, result, parameters);
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
223 }
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
224 finally {
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
225 if (userConnection != null) {
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
226 userConnection.close();
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
227 }
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
228 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
229 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
230 });
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
231 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
232
3391
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
233
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
234 /** Get singleton instance. */
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
235 public static synchronized Recommendations getInstance() {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
236 if (INSTANCE == null) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
237 INSTANCE = createRecommendations();
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 return INSTANCE;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
240 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
241
3391
2b3c4abe034f Doc, TODO added.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3076
diff changeset
242
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
243 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
244 InputStream in = null;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
245
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
246 try {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
247 in = new FileInputStream(file);
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
248
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
249 Document template = XMLUtils.parseDocument(in);
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
250
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
251 if (template == null) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
252 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
253 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
254 return template;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
255 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
256 finally {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
257 if (in != null) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
258 try {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
259 in.close();
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
260 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
261 catch (IOException ioe) {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
262 log.error(ioe);
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
263 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
264 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
265 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
266 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
267
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
268 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
269 log.debug("Recommendations.createBuilder");
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
270
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
271 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
272 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
273 return null;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
274 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
275
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
276 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
277
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
278 if (fbp.getBuilder() == null) {
1030
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
279 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
280 return null;
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
281 }
1030
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
282
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
283 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
284 ? fbp
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
285 : fbp.toStaticProvider();
1030
c586b6220f35 Datacage: Added a development mode for recommendations
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1029
diff changeset
286
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
287 return new Recommendations(bp);
1015
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
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
290 protected static Recommendations createRecommendations() {
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
291 log.debug("Recommendations.createRecommendations");
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
292
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
293 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
294
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
295 if (path == null) {
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
296 path = DEFAULT_TEMPLATE_PATH;
1015
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
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
299 path = Config.replaceConfigDir(path);
1015
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
300
1046
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
301 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
302
0a5eff5511b1 Fixed flys/issue262: Unified user and system datacage template
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1030
diff changeset
303 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
304 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
305 }
9a1a3080ad98 Bring user specific meta data service to life.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
306 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org