Mercurial > gemma
changeset 1808:77582da3adb0
Waterway gauges import: Added stub.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 15 Jan 2019 16:51:38 +0100 |
parents | 824e7b7d81a4 |
children | b16a6db0008f |
files | pkg/controllers/manualimports.go pkg/controllers/routes.go pkg/imports/scheduled.go pkg/imports/wg.go pkg/models/waterway.go |
diffstat | 5 files changed, 126 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/manualimports.go Tue Jan 15 14:51:44 2019 +0100 +++ b/pkg/controllers/manualimports.go Tue Jan 15 16:51:38 2019 +0100 @@ -87,6 +87,21 @@ return wa, due, retries, wai.SendEmail } +func importWaterwayGauge(input interface{}) (interface{}, time.Time, int, bool) { + wgi := input.(*models.WaterwayGaugeImport) + username, _ := wgi.Attributes.Get("username") + password, _ := wgi.Attributes.Get("password") + insecure := wgi.Attributes.Bool("insecure") + wg := &imports.WaterwayGauge{ + URL: wgi.URL, + Username: username, + Password: password, + Insecure: insecure, + } + due, retries := retry(wgi.Attributes) + return wg, due, retries, wgi.SendEmail +} + func manualImport( kind imports.JobKind, setup func(interface{}) (interface{}, time.Time, int, bool),
--- a/pkg/controllers/routes.go Tue Jan 15 14:51:44 2019 +0100 +++ b/pkg/controllers/routes.go Tue Jan 15 16:51:38 2019 +0100 @@ -205,6 +205,12 @@ NoConn: true, })).Methods(http.MethodPost) + api.Handle("/imports/waterwaygauge", waterwayAdmin(&JSONHandler{ + Input: func() interface{} { return new(models.WaterwayGaugeImport) }, + Handle: manualImport(imports.WGJobKind, importWaterwayGauge), + NoConn: true, + })).Methods(http.MethodPost) + // Import scheduler configuration api.Handle("/imports/config/{id:[0-9]+}/run", waterwayAdmin(&JSONHandler{
--- a/pkg/imports/scheduled.go Tue Jan 15 14:51:44 2019 +0100 +++ b/pkg/imports/scheduled.go Tue Jan 15 16:51:38 2019 +0100 @@ -87,6 +87,19 @@ SortBy: sb, }, nil }, + + WGJobKind: func(cfg *IDConfig) (interface{}, error) { + log.Println("info: schedule 'wg' import") + username, _ := cfg.Attributes.Get("username") + password, _ := cfg.Attributes.Get("password") + insecure := cfg.Attributes.Bool("insecure") + return &WaterwayGauge{ + URL: *cfg.URL, + Username: username, + Password: password, + Insecure: insecure, + }, nil + }, } func init() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/imports/wg.go Tue Jan 15 16:51:38 2019 +0100 @@ -0,0 +1,81 @@ +// 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" +) + +type WaterwayGauge struct { + // URL is the URL of the SOAP service. + URL string `json:"url"` + // Username is the username used to authenticate. + Username string `json:"username"` + // Passwort is the password to authenticate. + Password string `json:"password"` + // Insecure indicates if HTTPS traffic + // should validate certificates or not. + Insecure bool `json:"insecure"` +} + +const WGJobKind JobKind = "wg" + +type wgJobCreator struct{} + +func init() { + RegisterJobCreator(WGJobKind, wgJobCreator{}) +} + +func (wgJobCreator) Description() string { return "waterway gauges" } + +func (wgJobCreator) AutoAccept() bool { return false } + +func (wgJobCreator) Create(_ JobKind, data string) (Job, error) { + wg := new(WaterwayGauge) + if err := common.FromJSONString(data, wg); err != nil { + return nil, err + } + return wg, nil +} + +func (wgJobCreator) Depends() []string { + return []string{ + "gauges", + } +} + +func (wgJobCreator) StageDone( + ctx context.Context, + tx *sql.Tx, + id int64, +) error { + // TODO: Implement me! + return nil +} + +func (*WaterwayGauge) CleanUp() error { return nil } + +func (wg *WaterwayGauge) Do( + ctx context.Context, + importID int64, + conn *sql.Conn, + feedback Feedback, +) (interface{}, error) { + // TODO: Implement me! + return nil, errors.New("Not implemented, yet!") +}
--- a/pkg/models/waterway.go Tue Jan 15 14:51:44 2019 +0100 +++ b/pkg/models/waterway.go Tue Jan 15 16:51:38 2019 +0100 @@ -45,4 +45,15 @@ // Attributes are optional attributes. Attributes common.Attributes `json:"attributes,omitempty"` } + + // WaterwayAxisImport specifies an import of waterway gauges. + WaterwayGaugeImport struct { + // URL is the SOAP service URL. + URL string `json:"url"` + // SendEmail is set to true if an email should be send after + // importing the waterway gauges. + SendEmail bool `json:"send-email"` + // Attributes are optional attributes. + Attributes common.Attributes `json:"attributes,omitempty"` + } )