annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/SedimentLoadInfoService.java @ 5273:db196abd16ca

Use lookup table from bedd_height from database in importer.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 13 Mar 2013 16:39:08 +0100
parents b195fede1c3b
children
rev   line source
4297
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.services;
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
3 import java.util.Calendar;
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
4
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
5 import org.apache.log4j.Logger;
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6 import org.w3c.dom.Document;
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7 import org.w3c.dom.Element;
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9 import de.intevation.artifacts.ArtifactNamespaceContext;
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10 import de.intevation.artifacts.CallMeta;
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import de.intevation.artifacts.GlobalContext;
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import de.intevation.artifacts.common.utils.XMLUtils;
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import de.intevation.flys.artifacts.model.minfo.SedimentLoad;
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 import de.intevation.flys.artifacts.model.minfo.SedimentLoadFactory;
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17 public class SedimentLoadInfoService
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18 extends FLYSService
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19 {
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 /** The logger used in this service. */
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 private static Logger logger = Logger.getLogger(SedimentLoadInfoService.class);
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 public static final String RIVER_XPATH = "/art:river/text()";
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 public static final String TYPE_XPATH = "/art:river/art:type/text()";
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 public static final String FROM_XPATH = "/art:river/art:location/art:from/text()";
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 public static final String TO_XPATH = "/art:river/art:location/art:to/text()";
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 @Override
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 protected Document doProcess(
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 Document data,
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 GlobalContext globalContext,
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 CallMeta callMeta) {
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 String river = XMLUtils.xpathString(
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 data,
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 RIVER_XPATH,
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 ArtifactNamespaceContext.INSTANCE);
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 String type = XMLUtils.xpathString(
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 data,
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 TYPE_XPATH,
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 ArtifactNamespaceContext.INSTANCE);
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 String from = XMLUtils.xpathString(
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 data,
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 FROM_XPATH,
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 ArtifactNamespaceContext.INSTANCE);
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 String to = XMLUtils.xpathString(
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 data,
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47 TO_XPATH,
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 ArtifactNamespaceContext.INSTANCE);
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 double f, t;
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 try {
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 f = Double.parseDouble(from);
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 t = Double.parseDouble(to);
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 }
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 catch (NumberFormatException nfe) {
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 logger.warn("Invalid locations. Cannot return sediment loads.");
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 return XMLUtils.newDocument();
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 }
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 SedimentLoad[] loads = SedimentLoadFactory.getLoads(river, type, f, t);
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 return buildDocument(loads);
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 }
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 protected Document buildDocument(SedimentLoad[] loads) {
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 Document result = XMLUtils.newDocument();
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 Element all = result.createElement("sedimentloads");
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 for (SedimentLoad sl : loads) {
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 Element load = result.createElement("sedimentload");
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 load.setAttribute("description", sl.getDescription());
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 if (sl.isEpoch()) {
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 Calendar calendarS = Calendar.getInstance();
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 calendarS.setTime(sl.getStart());
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 Calendar calendarE = Calendar.getInstance();
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 calendarE.setTime(sl.getEnd());
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 load.setAttribute(
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 "date",
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 calendarS.get(Calendar.YEAR) +
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 " - " +
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 calendarE.get(Calendar.YEAR));
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 }
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 else {
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 Calendar calendar = Calendar.getInstance();
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 calendar.setTime(sl.getStart());
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83 load.setAttribute(
4736
b195fede1c3b Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4297
diff changeset
84 "date",
4297
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 String.valueOf(calendar.get(Calendar.YEAR)));
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86 }
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 all.appendChild(load);
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88 }
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 result.appendChild(all);
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 return result;
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91 }
6d44914b2dd4 Added serverside service for sediment load info.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
92 }

http://dive4elements.wald.intevation.org