changeset 617:4e90daa57086

Sounding results: Reject unknown depth references earlier before loading the XYZ files. TODO: The list of known depth references should be taken from the database.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 11 Sep 2018 10:25:58 +0200
parents 51dc26b0f066
children b7b69d25cafe
files cmd/soundingresults/main.go
diffstat 1 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/cmd/soundingresults/main.go	Tue Sep 11 09:50:37 2018 +0200
+++ b/cmd/soundingresults/main.go	Tue Sep 11 10:25:58 2018 +0200
@@ -52,6 +52,24 @@
 	return fn(db)
 }
 
+// TODO: This should come from the depth_references table.
+var knownDepthReferences = []string{
+	"ADR", "ETRS", "FZP", "GLW", "HBO",
+	"HDC", "HNW", "HSW", "IGN", "KP",
+	"LDC", "LNW", "NAP", "NGM", "POT",
+	"PUL", "RN", "TAW", "WGS", "ZPG",
+}
+
+func isKnownDepthReference(ref string) bool {
+	ref = strings.ToUpper(ref)
+	for _, r := range knownDepthReferences {
+		if r == ref {
+			return true
+		}
+	}
+	return false
+}
+
 type meta struct {
 	date           time.Time
 	name           string
@@ -130,6 +148,11 @@
 
 	depthReference := rest[idx+1:]
 
+	if !isKnownDepthReference(depthReference) {
+		return nil, fmt.Errorf(
+			"%s is not a known depth reference", depthReference)
+	}
+
 	rest = rest[:idx]
 
 	if !strings.HasSuffix(strings.ToUpper(rest), "_MB") {
@@ -196,12 +219,7 @@
 
 	if *dump {
 		var results []result
-		handler = func(r result) {
-			if r.m.depthReference != "ADR" {
-				return
-			}
-			results = append(results, r)
-		}
+		handler = func(r result) { results = append(results, r) }
 		flush = func() {
 			sort.Slice(results, func(i, j int) bool {
 				if a, b := results[i].m.name, results[j].m.name; a != b {