diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/imports/bn.go	Fri Dec 07 13:08:17 2018 +0100
@@ -0,0 +1,104 @@
+// 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 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 (
+	"context"
+	"database/sql"
+	"errors"
+
+	"gemma.intevation.de/gemma/pkg/common"
+	"gemma.intevation.de/gemma/pkg/soap/ifbn"
+)
+
+type Bottleneck struct {
+	URL      string `json:"url"`
+	Insecure bool   `json:"insecure"`
+}
+
+const BNJobKind JobKind = "bn"
+
+type bnJobCreator struct{}
+
+func init() {
+	RegisterJobCreator(BNJobKind, bnJobCreator{})
+}
+
+func (bnJobCreator) Create(_ JobKind, data string) (Job, error) {
+	bn := new(Bottleneck)
+	if err := common.FromJSONString(data, bn); err != nil {
+		return nil, err
+	}
+	return bn, nil
+}
+
+func (bnJobCreator) Depends() []string {
+	return []string{
+		"waterway.gauges",
+		"waterway.bottlenecks",
+	}
+}
+
+const (
+	bnStageDoneSQL = `
+UPDATE waterway.sounding_results SET staging_done = true
+WHERE id = (
+  SELECT key from waterway.track_imports
+  WHERE import_id = $1 AND
+        relation = 'waterway.sounding_results'::regclass)`
+)
+
+// StageDone moves the imported bottleneck out of the staging area.
+func (bnJobCreator) StageDone(
+	ctx context.Context,
+	tx *sql.Tx,
+	id int64,
+) error {
+	_, err := tx.ExecContext(ctx, srStageDoneSQL, id)
+	return err
+}
+
+// CleanUp of a bottleneck import is a NOP.
+func (bn *Bottleneck) CleanUp() error { return nil }
+
+// Do executes the actual bottleneck import.
+func (bn *Bottleneck) Do(
+	ctx context.Context,
+	importID int64,
+	conn *sql.Conn,
+	feedback Feedback,
+) (interface{}, error) {
+	client := ifbn.NewIBottleneckService(bn.URL, bn.Insecure, nil)
+
+	req := &ifbn.Export_bn_by_isrs{}
+
+	resp, err := client.Export_bn_by_isrs(req)
+	if err != nil {
+		feedback.Error("%v", err)
+		return nil, err
+	}
+
+	if resp.Export_bn_by_isrsResult == nil {
+		err := errors.New("no Bottlenecks found")
+		feedback.Error("%v", err)
+		return nil, err
+	}
+
+	// TODO: Implement me!
+	bns := resp.Export_bn_by_isrsResult.BottleNeckType
+
+	_ = bns
+
+	return nil, nil
+}