Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java @ 377:0ccf7200fc51
Enabled the server to handle longitudinal section chart requests with inserted W data - Ws are transformed into Qs then.
flys-artifacts/trunk@1789 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 02 May 2011 12:47:10 +0000 |
parents | fc3cf0ef777e |
children | 7c018f466d6d |
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.io.InputStream; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import java.io.IOException; |
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 java.sql.Connection; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.sql.SQLException; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import org.w3c.dom.Document; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import org.apache.log4j.Logger; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.artifacts.CallMeta; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.artifacts.ServiceFactory; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.artifactdatabase.DefaultService; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 import de.intevation.artifacts.common.utils.XMLUtils; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.flys.artifacts.services.meta.Builder; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.flys.backend.SessionHolder; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 import org.hibernate.Session; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 import org.hibernate.jdbc.Work; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 public class MetaDataService |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 extends DefaultService |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 private static Logger log = Logger.getLogger(MetaDataService.class); |
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 public static final String META_DATA_TEMPLATE = "/metadata/template.xml"; |
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 protected Builder builder; |
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 MetaDataService() { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 } |
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 @Override |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 public Document process( |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 Document data, |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 Object globalContext, |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 CallMeta callMeta |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 ) { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 log.debug("MetaDataService.process"); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 final Document result = XMLUtils.newDocument(); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 if (builder == null) { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 log.error("MetaDataService is not setup properly."); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 return result; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 } |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 Session session = SessionHolder.acquire(); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 try { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 session.doWork(new Work() { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 @Override |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 public void execute(Connection connection) |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 throws SQLException |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 log.debug("MetaDataService.execute"); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 builder.build(connection, result); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 } |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 }); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 } |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 finally { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 session.close(); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 SessionHolder.release(); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 } |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 return result; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 } |
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 @Override |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 public void setup(ServiceFactory factory, Object globalContext) { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 log.debug("MetaDataService.setup"); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 InputStream in = getClass().getResourceAsStream(META_DATA_TEMPLATE); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 if (in == null) { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 log.error("cannot get template resource"); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 return; |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 } |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 try { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 Document template = XMLUtils.parseDocument(in); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 if (template == null) { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 log.error("cannot parse meta data template"); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 } |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 else { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 builder = new Builder(template); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 } |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 finally { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 try { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 in.close(); |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 } |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 catch (IOException ioe) { |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 log.error(ioe); |
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 } |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 } |
fc3cf0ef777e
Added meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |