changeset 9010:dcbdff96d1a8

Tkh import with day instead of year
author mschaefer
date Wed, 18 Apr 2018 07:42:06 +0200
parents 6fd0f20b58aa
children a44200bf0547
files backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/TkhSeriesImport.java backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/TkhParser.java backend/src/main/java/org/dive4elements/river/model/sinfo/Tkh.java
diffstat 3 files changed, 37 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/TkhSeriesImport.java	Wed Apr 18 07:38:47 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/TkhSeriesImport.java	Wed Apr 18 07:42:06 2018 +0200
@@ -10,6 +10,7 @@
 
 package org.dive4elements.river.importer.sinfo.importitem;
 
+import java.util.Date;
 import java.util.List;
 
 import org.apache.log4j.Logger;
@@ -41,7 +42,7 @@
 
     private String comment;
 
-    private int year;
+    private Date day;
 
     private String sounding_info;
 
@@ -81,12 +82,12 @@
         this.comment = comment;
     }
 
-    public int getYear() {
-        return this.year;
+    public Date getDay() {
+        return this.day;
     }
 
-    public void setYear(final int year) {
-        this.year = year;
+    public void setDay(final Date day) {
+        this.day = day;
     }
 
     public String getSounding_info() {
@@ -140,6 +141,6 @@
     }
 
     private Tkh createSeriesItem(final River river) {
-        return new Tkh(river, this.filename, this.kmrange_info, this.comment, this.year, this.sounding_info, this.evaluation_by);
+        return new Tkh(river, this.filename, this.kmrange_info, this.comment, this.day, this.sounding_info, this.evaluation_by);
     }
 }
\ No newline at end of file
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/TkhParser.java	Wed Apr 18 07:38:47 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/TkhParser.java	Wed Apr 18 07:42:06 2018 +0200
@@ -15,7 +15,10 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.LineNumberReader;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -43,7 +46,7 @@
 
     private static final Logger log = Logger.getLogger(TkhParser.class);
 
-    private static final Pattern META_YEAR = Pattern.compile("^#\\sBezugsjahr:\\s*([12]\\d\\d\\d).*", Pattern.CASE_INSENSITIVE);
+    private static final Pattern META_DATUM = Pattern.compile("^#\\sDatum:\\s*([^;]*).*", Pattern.CASE_INSENSITIVE);
 
     private static final Pattern META_EVALUATOR = Pattern.compile("^#\\sAuswerter:\\s*([^;]*).*", Pattern.CASE_INSENSITIVE);
 
@@ -53,6 +56,8 @@
 
     private static final Pattern COLUMN_TITLE = Pattern.compile("Transportk((.)|(oe))rperh((.)|(oe))he\\s*\\((.+?)\\)\\s*\\[cm\\].*", Pattern.CASE_INSENSITIVE);
 
+    private static final DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
+
     private final TkhSeriesImport tkhGroup;
 
     private final List<TkhColumnParser> colParsers;
@@ -136,7 +141,7 @@
 
     @Override
     protected boolean handleMetaOther() {
-        if (handleMetaYear())
+        if (handleMetaDay())
             return true;
         else if (handleMetaType())
             return true;
@@ -148,11 +153,21 @@
             return false;
     }
 
-    private boolean handleMetaYear() {
-        final Matcher m = META_YEAR.matcher(this.currentLine);
+    private boolean handleMetaDay() {
+        final Matcher m = META_DATUM.matcher(this.currentLine);
         if (m.matches()) {
-            this.metaPatternsMatched.add(META_YEAR);
-            this.tkhGroup.setYear(Integer.parseInt(m.group(1)));
+            Date day = null;
+            try {
+                if (!m.group(1).isEmpty())
+                    day = dateFormat.parse(m.group(1));
+            }
+            catch (final Exception e) {
+                logError("Invalid date in line " + this.in.getLineNumber());
+            }
+            this.metaPatternsMatched.add(META_DATUM);
+            this.tkhGroup.setDay(day);
+            if (day == null)
+                logWarning("No date specified");
             return true;
         }
         return false;
--- a/backend/src/main/java/org/dive4elements/river/model/sinfo/Tkh.java	Wed Apr 18 07:38:47 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/Tkh.java	Wed Apr 18 07:42:06 2018 +0200
@@ -12,6 +12,7 @@
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 import javax.persistence.Column;
@@ -52,7 +53,7 @@
 
     private String comment;
 
-    private Integer year;
+    private Date day;
 
     private String sounding_info;
 
@@ -67,13 +68,13 @@
     }
 
 
-    public Tkh(final River river, final String filename, final String kmrange_info, final String comment, final Integer year, final String sounding_info,
+    public Tkh(final River river, final String filename, final String kmrange_info, final String comment, final Date day, final String sounding_info,
             final String evaluation_by) {
         this.river = river;
         this.filename = filename;
         this.kmrange_info = kmrange_info;
         this.comment = comment;
-        this.year = year;
+        this.day = day;
         this.setSounding_info(sounding_info);
         this.setEvaluation_by(evaluation_by);
         this.columns = new ArrayList<>();
@@ -130,13 +131,13 @@
         this.comment = comment;
     }
 
-    @Column(name = "year")
-    public Integer getYear() {
-        return this.year;
+    @Column(name = "day")
+    public Date getDay() {
+        return this.day;
     }
 
-    public void setYear(final Integer year) {
-        this.year = year;
+    public void setDay(final Date day) {
+        this.day = day;
     }
 
     @Column(name = "sounding_info")

http://dive4elements.wald.intevation.org