comparison flys-backend/src/main/java/de/intevation/flys/backend/SpatialInfo.java @ 3471:e4250c6e1538 2.8.1

merged flys-backend/2.8.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:40 +0200
parents 8df746f374cc
children 1d95391d056b
comparison
equal deleted inserted replaced
3468:f37e7e8907cb 3471:e4250c6e1538
1 package de.intevation.flys.backend;
2
3 import java.util.List;
4
5 import org.apache.log4j.Logger;
6
7 import org.hibernate.Query;
8 import org.hibernate.Session;
9
10 import de.intevation.flys.model.Building;
11 import de.intevation.flys.model.CrossSectionTrack;
12 import de.intevation.flys.model.Fixpoint;
13 import de.intevation.flys.model.Line;
14 import de.intevation.flys.model.River;
15 import de.intevation.flys.model.RiverAxis;
16
17
18 public class SpatialInfo {
19
20 private static Logger logger = Logger.getLogger(SpatialInfo.class);
21
22 protected static String RIVERNAME = System.getProperty(
23 "flys.backend.spatial.river", "Saar");
24
25 protected Session session;
26
27
28 public static void main(String[] args) {
29 logger.info("Start SpatialInfo application.");
30
31 SpatialInfo spatial = null;
32
33 try {
34 spatial = new SpatialInfo();
35
36 River river = spatial.getRiver(RIVERNAME);
37 if (river == null) {
38 logger.warn("Could not find river '" + RIVERNAME + "'!");
39 return;
40 }
41
42 logger.info("Spatial information of River '" + RIVERNAME + "'");
43 spatial.doRiverAxisInfo(river);
44 spatial.doCrossSectionTracksInfo(river);
45 spatial.doLinesInfo(river);
46 spatial.doBuildingsInfo(river);
47 spatial.doFixpointsInfo(river);
48 }
49 finally {
50 if (spatial != null) {
51 spatial.close();
52 }
53 }
54
55 logger.info("Finish SpatialInfo application.");
56 }
57
58
59 public SpatialInfo() {
60 session = SessionFactoryProvider
61 .createSessionFactory()
62 .openSession();
63 }
64
65
66 public void close() {
67 session.close();
68 }
69
70
71 protected River getRiver(String rivername) {
72 Query query = session.createQuery(
73 "from River where name =:name");
74 query.setParameter("name", rivername);
75
76 List<River> list = query.list();
77
78 if (list == null || list.size() == 0) {
79 logger.warn("No river '" + rivername + "' found!");
80 return null;
81 }
82
83 return list.get(0);
84 }
85
86
87 protected void doRiverAxisInfo(River river) {
88 List<RiverAxis> axis = RiverAxis.getRiverAxis(river.getName());
89 if (axis != null && axis.size() > 0) {
90 logger.debug("TODO: Compute length and boundary.");
91 }
92 else {
93 logger.warn("River has no RiverAxis.");
94 }
95 }
96
97
98 protected void doCrossSectionTracksInfo(River river) {
99 Query query = session.createQuery(
100 "from CrossSectionTrack where river =:river");
101 query.setParameter("river", river);
102
103 List<CrossSectionTrack> list = query.list();
104
105 if (list == null || list.size() == 0) {
106 logger.warn("No CrossSectionTracks for '" + river.getName() + "' found!");
107 return;
108 }
109 else {
110 logger.info("River contains " + list.size() + " CrossSectionTracks.");
111 }
112 }
113
114
115 protected void doLinesInfo(River river) {
116 Query query = session.createQuery(
117 "from Line where river =:river");
118 query.setParameter("river", river);
119
120 List<Line> list = query.list();
121
122 if (list == null || list.size() == 0) {
123 logger.warn("No Lines for '" + river.getName() + "' found!");
124 return;
125 }
126 else {
127 logger.info("River contains " + list.size() + " Lines.");
128 }
129 }
130
131
132 protected void doBuildingsInfo(River river) {
133 Query query = session.createQuery(
134 "from Building where river =:river");
135 query.setParameter("river", river);
136
137 List<Building> list = query.list();
138
139 if (list == null || list.size() == 0) {
140 logger.warn("No Buildings for '" + river.getName() + "' found!");
141 return;
142 }
143 else {
144 logger.info("River contains " + list.size() + " Buildings.");
145 }
146 }
147
148
149 protected void doFixpointsInfo(River river) {
150 Query query = session.createQuery(
151 "from Fixpoint where river =:river");
152 query.setParameter("river", river);
153
154 List<Fixpoint> list = query.list();
155
156 if (list == null || list.size() == 0) {
157 logger.warn("No Fixpoints for '" + river.getName() + "' found!");
158 return;
159 }
160 else {
161 logger.info("River contains " + list.size() + " Fixpoints.");
162 }
163 }
164 }
165 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org