diff pkg/imports/modelconvert.go @ 2040:f1e32babb587 unify_imports

Imports: Moved constructor functions for import models to a table in the import package to be re-used by the configure/scheduled import.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 25 Jan 2019 12:57:53 +0100
parents 42a33f9e1f95
children d29ac997eb34
line wrap: on
line diff
--- a/pkg/imports/modelconvert.go	Fri Jan 25 12:43:08 2019 +0100
+++ b/pkg/imports/modelconvert.go	Fri Jan 25 12:57:53 2019 +0100
@@ -14,9 +14,31 @@
 package imports
 
 import (
+	"fmt"
+
 	"gemma.intevation.de/gemma/pkg/models"
 )
 
+var kindToImportModel = map[JobKind]func() interface{}{
+	BNJobKind:  func() interface{} { return new(models.BottleneckImport) },
+	GMJobKind:  func() interface{} { return new(models.GaugeMeasurementImport) },
+	FAJobKind:  func() interface{} { return new(models.FairwayAvailabilityImport) },
+	WXJobKind:  func() interface{} { return new(models.WaterwayAxisImport) },
+	WAJobKind:  func() interface{} { return new(models.WaterwayAreaImport) },
+	WGJobKind:  func() interface{} { return new(models.WaterwayGaugeImport) },
+	DMVJobKind: func() interface{} { return new(models.DistanceMarksVirtualImport) },
+	FDJobKind:  func() interface{} { return new(models.FairwayDimensionImport) },
+	DMAJobKind: func() interface{} { return new(models.DistanceMarksAshoreImport) },
+	STJobKind:  func() interface{} { return new(models.StretchImport) },
+}
+
+func MustImportModel(kind JobKind) func() interface{} {
+	if ctor := kindToImportModel[kind]; ctor != nil {
+		return ctor
+	}
+	panic(fmt.Sprintf("Cannot find import model for kind '%s'.", kind))
+}
+
 var convertModel = map[JobKind]func(interface{}) interface{}{
 
 	BNJobKind: func(input interface{}) interface{} {