Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportPorosity.java @ 7840:02711de579cc
Added model, parser and importer for porosities.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 30 Apr 2014 14:11:29 +0200 |
parents | |
children | 8c6ed23ce315 cdef048c4ac5 |
comparison
equal
deleted
inserted
replaced
7839:3f6b9fae1637 | 7840:02711de579cc |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.importer; | |
10 | |
11 import java.util.ArrayList; | |
12 import java.util.List; | |
13 | |
14 import org.apache.log4j.Logger; | |
15 import org.hibernate.Query; | |
16 import org.hibernate.Session; | |
17 | |
18 import org.dive4elements.river.model.River; | |
19 import org.dive4elements.river.model.Porosity; | |
20 import org.dive4elements.river.model.TimeInterval; | |
21 | |
22 | |
23 public class ImportPorosity { | |
24 | |
25 private static Logger log = Logger.getLogger(ImportPorosity.class); | |
26 | |
27 protected Porosity peer; | |
28 | |
29 protected ImportDepth depth; | |
30 | |
31 protected String description; | |
32 | |
33 protected ImportTimeInterval timeInterval; | |
34 | |
35 protected List<ImportPorosityValue> values; | |
36 | |
37 public ImportPorosity(String description) { | |
38 this.description = description; | |
39 this.values = new ArrayList<ImportPorosityValue>(); | |
40 } | |
41 | |
42 public String getDescription() { | |
43 return description; | |
44 } | |
45 | |
46 public void setDepth(ImportDepth depth) { | |
47 this.depth = depth; | |
48 } | |
49 | |
50 public void setTimeInterval(ImportTimeInterval importTimeInterval) { | |
51 this.timeInterval = importTimeInterval; | |
52 } | |
53 | |
54 public void addValue(ImportPorosityValue value) { | |
55 values.add(value); | |
56 } | |
57 | |
58 public void storeDependencies(River river) { | |
59 log.info("store dependencies"); | |
60 | |
61 if (depth != null) { | |
62 depth.storeDependencies(); | |
63 } | |
64 | |
65 Porosity peer = getPeer(river); | |
66 | |
67 if (peer != null) { | |
68 log.info("store porosity values."); | |
69 for (ImportPorosityValue value : values) { | |
70 value.storeDependencies(peer); | |
71 } | |
72 } | |
73 } | |
74 | |
75 public Porosity getPeer(River river) { | |
76 log.info("get peer"); | |
77 | |
78 if (depth == null) { | |
79 log.warn("cannot store porosity '" + description | |
80 + "': no depth"); | |
81 return null; | |
82 } | |
83 | |
84 if (peer == null) { | |
85 Session session = ImporterSession.getInstance() | |
86 .getDatabaseSession(); | |
87 | |
88 Query query = session.createQuery("from Porosity where " | |
89 + " river=:river and " + " depth=:depth"); | |
90 | |
91 query.setParameter("river", river); | |
92 query.setParameter("depth", depth.getPeer()); | |
93 | |
94 List<Porosity> porosity = query.list(); | |
95 | |
96 if (porosity.isEmpty()) { | |
97 log.debug("Create new Porosity DB instance."); | |
98 | |
99 peer = new Porosity(river, depth.getPeer(), | |
100 description, timeInterval.getPeer()); | |
101 | |
102 session.save(peer); | |
103 } | |
104 else { | |
105 peer = porosity.get(0); | |
106 } | |
107 } | |
108 | |
109 return peer; | |
110 } | |
111 } | |
112 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |