Mercurial > gemma
view pkg/imports/modelconvert.go @ 2750:6446bf6d2a89
search: use global search only in global context
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Thu, 21 Mar 2019 12:23:52 +0100 |
parents | a10022399e24 |
children | c8ded555c2a8 |
line wrap: on
line source
// This is Free Software under GNU Affero General Public License v >= 3.0 // without warranty, see README.md and license for details. // // SPDX-License-Identifier: AGPL-3.0-or-later // License-Filename: LICENSES/AGPL-3.0.txt // // Copyright (C) 2018 by via donau // – Österreichische Wasserstraßen-Gesellschaft mbH // Software engineering by Intevation GmbH // // Author(s): // * Sascha L. Teichmann <sascha.teichmann@intevation.de> package imports import ( "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 ImportModelForJobKind(kind JobKind) func() interface{} { return kindToImportModel[kind] } var convertModel = map[JobKind]func(interface{}) interface{}{ BNJobKind: func(input interface{}) interface{} { bi := input.(*models.BottleneckImport) return &Bottleneck{ URL: bi.URL, Tolerance: bi.Tolerance, Insecure: bi.Insecure, } }, GMJobKind: func(input interface{}) interface{} { gi := input.(*models.GaugeMeasurementImport) return &GaugeMeasurement{ URL: gi.URL, Insecure: gi.Insecure, } }, FAJobKind: func(input interface{}) interface{} { fai := input.(*models.FairwayAvailabilityImport) return &FairwayAvailability{ URL: fai.URL, Insecure: fai.Insecure, } }, WXJobKind: func(input interface{}) interface{} { wxi := input.(*models.WaterwayAxisImport) return &WaterwayAxis{ URL: wxi.URL, FeatureType: wxi.FeatureType, SortBy: nilString(wxi.SortBy), User: nilString(wxi.User), Password: nilString(wxi.Password), } }, WAJobKind: func(input interface{}) interface{} { wai := input.(*models.WaterwayAreaImport) return &WaterwayArea{ URL: wai.URL, FeatureType: wai.FeatureType, SortBy: nilString(wai.SortBy), User: nilString(wai.User), Password: nilString(wai.Password), } }, WGJobKind: func(input interface{}) interface{} { wgi := input.(*models.WaterwayGaugeImport) return &WaterwayGauge{ URL: wgi.URL, Username: nilString(wgi.User), Password: nilString(wgi.Password), Insecure: wgi.Insecure, } }, DMVJobKind: func(input interface{}) interface{} { dmvi := input.(*models.DistanceMarksVirtualImport) return &DistanceMarksVirtual{ URL: dmvi.URL, Username: nilString(dmvi.User), Password: nilString(dmvi.Password), Insecure: dmvi.Insecure, } }, FDJobKind: func(input interface{}) interface{} { fdi := input.(*models.FairwayDimensionImport) return &FairwayDimension{ URL: fdi.URL, FeatureType: fdi.FeatureType, SortBy: nilString(fdi.SortBy), LOS: fdi.LOS, MinWidth: fdi.MinWidth, MaxWidth: fdi.MaxWidth, Depth: fdi.Depth, SourceOrganization: fdi.SourceOrganization, User: nilString(fdi.User), Password: nilString(fdi.Password), } }, DMAJobKind: func(input interface{}) interface{} { dmai := input.(*models.DistanceMarksAshoreImport) return &DistanceMarksAshore{ URL: dmai.URL, FeatureType: dmai.FeatureType, SortBy: nilString(dmai.SortBy), User: nilString(dmai.User), Password: nilString(dmai.Password), } }, STJobKind: func(input interface{}) interface{} { sti := input.(*models.StretchImport) return &Stretch{ Name: sti.Name, From: sti.From, To: sti.To, Tolerance: sti.Tolerance, ObjNam: sti.ObjNam, NObjNam: sti.NObjNam, Source: sti.Source, Date: sti.Date, Countries: sti.Countries, } }, } func nilString(s *string) string { if s != nil { return *s } return "" } func ConvertToInternal(kind JobKind, src interface{}) interface{} { fn := convertModel[kind] if fn == nil { return nil } return fn(src) }