comparison pkg/imports/wg.go @ 2318:06c4e57435f1

Warn on import of unknown reference level codes According to the RIS-Index encoding guide, reference level codes should be in line with the NtS reference_code table. Amend also the comment in the schema definition to reflect the 'should', which is not 'shall'.
author Tom Gottfried <tom@intevation.de>
date Mon, 18 Feb 2019 19:38:48 +0100
parents 8a8680e70d2e
children e199655809c1
comparison
equal deleted inserted replaced
2317:8a8680e70d2e 2318:06c4e57435f1
2 // without warranty, see README.md and license for details. 2 // without warranty, see README.md and license for details.
3 // 3 //
4 // SPDX-License-Identifier: AGPL-3.0-or-later 4 // SPDX-License-Identifier: AGPL-3.0-or-later
5 // License-Filename: LICENSES/AGPL-3.0.txt 5 // License-Filename: LICENSES/AGPL-3.0.txt
6 // 6 //
7 // Copyright (C) 2018 by via donau 7 // Copyright (C) 2018, 2019 by via donau
8 // – Österreichische Wasserstraßen-Gesellschaft mbH 8 // – Österreichische Wasserstraßen-Gesellschaft mbH
9 // Software engineering by Intevation GmbH 9 // Software engineering by Intevation GmbH
10 // 10 //
11 // Author(s): 11 // Author(s):
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> 12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
13 // * Tom Gottfried <tom.gottfried@intevation.de>
13 14
14 package imports 15 package imports
15 16
16 import ( 17 import (
17 "context" 18 "context"
111 zero_point = $12, 112 zero_point = $12,
112 geodref = $13, 113 geodref = $13,
113 date_info = $14, 114 date_info = $14,
114 source_organization = $15 115 source_organization = $15
115 ` 116 `
117 isNtSDepthRefSQL = `
118 SELECT EXISTS(SELECT 1 FROM depth_references WHERE depth_reference = $1)`
119
116 insertReferenceWaterLevelsSQL = ` 120 insertReferenceWaterLevelsSQL = `
117 INSERT INTO waterway.gauges_reference_water_levels ( 121 INSERT INTO waterway.gauges_reference_water_levels (
118 gauge_id, 122 gauge_id,
119 depth_reference, 123 depth_reference,
120 value 124 value
283 if err != nil { 287 if err != nil {
284 return nil, err 288 return nil, err
285 } 289 }
286 defer insertWaterLevelStmt.Close() 290 defer insertWaterLevelStmt.Close()
287 291
292 isNtSDepthRefStmt, err := tx.PrepareContext(ctx, isNtSDepthRefSQL)
293 if err != nil {
294 return nil, err
295 }
296 defer isNtSDepthRefStmt.Close()
297
288 // insert/update the gauges 298 // insert/update the gauges
289 for i := range news { 299 for i := range news {
290 ic := &news[i] 300 ic := &news[i]
291 dr := data.RisdataReturn[ic.idx] 301 dr := data.RisdataReturn[ic.idx]
292 302
394 {&dr.Reflevel3code, &dr.Reflevel3value}, 404 {&dr.Reflevel3code, &dr.Reflevel3value},
395 } { 405 } {
396 if *wl.level == nil || *wl.value == nil { 406 if *wl.level == nil || *wl.value == nil {
397 continue 407 continue
398 } 408 }
409
410 var isNtSDepthRef bool
411 if err := isNtSDepthRefStmt.QueryRowContext(
412 ctx,
413 string(**wl.level),
414 ).Scan(
415 &isNtSDepthRef,
416 ); err != nil {
417 return nil, err
418 }
419 if !isNtSDepthRef {
420 feedback.Warn(
421 "Reference level code '%s' is not in line with the NtS reference_code table",
422 string(**wl.level))
423 }
424
399 if _, err := insertWaterLevelStmt.ExecContext( 425 if _, err := insertWaterLevelStmt.ExecContext(
400 ctx, 426 ctx,
401 ic.code.CountryCode, 427 ic.code.CountryCode,
402 ic.code.LoCode, 428 ic.code.LoCode,
403 ic.code.FairwaySection, 429 ic.code.FairwaySection,