comparison pkg/imports/bn.go @ 1531:24445a618513

Added stub for bottleneck importer.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 07 Dec 2018 13:08:17 +0100
parents
children 8fc1a2298acb
comparison
equal deleted inserted replaced
1530:e7830ab6bacc 1531:24445a618513
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 "context"
18 "database/sql"
19 "errors"
20
21 "gemma.intevation.de/gemma/pkg/common"
22 "gemma.intevation.de/gemma/pkg/soap/ifbn"
23 )
24
25 type Bottleneck struct {
26 URL string `json:"url"`
27 Insecure bool `json:"insecure"`
28 }
29
30 const BNJobKind JobKind = "bn"
31
32 type bnJobCreator struct{}
33
34 func init() {
35 RegisterJobCreator(BNJobKind, bnJobCreator{})
36 }
37
38 func (bnJobCreator) Create(_ JobKind, data string) (Job, error) {
39 bn := new(Bottleneck)
40 if err := common.FromJSONString(data, bn); err != nil {
41 return nil, err
42 }
43 return bn, nil
44 }
45
46 func (bnJobCreator) Depends() []string {
47 return []string{
48 "waterway.gauges",
49 "waterway.bottlenecks",
50 }
51 }
52
53 const (
54 bnStageDoneSQL = `
55 UPDATE waterway.sounding_results SET staging_done = true
56 WHERE id = (
57 SELECT key from waterway.track_imports
58 WHERE import_id = $1 AND
59 relation = 'waterway.sounding_results'::regclass)`
60 )
61
62 // StageDone moves the imported bottleneck out of the staging area.
63 func (bnJobCreator) StageDone(
64 ctx context.Context,
65 tx *sql.Tx,
66 id int64,
67 ) error {
68 _, err := tx.ExecContext(ctx, srStageDoneSQL, id)
69 return err
70 }
71
72 // CleanUp of a bottleneck import is a NOP.
73 func (bn *Bottleneck) CleanUp() error { return nil }
74
75 // Do executes the actual bottleneck import.
76 func (bn *Bottleneck) Do(
77 ctx context.Context,
78 importID int64,
79 conn *sql.Conn,
80 feedback Feedback,
81 ) (interface{}, error) {
82 client := ifbn.NewIBottleneckService(bn.URL, bn.Insecure, nil)
83
84 req := &ifbn.Export_bn_by_isrs{}
85
86 resp, err := client.Export_bn_by_isrs(req)
87 if err != nil {
88 feedback.Error("%v", err)
89 return nil, err
90 }
91
92 if resp.Export_bn_by_isrsResult == nil {
93 err := errors.New("no Bottlenecks found")
94 feedback.Error("%v", err)
95 return nil, err
96 }
97
98 // TODO: Implement me!
99 bns := resp.Export_bn_by_isrsResult.BottleNeckType
100
101 _ = bns
102
103 return nil, nil
104 }