annotate pkg/models/sr.go @ 5427:235cfce555b5 marking-single-beam

Minor clean-up.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 10 Jul 2021 01:09:57 +0200
parents 850f5847d18a
children 7e8830c808ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 // This is Free Software under GNU Affero General Public License v >= 3.0
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2 // without warranty, see README.md and license for details.
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 //
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 // SPDX-License-Identifier: AGPL-3.0-or-later
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 // License-Filename: LICENSES/AGPL-3.0.txt
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 //
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 // Copyright (C) 2018 by via donau
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 // Software engineering by Intevation GmbH
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 //
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 // Author(s):
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 // * Bernhard E. Reiter <bernhard.reiter@intevation.de>
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 package models
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 import (
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 "context"
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 "database/sql"
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 "encoding/json"
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 "errors"
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 "fmt"
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 "io"
2345
df6383831ad3 Sounding result import: Be more verbose if sounding result already exists for a bottleneck/date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
24
df6383831ad3 Sounding result import: Be more verbose if sounding result already exists for a bottleneck/date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
25 "gemma.intevation.de/gemma/pkg/common"
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 )
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27
5403
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
28 type SurveyType string
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
29
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
30 const (
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
31 SurveyTypeMultiBeam = SurveyType("multi")
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
32 SurveyTypeSingleBeam = SurveyType("single")
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
33 SurveyTypeMarking = SurveyType("marking")
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
34 )
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
35
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 type (
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 SoundingResultMeta struct {
5403
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
38 Date Date `json:"date"`
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
39 Bottleneck string `json:"bottleneck"`
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
40 EPSG uint `json:"epsg"`
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
41 DepthReference string `json:"depth-reference"`
5407
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
42 SingleBeam *bool `json:"single-beam,omitempty"` // kept in for compat!
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
43 SurveyType SurveyType `json:"survey-type,omitempty"`
5403
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
44 NegateZ bool `json:"negate-z,omitempty"`
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 }
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 )
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
5403
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
48 func (st *SurveyType) UnmarshalJSON(data []byte) error {
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
49 var s string
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
50 if err := json.Unmarshal(data, &s); err != nil {
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
51 return err
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
52 }
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
53 switch x := SurveyType(s); x {
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
54 case SurveyTypeMultiBeam, SurveyTypeSingleBeam, SurveyTypeMarking:
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
55 *st = x
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
56 return nil
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
57 default:
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
58 return fmt.Errorf("unkown survey type '%s'", s)
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
59 }
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
60 }
85f19e924a43 Adjusted the import model to be able to handle marking single beam scans.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4055
diff changeset
61
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 const (
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 checkDepthReferenceSQL = `
2961
5bc941d9ec43 Fix checking of depth reference for sounding result
Tom Gottfried <tom@intevation.de>
parents: 2345
diff changeset
64 SELECT EXISTS(SELECT 1
5bc941d9ec43 Fix checking of depth reference for sounding result
Tom Gottfried <tom@intevation.de>
parents: 2345
diff changeset
65 FROM waterway.bottlenecks bn
3302
ec6163c6687d 'Historicise' gauges on import
Tom Gottfried <tom@intevation.de>
parents: 2961
diff changeset
66 JOIN waterway.gauges g
4055
98e2041c7ebf Adapted sr-import to new historization model.
Sascha Wilde <wilde@intevation.de>
parents: 3945
diff changeset
67 ON bn.gauge_location = g.location AND $3::timestamptz <@ g.validity
3645
02951a62e8c6 'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents: 3585
diff changeset
68 JOIN waterway.gauges_reference_water_levels rl
02951a62e8c6 'Historicise' bottlenecks on import
Tom Gottfried <tom@intevation.de>
parents: 3585
diff changeset
69 ON g.location = rl.location AND g.validity = rl.validity
2961
5bc941d9ec43 Fix checking of depth reference for sounding result
Tom Gottfried <tom@intevation.de>
parents: 2345
diff changeset
70 WHERE bn.objnam = $1
5bc941d9ec43 Fix checking of depth reference for sounding result
Tom Gottfried <tom@intevation.de>
parents: 2345
diff changeset
71 AND rl.depth_reference = $2)`
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 checkBottleneckSQL = `
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 SELECT true FROM waterway.bottlenecks WHERE objnam = $1`
1297
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
75
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
76 checkBottleneckDateUniqueSQL = `
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
77 SELECT true FROM waterway.sounding_results sr JOIN
3656
2a079d0a71c1 Ensure sounding results are associated to matching bottleneck version
Tom Gottfried <tom@intevation.de>
parents: 3645
diff changeset
78 waterway.bottlenecks bn ON sr.bottleneck_id = bn.bottleneck_id
1297
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
79 WHERE bn.objnam = $1 AND sr.date_info = $2`
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 )
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 func (m *SoundingResultMeta) Decode(r io.Reader) error {
5427
235cfce555b5 Minor clean-up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5407
diff changeset
83 if err := json.NewDecoder(r).Decode(m); err != nil {
5407
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
84 return err
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
85 }
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
86
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
87 if m.EPSG == 0 {
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 m.EPSG = WGS84
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 }
5407
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
90
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
91 if m.SingleBeam != nil {
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
92 // Check if single-beam and survey-type match.
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
93 if m.SurveyType != "" {
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
94 if (*m.SingleBeam && m.SurveyType != SurveyTypeSingleBeam) ||
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
95 (!*m.SingleBeam && m.SurveyType != SurveyTypeMultiBeam) {
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
96 return errors.New("'single-beam' and 'survey-type' mismatch")
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
97 }
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
98 } else { // Only single-beam given
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
99 if *m.SingleBeam {
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
100 m.SurveyType = SurveyTypeSingleBeam
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
101 } else {
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
102 m.SurveyType = SurveyTypeMultiBeam
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
103 }
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
104 }
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
105 // Kill single-beam
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
106 m.SingleBeam = nil
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
107 }
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
108
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
109 if m.SurveyType == "" { // default to multi-beam
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
110 m.SurveyType = SurveyTypeMultiBeam
850f5847d18a Re-establish compat with old single-beam interface.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5403
diff changeset
111 }
5427
235cfce555b5 Minor clean-up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5407
diff changeset
112
235cfce555b5 Minor clean-up.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5407
diff changeset
113 return nil
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 }
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115
1328
d753ce6cf588 To make golint happier made context.Context to be the first argument in all calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1297
diff changeset
116 func (m *SoundingResultMeta) Validate(ctx context.Context, conn *sql.Conn) []error {
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 var errs []error
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120 var b bool
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121 err := conn.QueryRowContext(ctx,
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122 checkBottleneckSQL,
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 m.Bottleneck).Scan(&b)
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 switch {
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 case err == sql.ErrNoRows:
1330
785f14264426 Follow the rules for error messages to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1328
diff changeset
126 errs = append(errs, fmt.Errorf("unknown bottleneck '%s'", m.Bottleneck))
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127 case err != nil:
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128 errs = append(errs, err)
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 case !b:
1331
275ead19b9fd More on following the rules for error messages to make golint happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1330
diff changeset
130 errs = append(errs, errors.New("unexpected bottleneck"))
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 }
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132
3895
07b2df71bb4a Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3656
diff changeset
133 if m.DepthReference != "ZPG" {
07b2df71bb4a Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3656
diff changeset
134 err = conn.QueryRowContext(ctx,
07b2df71bb4a Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3656
diff changeset
135 checkDepthReferenceSQL,
07b2df71bb4a Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3656
diff changeset
136 m.Bottleneck,
4055
98e2041c7ebf Adapted sr-import to new historization model.
Sascha Wilde <wilde@intevation.de>
parents: 3945
diff changeset
137 m.DepthReference,
98e2041c7ebf Adapted sr-import to new historization model.
Sascha Wilde <wilde@intevation.de>
parents: 3945
diff changeset
138 m.Date.Time).Scan(&b)
3895
07b2df71bb4a Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3656
diff changeset
139 switch {
07b2df71bb4a Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3656
diff changeset
140 case !b:
07b2df71bb4a Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3656
diff changeset
141 errs = append(errs,
07b2df71bb4a Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3656
diff changeset
142 fmt.Errorf("unknown depth reference '%s'", m.DepthReference))
07b2df71bb4a Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3656
diff changeset
143 case err != nil:
07b2df71bb4a Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3656
diff changeset
144 errs = append(errs, err)
07b2df71bb4a Allow 'ZPG' as a depth reference system in meta.json files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3656
diff changeset
145 }
2961
5bc941d9ec43 Fix checking of depth reference for sounding result
Tom Gottfried <tom@intevation.de>
parents: 2345
diff changeset
146 }
5bc941d9ec43 Fix checking of depth reference for sounding result
Tom Gottfried <tom@intevation.de>
parents: 2345
diff changeset
147
5bc941d9ec43 Fix checking of depth reference for sounding result
Tom Gottfried <tom@intevation.de>
parents: 2345
diff changeset
148 err = conn.QueryRowContext(ctx,
1297
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
149 checkBottleneckDateUniqueSQL,
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
150 m.Bottleneck, m.Date.Time).Scan(&b)
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
151 switch {
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
152 case err == sql.ErrNoRows: // good! -> unique.
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
153 case err != nil:
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
154 errs = append(errs, err)
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
155 case b:
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
156 errs = append(errs,
2345
df6383831ad3 Sounding result import: Be more verbose if sounding result already exists for a bottleneck/date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
157 fmt.Errorf("sounding result for date %s already exists at bottleneck '%s'",
df6383831ad3 Sounding result import: Be more verbose if sounding result already exists for a bottleneck/date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
158 m.Date.Time.Format(common.DateFormat),
df6383831ad3 Sounding result import: Be more verbose if sounding result already exists for a bottleneck/date.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1900
diff changeset
159 m.Bottleneck))
1297
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
160 }
1c0c9190fcf2 Import sounding result: If uploading a zip with a meta.json which has
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1224
diff changeset
161
1224
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 return errs
bc4b642c8d04 Started with an upload sounding result to temp upload area.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 }