annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java @ 1009:fc5fca0c33b3

Datacage: Set the name of the collections at initial scan, too. flys-artifacts/trunk@2454 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 02 Aug 2011 14:09:01 +0000
parents b81626b10cb7
children 9a1a3080ad98
rev   line source
372
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.services;
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.sql.Connection;
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import java.sql.SQLException;
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import org.w3c.dom.Document;
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import org.apache.log4j.Logger;
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
415
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
10 import java.util.Map;
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
11 import java.util.HashMap;
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
12
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
13 import de.intevation.artifacts.Artifact;
372
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 import de.intevation.artifacts.CallMeta;
966
a63d79107289 Adjusted services to implement changed signature.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 950
diff changeset
15 import de.intevation.artifacts.GlobalContext;
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
16 import de.intevation.artifacts.ArtifactDatabase;
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
17 import de.intevation.artifacts.ArtifactDatabaseException;
372
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 import de.intevation.artifactdatabase.DefaultService;
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 import de.intevation.artifacts.common.utils.XMLUtils;
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
22 import de.intevation.artifacts.common.utils.StringUtils;
372
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
421
24b53f9aa9dc MetaDataService: Make incoming XML symmetric to DistanceInfoService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 415
diff changeset
24 import de.intevation.artifacts.common.ArtifactNamespaceContext;
24b53f9aa9dc MetaDataService: Make incoming XML symmetric to DistanceInfoService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 415
diff changeset
25
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 975
diff changeset
26 import de.intevation.flys.artifacts.datacage.templating.Builder;
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 975
diff changeset
27 import de.intevation.flys.artifacts.datacage.templating.NoneUserSpecific;
372
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
29 import de.intevation.flys.artifacts.FLYSArtifact;
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
30
372
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 import de.intevation.flys.backend.SessionHolder;
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 import org.hibernate.Session;
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 import org.hibernate.jdbc.Work;
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 public class MetaDataService
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 extends DefaultService
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 {
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 private static Logger log = Logger.getLogger(MetaDataService.class);
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41
969
2c8fc60125b9 Meta data template: Allow '-' in variable names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 966
diff changeset
42 // old service. To be removed
421
24b53f9aa9dc MetaDataService: Make incoming XML symmetric to DistanceInfoService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 415
diff changeset
43 public static final String XPATH_RIVER = "/art:river/text()";
415
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
44
974
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
45 public static final String XPATH_UUID = "/art:meta/art:uuid/@value";
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
46 public static final String XPATH_OUTS = "/art:meta/art:outs/@value";
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
47 public static final String XPATH_PARAMETERS = "/art:meta/art:parameters/@value";
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
48 public static final String XPATH_FILTERS = "/art:meta/art:filters/@value";
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
49
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
50 /** The global context key of the artifact database */
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
51 public static final String ARTIFACT_DATA_BASE_KEY =
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
52 "global.artifact.database";
969
2c8fc60125b9 Meta data template: Allow '-' in variable names.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 966
diff changeset
53
372
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 public MetaDataService() {
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 }
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
415
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
57 protected static Map<String, Object> extractParameters(Document data) {
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
58 HashMap<String, Object> parameters = new HashMap<String, Object>();
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
59
421
24b53f9aa9dc MetaDataService: Make incoming XML symmetric to DistanceInfoService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 415
diff changeset
60 String river = XMLUtils.xpathString(
24b53f9aa9dc MetaDataService: Make incoming XML symmetric to DistanceInfoService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 415
diff changeset
61 data, XPATH_RIVER, ArtifactNamespaceContext.INSTANCE);
415
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
62
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
63 if (river == null || (river = river.trim()).length() == 0) {
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
64 river = "%"; // matches all rivers
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
65 }
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
66
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
67 parameters.put("river", river);
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
68
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
69 return parameters;
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
70 }
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
71
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
72 /** The old service. To be removed. */
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
73 protected Document oldService(Document data) {
372
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 final Document result = XMLUtils.newDocument();
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 975
diff changeset
77 final Builder builder = NoneUserSpecific.getInstance().getBuilder();
950
22bc87a42a0d First step to factor out the "Datenkorb" logic into a service independent singleton.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 948
diff changeset
78
372
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 if (builder == null) {
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 log.error("MetaDataService is not setup properly.");
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 return result;
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 }
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83
415
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
84 final Map<String, Object> parameters = extractParameters(data);
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
85
372
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 Session session = SessionHolder.acquire();
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 try {
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 session.doWork(new Work() {
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 @Override
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 public void execute(Connection connection)
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 throws SQLException
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 {
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 log.debug("MetaDataService.execute");
415
7c018f466d6d Datacage: Added river parameter to meta data services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 372
diff changeset
94 builder.build(connection, result, parameters);
372
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 }
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 });
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 }
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 finally {
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 session.close();
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 SessionHolder.release();
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 }
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 return result;
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 }
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
105
974
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
106 protected static Map<String, Object> parameters(
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
107 String parameters,
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
108 Map<String, Object> data
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
109 ) {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
110 if (parameters != null) {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
111 String [] parts = parameters.split("\\s*;\\s*");
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
112 for (String part: parts) {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
113 String [] kv = part.split("\\s*:\\s*");
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
114 if (kv.length < 2 || (kv[0] = kv[0].trim()).length() == 0) {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
115 continue;
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
116 }
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
117 String [] values = kv[1].split("\\s*,\\s*");
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
118 data.put(kv[0], values.length == 1 ? values[0] : values);
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
119 }
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
120 }
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
121 return data;
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
122 }
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
123
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
124 protected static Map<String, Object> filters(
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
125 String filters,
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
126 Map<String, Object> data
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
127 ) {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
128 if (filters != null) {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
129 for (String filter: filters.split("\\s*,\\*s")) {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
130 data.put(filter, "true");
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
131 }
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
132 }
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
133 return data;
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
134 }
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
135
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
136 protected Document newService(
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
137 String uuid,
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
138 String outsString,
974
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
139 String parameters,
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
140 String filters,
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
141 GlobalContext globalContext
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
142 ) {
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
143 Document result = XMLUtils.newDocument();
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
144
974
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
145 FLYSArtifact flysArtifact;
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
146
975
a111f0984706 meta data service: Added 'if log.isDebugEnabled() {}'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 974
diff changeset
147 if (log.isDebugEnabled()) {
a111f0984706 meta data service: Added 'if log.isDebugEnabled() {}'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 974
diff changeset
148 log.debug("uuid: " + uuid);
a111f0984706 meta data service: Added 'if log.isDebugEnabled() {}'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 974
diff changeset
149 log.debug("outs: " + outsString);
a111f0984706 meta data service: Added 'if log.isDebugEnabled() {}'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 974
diff changeset
150 log.debug("filters: " + filters);
a111f0984706 meta data service: Added 'if log.isDebugEnabled() {}'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 974
diff changeset
151 }
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
152
974
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
153 if (uuid != null && uuid.length() != 0) {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
154 if (!StringUtils.checkUUID(uuid)) {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
155 log.warn("'" + uuid + "' is not a UUID");
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
156 return result;
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
157 }
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
158
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
159 Object dbObject =
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
160 (ArtifactDatabase)globalContext.get(ARTIFACT_DATA_BASE_KEY);
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
161
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
162 if (!(dbObject instanceof ArtifactDatabase)) {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
163 log.error("Cannot find artifact database");
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
164 return result;
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
165 }
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
166
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
167 ArtifactDatabase db = (ArtifactDatabase)dbObject;
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
168
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
169 Artifact artifact;
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
170
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
171 try {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
172 artifact = db.getRawArtifact(uuid);
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
173 }
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
174 catch (ArtifactDatabaseException adbe) {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
175 log.warn("fetching artifact failed", adbe);
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
176 return result;
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
177 }
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
178
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
179 if (!(artifact instanceof FLYSArtifact)) {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
180 log.warn("artifact is not a FLYS artifact.");
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
181 return result;
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
182 }
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
183
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
184 flysArtifact = (FLYSArtifact)artifact;
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
185 }
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
186 else {
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
187 flysArtifact = null;
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
188 }
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
189
974
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
190 Map<String, Object> data =
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
191 filters(filters,
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
192 parameters(parameters,
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
193 new HashMap<String, Object>()));
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
194
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
195 String [] outs = outsString.split("\\s*,\\s*");
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
196
998
b81626b10cb7 Datacage: Moved templating in a better suited package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 975
diff changeset
197 NoneUserSpecific dc = NoneUserSpecific.getInstance();
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
198
974
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
199 dc.recommend(flysArtifact, outs, data, result);
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
200
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
201 return result;
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
202 }
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
203
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
204 @Override
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
205 public Document process(
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
206 Document data,
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
207 GlobalContext globalContext,
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
208 CallMeta callMeta
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
209 ) {
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
210 log.debug("MetaDataService.process");
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
211
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
212 String uuid = XMLUtils.xpathString(
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
213 data, XPATH_UUID, ArtifactNamespaceContext.INSTANCE);
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
214
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
215 String outs = XMLUtils.xpathString(
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
216 data, XPATH_OUTS, ArtifactNamespaceContext.INSTANCE);
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
217
974
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
218 String parameters = XMLUtils.xpathString(
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
219 data, XPATH_PARAMETERS, ArtifactNamespaceContext.INSTANCE);
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
220
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
221 String filters = XMLUtils.xpathString(
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
222 data, XPATH_FILTERS, ArtifactNamespaceContext.INSTANCE);
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
223
974
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
224 return outs != null
30c85cb33a50 meta data service: made artifact optional and allow passing extra parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 970
diff changeset
225 ? newService(uuid, outs, parameters, filters, globalContext)
970
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
226 : oldService(data);
e456aca4eb7b meta data service: Adjusted to use the DataCage recommendations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 969
diff changeset
227 }
372
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
228 }
fc3cf0ef777e Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
229 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org