Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/data/importer/AttributeMapper.java @ 310:821557a17e5e
First version of the LAF importer.
The importer module currently only runs with the test application (comming in the next commit)!
* LAF Parser:
- Uses a small implementation of a state machine.
- Extracts the keys with its value or multi value.
- Uses the producer interface to generate objects.
* Attribute mapper:
- Maps the attributes defined in the configuration file to object attributes.
- Generates objects from multi value attributes.
* LAF format:
- Reads the config file
* LAF importer:
- Implemetation of the importer interface for LAF format.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 20 Aug 2013 16:13:17 +0200 |
parents | |
children | 5844d7457dde |
comparison
equal
deleted
inserted
replaced
309:ae4bf396bd3b | 310:821557a17e5e |
---|---|
1 package de.intevation.lada.data.importer; | |
2 | |
3 import java.text.DateFormat; | |
4 import java.text.ParseException; | |
5 import java.text.SimpleDateFormat; | |
6 import java.util.Date; | |
7 import java.util.regex.Matcher; | |
8 import java.util.regex.Pattern; | |
9 | |
10 import javax.inject.Inject; | |
11 import javax.persistence.EntityManager; | |
12 | |
13 import de.intevation.lada.model.LKommentarM; | |
14 import de.intevation.lada.model.LKommentarP; | |
15 import de.intevation.lada.model.LMessung; | |
16 import de.intevation.lada.model.LMessungId; | |
17 import de.intevation.lada.model.LMesswert; | |
18 import de.intevation.lada.model.LOrt; | |
19 import de.intevation.lada.model.LProbe; | |
20 | |
21 | |
22 public class AttributeMapper | |
23 { | |
24 @Inject | |
25 private EntityManager em; | |
26 | |
27 public LProbe addAttribute(String key, Object value, LProbe probe) { | |
28 DateFormat format = new SimpleDateFormat("yyyyMMDD hhmm"); | |
29 if ("datenbasis_s".equals(key)) { | |
30 Integer v = Integer.valueOf(value.toString()); | |
31 probe.setDatenbasisId(v); | |
32 } | |
33 else if ("probe_id".equals(key)) { | |
34 probe.setProbeId(value.toString()); | |
35 } | |
36 else if ("hauptprobennummer".equals(key)) { | |
37 probe.setHauptprobenNr(value.toString()); | |
38 } | |
39 else if ("mpr_id".equals(key)) { | |
40 Integer v = Integer.valueOf(value.toString()); | |
41 probe.setMprId(v); | |
42 } | |
43 else if ("messprogramm_land".equals(key)) { | |
44 probe.setMplId(value.toString()); | |
45 } | |
46 else if ("messstelle".equals(key)) { | |
47 probe.setMstId(value.toString()); | |
48 } | |
49 else if ("betriebsart".equals(key)) { | |
50 probe.setBaId(value.toString()); | |
51 } | |
52 else if ("soll_datum_uhrzeit_a".equals(key)) { | |
53 try { | |
54 Date d = format.parse(value.toString()); | |
55 probe.setSolldatumBeginn(d); | |
56 } | |
57 catch (ParseException e) { | |
58 //TODO handle warning. | |
59 } | |
60 } | |
61 else if ("soll_datum_uhrzeit_e".equals(key)) { | |
62 try { | |
63 Date d = format.parse(value.toString()); | |
64 probe.setSolldatumEnde(d); | |
65 } | |
66 catch (ParseException e) { | |
67 //TODO handle warning. | |
68 } | |
69 } | |
70 else if ("probenahme_datum_uhrzeit_a".equals(key)) { | |
71 try { | |
72 Date d = format.parse(value.toString()); | |
73 probe.setProbeentnahmeBeginn(d); | |
74 } | |
75 catch (ParseException e) { | |
76 //TODO handle warning. | |
77 } | |
78 } | |
79 else if ("probenahme_datum_uhrzeit_e".equals(key)) { | |
80 try { | |
81 Date d = format.parse(value.toString()); | |
82 probe.setProbeentnahmeEnde(d); | |
83 } | |
84 catch (ParseException e) { | |
85 //TODO handle warning. | |
86 } | |
87 } | |
88 else if ("umweltbereich_s".equals(key)) { | |
89 probe.setUmwId(value.toString()); | |
90 } | |
91 else if ("deskriptoren".equals(key)) { | |
92 probe.setMediaDesk(value.toString()); | |
93 } | |
94 else if ("testdaten".equals(key)) { | |
95 if (!value.toString().equals("0")) { | |
96 probe.setTest(true); | |
97 } | |
98 else { | |
99 probe.setTest(false); | |
100 } | |
101 } | |
102 return probe; | |
103 } | |
104 | |
105 public LKommentarP addAttribute( | |
106 String key, | |
107 Object values, | |
108 LKommentarP kommentar | |
109 ) { | |
110 DateFormat format = new SimpleDateFormat("yyyyMMDD hhmm"); | |
111 String v = values.toString(); | |
112 String erzeuger = v.substring(1, 5); | |
113 String date = v.substring(8, 21); | |
114 Date d; | |
115 try { | |
116 d = format.parse(date); | |
117 kommentar.setKDatum(d); | |
118 } | |
119 catch (ParseException e) { | |
120 //TODO: handle warning. | |
121 } | |
122 String text = v.substring(23, v.length() -1); | |
123 kommentar.setErzeuger(erzeuger); | |
124 kommentar.setKText(text); | |
125 return kommentar; | |
126 } | |
127 | |
128 public LKommentarM addAttribute( | |
129 String key, | |
130 Object values, | |
131 LKommentarM kommentar | |
132 ) { | |
133 DateFormat format = new SimpleDateFormat("yyyyMMDD hhmm"); | |
134 String v = values.toString(); | |
135 String erzeuger = v.substring(1, 5); | |
136 String date = v.substring(8, 21); | |
137 Date d; | |
138 try { | |
139 d = format.parse(date); | |
140 kommentar.setKDatum(d); | |
141 } | |
142 catch (ParseException e) { | |
143 //TODO: handle warning. | |
144 } | |
145 String text = v.substring(23, v.length() -1); | |
146 kommentar.setErzeuger(erzeuger); | |
147 kommentar.setKText(text); | |
148 return kommentar; | |
149 } | |
150 | |
151 public LMessung addAttribute( | |
152 String key, | |
153 Object values, | |
154 LMessung messung | |
155 ) { | |
156 DateFormat format = new SimpleDateFormat("yyyyMMDD hhmm"); | |
157 if ("messungs_id".equals(key)) { | |
158 LMessungId id = messung.getId(); | |
159 Integer v = Integer.valueOf(values.toString()); | |
160 id.setMessungsId(v); | |
161 messung.setId(id); | |
162 } | |
163 else if ("nebenprobennummer".equals(key)) { | |
164 messung.setNebenprobenNr(values.toString()); | |
165 } | |
166 else if ("mess_datum_uhrzeit".equals(key)) { | |
167 try { | |
168 Date d = format.parse(values.toString()); | |
169 messung.setMesszeitpunkt(d); | |
170 } | |
171 catch (ParseException e) { | |
172 //TODO: handle warnings. | |
173 } | |
174 } | |
175 else if ("messzeit_sekunden".equals(key)) { | |
176 Integer i = Integer.valueOf(values.toString()); | |
177 messung.setMessdauer(i); | |
178 } | |
179 else if ("messmethode_s".equals(key)) { | |
180 messung.setMmtId(values.toString()); | |
181 } | |
182 else if ("bearbeitungsstatus".equals(key)) { | |
183 //ignored.!? | |
184 } | |
185 else if ("erfassung_abgeschlossen".equals(key)) { | |
186 if(!values.toString().equals("0")) { | |
187 messung.setFertig(true); | |
188 } | |
189 else { | |
190 messung.setFertig(false); | |
191 } | |
192 } | |
193 return messung; | |
194 } | |
195 | |
196 public LMesswert addAttribute( | |
197 String key, | |
198 Object values, | |
199 LMesswert messwert | |
200 ) { | |
201 Pattern p = Pattern.compile( | |
202 "(\".+\")( .+ )(\".+\")( .*)( .{1,12})( .{1,9})(.{0,9})(.{0,3})"); | |
203 //TODO Does not perfectly match... Use better matching for floats. | |
204 Matcher m = p.matcher(values.toString()); | |
205 if (m.matches()) { | |
206 String messgroesse = m.group(1); | |
207 String wert = m.group(2); | |
208 String einheit = m.group(3); | |
209 if (wert.startsWith(" <")) { | |
210 wert = wert.substring(2); | |
211 messwert.setGrenzwertueberschreitung(false); | |
212 } | |
213 else if (wert.startsWith(" >")) { | |
214 wert = wert.substring(2); | |
215 messwert.setGrenzwertueberschreitung(true); | |
216 } | |
217 float fWert = Float.valueOf(wert); | |
218 messwert.setMesswert(fWert); | |
219 } | |
220 //TODO: Match the other values. | |
221 return messwert; | |
222 } | |
223 | |
224 public LOrt addAttribute( | |
225 String key, | |
226 Object values, | |
227 LOrt ort | |
228 ) { | |
229 if ("ort_id".equals(key)) { | |
230 Integer v = Integer.valueOf(values.toString()); | |
231 ort.setOrtId(v); | |
232 } | |
233 else if ("ort_typ".equals(key)) { | |
234 ort.setOrtsTyp(values.toString()); | |
235 } | |
236 return ort; | |
237 } | |
238 } |