Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/TkhSeriesImport.java @ 8971:50416a0df385
Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
author | mschaefer |
---|---|
date | Tue, 03 Apr 2018 10:18:30 +0200 |
parents | |
children | dcbdff96d1a8 |
comparison
equal
deleted
inserted
replaced
8970:da5dc7446652 | 8971:50416a0df385 |
---|---|
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 | |
11 package org.dive4elements.river.importer.sinfo.importitem; | |
12 | |
13 import java.util.List; | |
14 | |
15 import org.apache.log4j.Logger; | |
16 import org.dive4elements.river.importer.ImporterSession; | |
17 import org.dive4elements.river.importer.common.StoreMode; | |
18 import org.dive4elements.river.model.River; | |
19 import org.dive4elements.river.model.sinfo.Tkh; | |
20 import org.hibernate.Query; | |
21 import org.hibernate.Session; | |
22 | |
23 /** | |
24 * Imported Transportkörperhöhe data series group of a river | |
25 * | |
26 * @author Matthias Schäfer | |
27 * | |
28 */ | |
29 public class TkhSeriesImport { | |
30 | |
31 /***** FIELDS *****/ | |
32 | |
33 private static Logger log = Logger.getLogger(TkhSeriesImport.class); | |
34 | |
35 /** | |
36 * Name of the imported file without type extension | |
37 */ | |
38 private final String filename; | |
39 | |
40 private String kmrange_info; | |
41 | |
42 private String comment; | |
43 | |
44 private int year; | |
45 | |
46 private String sounding_info; | |
47 | |
48 private String evaluation_by; | |
49 | |
50 private Tkh peer; | |
51 | |
52 private StoreMode storeMode; | |
53 | |
54 | |
55 /***** CONSTRUCTORS *****/ | |
56 | |
57 public TkhSeriesImport(final String filename) { | |
58 this.filename = filename; | |
59 } | |
60 | |
61 | |
62 /***** METHODS *****/ | |
63 | |
64 public String getFilename() { | |
65 return this.filename; | |
66 } | |
67 | |
68 public String getKmrange_info() { | |
69 return this.kmrange_info; | |
70 } | |
71 | |
72 public void setKmrange_info(final String kmrange_info) { | |
73 this.kmrange_info = kmrange_info; | |
74 } | |
75 | |
76 public String getComment() { | |
77 return this.comment; | |
78 } | |
79 | |
80 public void setComment(final String comment) { | |
81 this.comment = comment; | |
82 } | |
83 | |
84 public int getYear() { | |
85 return this.year; | |
86 } | |
87 | |
88 public void setYear(final int year) { | |
89 this.year = year; | |
90 } | |
91 | |
92 public String getSounding_info() { | |
93 return this.sounding_info; | |
94 } | |
95 | |
96 public void setSounding_info(final String sounding_info) { | |
97 this.sounding_info = sounding_info; | |
98 } | |
99 | |
100 public String getEvaluation_by() { | |
101 return this.evaluation_by; | |
102 } | |
103 | |
104 public void setEvaluation_by(final String evaluation_by) { | |
105 this.evaluation_by = evaluation_by; | |
106 } | |
107 | |
108 public StoreMode getStoreMode() { | |
109 return this.storeMode; | |
110 } | |
111 | |
112 /** | |
113 * Gets the model object of the data series group, inserting it into the database if not already existing | |
114 */ | |
115 public Tkh getPeer(final River river) { | |
116 if (this.peer != null) { | |
117 this.storeMode = StoreMode.NONE; | |
118 return this.peer; | |
119 } | |
120 final Session session = ImporterSession.getInstance().getDatabaseSession(); | |
121 final List<Tkh> rows = querySeriesItem(session, river); | |
122 if (rows.isEmpty()) { | |
123 log.info("Create new database instance"); | |
124 this.peer = createSeriesItem(river); | |
125 session.save(this.peer); | |
126 this.storeMode = StoreMode.INSERT; | |
127 } | |
128 else { | |
129 this.peer = rows.get(0); | |
130 this.storeMode = StoreMode.UPDATE; | |
131 } | |
132 return this.peer; | |
133 } | |
134 | |
135 private List<Tkh> querySeriesItem(final Session session, final River river) { | |
136 final Query query = session.createQuery("FROM Tkh WHERE river=:river AND lower(filename)=:filename"); | |
137 query.setParameter("river", river); | |
138 query.setParameter("filename", this.filename.toLowerCase()); | |
139 return query.list(); | |
140 } | |
141 | |
142 private Tkh createSeriesItem(final River river) { | |
143 return new Tkh(river, this.filename, this.kmrange_info, this.comment, this.year, this.sounding_info, this.evaluation_by); | |
144 } | |
145 } |