Mercurial > gemma
changeset 1855:bbd653a43a6a
Distance marks virtual import: Added stub.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 17 Jan 2019 11:45:33 +0100 |
parents | 79283856f9cb |
children | 5996b50d154a |
files | pkg/controllers/manualimports.go pkg/controllers/routes.go pkg/imports/dmv.go pkg/imports/scheduled.go pkg/models/distancemarks.go |
diffstat | 5 files changed, 141 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/manualimports.go Thu Jan 17 11:36:59 2019 +0100 +++ b/pkg/controllers/manualimports.go Thu Jan 17 11:45:33 2019 +0100 @@ -102,6 +102,21 @@ return wg, due, retries, wgi.SendEmail } +func importDistancemarksVirtual(input interface{}) (interface{}, time.Time, int, bool) { + dmvi := input.(*models.DistanceMarksVirtualImport) + username, _ := dmvi.Attributes.Get("username") + password, _ := dmvi.Attributes.Get("password") + insecure := dmvi.Attributes.Bool("insecure") + wg := &imports.DistanceMarksVirtual{ + URL: dmvi.URL, + Username: username, + Password: password, + Insecure: insecure, + } + due, retries := retry(dmvi.Attributes) + return wg, due, retries, dmvi.SendEmail +} + func importFairwayDimension(input interface{}) (interface{}, time.Time, int, bool) { fdi := input.(*models.FairwayDimensionImport) fd := &imports.FairwayDimension{
--- a/pkg/controllers/routes.go Thu Jan 17 11:36:59 2019 +0100 +++ b/pkg/controllers/routes.go Thu Jan 17 11:45:33 2019 +0100 @@ -211,6 +211,12 @@ NoConn: true, })).Methods(http.MethodPost) + api.Handle("/imports/distancemarksvirtual", waterwayAdmin(&JSONHandler{ + Input: func() interface{} { return new(models.DistanceMarksVirtualImport) }, + Handle: manualImport(imports.DMVJobKind, importDistancemarksVirtual), + NoConn: true, + })).Methods(http.MethodPost) + api.Handle("/imports/fairwaydimension", waterwayAdmin(&JSONHandler{ Input: func() interface{} { return new(models.FairwayDimensionImport) }, Handle: manualImport(imports.FDJobKind, importFairwayDimension),
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/imports/dmv.go Thu Jan 17 11:45:33 2019 +0100 @@ -0,0 +1,78 @@ +// 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 DistanceMarksVirtual 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 DMVJobKind JobKind = "dmv" + +type dmvJobCreator struct{} + +func init() { + RegisterJobCreator(DMVJobKind, dmvJobCreator{}) +} + +func (dmvJobCreator) Description() string { return "distance marks virtual" } + +func (dmvJobCreator) AutoAccept() bool { return true } + +func (dmvJobCreator) Create(_ JobKind, data string) (Job, error) { + dmv := new(DistanceMarksVirtual) + if err := common.FromJSONString(data, dmv); err != nil { + return nil, err + } + return dmv, nil +} + +func (dmvJobCreator) Depends() []string { + return []string{ + "distance_marks_virtual", + } +} + +// StageDone does nothing as there is no staging for distance marks virtual. +func (dmvJobCreator) StageDone(context.Context, *sql.Tx, int64) error { return nil } + +// CleanUp does nothing as there is nothing to cleanup with distance marks virtual. +func (*DistanceMarksVirtual) CleanUp() error { return nil } + +func (dmv *DistanceMarksVirtual) 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/imports/scheduled.go Thu Jan 17 11:36:59 2019 +0100 +++ b/pkg/imports/scheduled.go Thu Jan 17 11:45:33 2019 +0100 @@ -100,6 +100,19 @@ Insecure: insecure, }, nil }, + + DMVJobKind: func(cfg *IDConfig) (interface{}, error) { + log.Println("info: schedule 'dvm' import") + username, _ := cfg.Attributes.Get("username") + password, _ := cfg.Attributes.Get("password") + insecure := cfg.Attributes.Bool("insecure") + return &DistanceMarksVirtual{ + URL: *cfg.URL, + Username: username, + Password: password, + Insecure: insecure, + }, nil + }, } func init() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/models/distancemarks.go Thu Jan 17 11:45:33 2019 +0100 @@ -0,0 +1,29 @@ +// 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 models + +import "gemma.intevation.de/gemma/pkg/common" + +type ( + // DistanceMarksVirtualImport specifies an import of distance marks virtual. + DistanceMarksVirtualImport 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"` + } +)