Mercurial > gemma
view pkg/imports/modelconvert.go @ 4940:b3b2ba09a450 fairway-marks-import
Add missing fairway mark types
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 17 Feb 2020 18:38:45 +0100 |
parents | 9bd6a0ca63ea |
children | b0dbc0f2c748 |
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, 2020 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) }, BCNLATJobKind: func() interface{} { return new(models.FairwayMarksImport) }, BOYCARJobKind: func() interface{} { return new(models.FairwayMarksImport) }, BOYLATJobKind: func() interface{} { return new(models.FairwayMarksImport) }, BOYSAWJobKind: func() interface{} { return new(models.FairwayMarksImport) }, BOYSPPJobKind: func() interface{} { return new(models.FairwayMarksImport) }, DAYMARJobKind: func() interface{} { return new(models.FairwayMarksImport) }, LIGHTSJobKind: func() interface{} { return new(models.FairwayMarksImport) }, RTPBCNJobKind: func() interface{} { return new(models.FairwayMarksImport) }, TOPMARJobKind: func() interface{} { return new(models.FairwayMarksImport) }, NOTMRKJobKind: func() interface{} { return new(models.FairwayMarksImport) }, STJobKind: func() interface{} { return new(models.StretchImport) }, SECJobKind: func() interface{} { return new(models.SectionImport) }, DSECJobKind: func() interface{} { return new(models.SectionDelete) }, DSTJobKind: func() interface{} { return new(models.StretchDelete) }, DSRJobKind: func() interface{} { return new(models.SoundingResultDelete) }, } // ImportModelForJobKind returns the constructor function to // de-serialize an incoming JSON REST represention of an import. 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), } }, BCNLATJobKind: func(input interface{}) interface{} { fmi := input.(*models.FairwayMarksImport) return &FairwayMarks{ URL: fmi.URL, FeatureType: fmi.FeatureType, SortBy: nilString(fmi.SortBy), User: nilString(fmi.User), Password: nilString(fmi.Password), } }, BOYCARJobKind: func(input interface{}) interface{} { fmi := input.(*models.FairwayMarksImport) return &FairwayMarks{ URL: fmi.URL, FeatureType: fmi.FeatureType, SortBy: nilString(fmi.SortBy), User: nilString(fmi.User), Password: nilString(fmi.Password), } }, BOYLATJobKind: func(input interface{}) interface{} { fmi := input.(*models.FairwayMarksImport) return &FairwayMarks{ URL: fmi.URL, FeatureType: fmi.FeatureType, SortBy: nilString(fmi.SortBy), User: nilString(fmi.User), Password: nilString(fmi.Password), } }, BOYSAWJobKind: func(input interface{}) interface{} { fmi := input.(*models.FairwayMarksImport) return &FairwayMarks{ URL: fmi.URL, FeatureType: fmi.FeatureType, SortBy: nilString(fmi.SortBy), User: nilString(fmi.User), Password: nilString(fmi.Password), } }, BOYSPPJobKind: func(input interface{}) interface{} { fmi := input.(*models.FairwayMarksImport) return &FairwayMarks{ URL: fmi.URL, FeatureType: fmi.FeatureType, SortBy: nilString(fmi.SortBy), User: nilString(fmi.User), Password: nilString(fmi.Password), } }, DAYMARJobKind: func(input interface{}) interface{} { fmi := input.(*models.FairwayMarksImport) return &FairwayMarks{ URL: fmi.URL, FeatureType: fmi.FeatureType, SortBy: nilString(fmi.SortBy), User: nilString(fmi.User), Password: nilString(fmi.Password), } }, LIGHTSJobKind: func(input interface{}) interface{} { fmi := input.(*models.FairwayMarksImport) return &FairwayMarks{ URL: fmi.URL, FeatureType: fmi.FeatureType, SortBy: nilString(fmi.SortBy), User: nilString(fmi.User), Password: nilString(fmi.Password), } }, RTPBCNJobKind: func(input interface{}) interface{} { fmi := input.(*models.FairwayMarksImport) return &FairwayMarks{ URL: fmi.URL, FeatureType: fmi.FeatureType, SortBy: nilString(fmi.SortBy), User: nilString(fmi.User), Password: nilString(fmi.Password), } }, TOPMARJobKind: func(input interface{}) interface{} { fmi := input.(*models.FairwayMarksImport) return &FairwayMarks{ URL: fmi.URL, FeatureType: fmi.FeatureType, SortBy: nilString(fmi.SortBy), User: nilString(fmi.User), Password: nilString(fmi.Password), } }, NOTMRKJobKind: func(input interface{}) interface{} { fmi := input.(*models.FairwayMarksImport) return &FairwayMarks{ URL: fmi.URL, FeatureType: fmi.FeatureType, SortBy: nilString(fmi.SortBy), User: nilString(fmi.User), Password: nilString(fmi.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, } }, SECJobKind: func(input interface{}) interface{} { seci := input.(*models.SectionImport) return &Section{ Name: seci.Name, From: seci.From, To: seci.To, Tolerance: seci.Tolerance, ObjNam: seci.ObjNam, NObjNam: seci.NObjNam, Source: seci.Source, Date: seci.Date, } }, DSECJobKind: func(input interface{}) interface{} { dsec := input.(*models.SectionDelete) return &DeleteSection{ID: dsec.ID} }, DSTJobKind: func(input interface{}) interface{} { dst := input.(*models.StretchDelete) return &DeleteStretch{ID: dst.ID} }, DSRJobKind: func(input interface{}) interface{} { dsr := input.(*models.SoundingResultDelete) return &DeleteSoundingResult{ BottleneckID: dsr.BottleneckId, Date: dsr.Date, } }, } func nilString(s *string) string { if s != nil { return *s } return "" } // ConvertToInternal converts an external JSON REST represention // of an import into the internal one store in the import queue. func ConvertToInternal(kind JobKind, src interface{}) interface{} { fn := convertModel[kind] if fn == nil { return nil } return fn(src) }