Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportCrossSection.java @ 7730:e1b831fe435a slt-simplify-cross-sections
Merged default into slt-simplify-cross-sections branch and updated package and class names.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 20 Jan 2014 14:04:20 +0100 |
parents | 9344aa0fb021 |
children | 392bbcd8a88b 0a5239a1e46e |
comparison
equal
deleted
inserted
replaced
5084:ca45dd039b54 | 7730:e1b831fe435a |
---|---|
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 org.dive4elements.river.model.River; | |
12 import org.dive4elements.river.model.CrossSection; | |
13 import org.dive4elements.river.model.TimeInterval; | |
14 | |
15 import org.hibernate.Session; | |
16 import org.hibernate.Query; | |
17 | |
18 import java.util.List; | |
19 | |
20 import org.apache.log4j.Logger; | |
21 | |
22 /** CrossSection to be imported, holds list of ImportCrossSectionLines. */ | |
23 public class ImportCrossSection | |
24 { | |
25 private static Logger log = Logger.getLogger(ImportCrossSection.class); | |
26 | |
27 protected ImportRiver river; | |
28 protected String description; | |
29 protected ImportTimeInterval timeInterval; | |
30 protected List<ImportCrossSectionLine> lines; | |
31 | |
32 protected CrossSection peer; | |
33 | |
34 public ImportCrossSection() { | |
35 } | |
36 | |
37 public ImportCrossSection( | |
38 ImportRiver river, | |
39 String description, | |
40 ImportTimeInterval timeInterval, | |
41 List<ImportCrossSectionLine> lines | |
42 ) { | |
43 this.river = river; | |
44 this.description = description; | |
45 this.timeInterval = timeInterval; | |
46 this.lines = lines; | |
47 wireWithLines(); | |
48 } | |
49 | |
50 public void wireWithLines() { | |
51 for (ImportCrossSectionLine line: lines) { | |
52 line.setCrossSection(this); | |
53 } | |
54 } | |
55 | |
56 public ImportRiver getRiver() { | |
57 return river; | |
58 } | |
59 | |
60 public void setRiver(ImportRiver river) { | |
61 this.river = river; | |
62 } | |
63 | |
64 public String getDescription() { | |
65 return description; | |
66 } | |
67 | |
68 public void setDescription(String description) { | |
69 this.description = description; | |
70 } | |
71 | |
72 public ImportTimeInterval getTimeInterval() { | |
73 return timeInterval; | |
74 } | |
75 | |
76 public void setTimeInterval(ImportTimeInterval timeInterval) { | |
77 this.timeInterval = timeInterval; | |
78 } | |
79 | |
80 public void storeDependencies() { | |
81 | |
82 log.info("store cross section '" + description + "'"); | |
83 | |
84 getPeer(); | |
85 | |
86 int i = 1, N = lines.size(); | |
87 | |
88 for (ImportCrossSectionLine line: lines) { | |
89 line.storeDependencies(); | |
90 log.info(" stored " + i + " lines. remaining: " + (N-i)); | |
91 ++i; | |
92 } | |
93 } | |
94 | |
95 public CrossSection getPeer() { | |
96 | |
97 if (peer == null) { | |
98 River r = river.getPeer(); | |
99 TimeInterval t = timeInterval != null | |
100 ? timeInterval.getPeer() | |
101 : null; | |
102 | |
103 Session session = | |
104 ImporterSession.getInstance().getDatabaseSession(); | |
105 | |
106 Query query = session.createQuery( | |
107 "from CrossSection where " + | |
108 "river=:r and " + | |
109 "timeInterval=:t and " + | |
110 "description=:d"); | |
111 | |
112 query.setParameter("r", r); | |
113 query.setParameter("t", t); | |
114 query.setParameter("d", description); | |
115 | |
116 List<CrossSection> crossSections = query.list(); | |
117 if (crossSections.isEmpty()) { | |
118 peer = new CrossSection(r, t, description); | |
119 session.save(peer); | |
120 } | |
121 else { | |
122 peer = crossSections.get(0); | |
123 } | |
124 } | |
125 return peer; | |
126 } | |
127 } | |
128 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |