Mercurial > gemma
comparison pkg/imports/modelconvert.go @ 2038:42a33f9e1f95 unify_imports
Imports: Moved model conversion into a table in the imports package.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 25 Jan 2019 12:31:50 +0100 |
parents | |
children | f1e32babb587 |
comparison
equal
deleted
inserted
replaced
2037:11cb57f85c60 | 2038:42a33f9e1f95 |
---|---|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 | |
2 // without warranty, see README.md and license for details. | |
3 // | |
4 // SPDX-License-Identifier: AGPL-3.0-or-later | |
5 // License-Filename: LICENSES/AGPL-3.0.txt | |
6 // | |
7 // Copyright (C) 2018 by via donau | |
8 // – Österreichische Wasserstraßen-Gesellschaft mbH | |
9 // Software engineering by Intevation GmbH | |
10 // | |
11 // Author(s): | |
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> | |
13 | |
14 package imports | |
15 | |
16 import ( | |
17 "gemma.intevation.de/gemma/pkg/models" | |
18 ) | |
19 | |
20 var convertModel = map[JobKind]func(interface{}) interface{}{ | |
21 | |
22 BNJobKind: func(input interface{}) interface{} { | |
23 bi := input.(*models.BottleneckImport) | |
24 return &Bottleneck{ | |
25 URL: bi.URL, | |
26 Insecure: bi.Insecure, | |
27 } | |
28 }, | |
29 | |
30 GMJobKind: func(input interface{}) interface{} { | |
31 gi := input.(*models.GaugeMeasurementImport) | |
32 return &GaugeMeasurement{ | |
33 URL: gi.URL, | |
34 Insecure: gi.Insecure, | |
35 } | |
36 }, | |
37 | |
38 FAJobKind: func(input interface{}) interface{} { | |
39 fai := input.(*models.FairwayAvailabilityImport) | |
40 return &FairwayAvailability{ | |
41 URL: fai.URL, | |
42 Insecure: fai.Insecure, | |
43 } | |
44 }, | |
45 | |
46 WXJobKind: func(input interface{}) interface{} { | |
47 wxi := input.(*models.WaterwayAxisImport) | |
48 return &WaterwayAxis{ | |
49 URL: wxi.URL, | |
50 FeatureType: wxi.FeatureType, | |
51 SortBy: nilString(wxi.SortBy), | |
52 } | |
53 }, | |
54 | |
55 WAJobKind: func(input interface{}) interface{} { | |
56 wai := input.(*models.WaterwayAreaImport) | |
57 return &WaterwayArea{ | |
58 URL: wai.URL, | |
59 FeatureType: wai.FeatureType, | |
60 SortBy: nilString(wai.SortBy), | |
61 } | |
62 }, | |
63 | |
64 WGJobKind: func(input interface{}) interface{} { | |
65 wgi := input.(*models.WaterwayGaugeImport) | |
66 return &WaterwayGauge{ | |
67 Username: nilString(wgi.User), | |
68 Password: nilString(wgi.Password), | |
69 Insecure: wgi.Insecure, | |
70 } | |
71 }, | |
72 | |
73 DMVJobKind: func(input interface{}) interface{} { | |
74 dmvi := input.(*models.DistanceMarksVirtualImport) | |
75 return &DistanceMarksVirtual{ | |
76 URL: dmvi.URL, | |
77 Username: nilString(dmvi.User), | |
78 Password: nilString(dmvi.Password), | |
79 Insecure: dmvi.Insecure, | |
80 } | |
81 }, | |
82 | |
83 FDJobKind: func(input interface{}) interface{} { | |
84 fdi := input.(*models.FairwayDimensionImport) | |
85 return &FairwayDimension{ | |
86 URL: fdi.URL, | |
87 FeatureType: fdi.FeatureType, | |
88 SortBy: nilString(fdi.SortBy), | |
89 LOS: fdi.LOS, | |
90 MinWidth: fdi.MinWidth, | |
91 MaxWidth: fdi.MaxWidth, | |
92 Depth: fdi.Depth, | |
93 SourceOrganization: fdi.SourceOrganization, | |
94 } | |
95 }, | |
96 | |
97 DMAJobKind: func(input interface{}) interface{} { | |
98 dmai := input.(*models.DistanceMarksAshoreImport) | |
99 return &DistanceMarksAshore{ | |
100 URL: dmai.URL, | |
101 FeatureType: dmai.FeatureType, | |
102 SortBy: nilString(dmai.SortBy), | |
103 } | |
104 }, | |
105 | |
106 STJobKind: func(input interface{}) interface{} { | |
107 sti := input.(*models.StretchImport) | |
108 return &Stretch{ | |
109 Name: sti.Name, | |
110 From: sti.From, | |
111 To: sti.To, | |
112 ObjNam: sti.ObjNam, | |
113 NObjNam: sti.NObjNam, | |
114 Source: sti.Source, | |
115 Date: sti.Date, | |
116 Countries: sti.Countries, | |
117 } | |
118 }, | |
119 } | |
120 | |
121 func nilString(s *string) string { | |
122 if s != nil { | |
123 return *s | |
124 } | |
125 return "" | |
126 } | |
127 | |
128 func ConvertToInternal(kind JobKind, src interface{}) interface{} { | |
129 fn := convertModel[kind] | |
130 if fn == nil { | |
131 return nil | |
132 } | |
133 return fn(src) | |
134 } |