changeset 5326:96ceb150ea46 extented-report

Added infrastructure for report 'import'.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 30 May 2021 13:18:10 +0200
parents 80d9fd782f00
children c008e13fa1d1
files pkg/controllers/routes.go pkg/imports/modelconvert.go pkg/imports/report.go
diffstat 3 files changed, 74 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/routes.go	Thu May 27 15:09:13 2021 +0200
+++ b/pkg/controllers/routes.go	Sun May 30 13:18:10 2021 +0200
@@ -251,6 +251,7 @@
 		"fm_rtpbcn",
 		"fm_topmar",
 		"fm_notmrk",
+		"report",
 	}, "|")
 
 	api.Handle("/imports/{kind:"+kinds+"}", waterwayAdmin(&mw.JSONHandler{
--- a/pkg/imports/modelconvert.go	Thu May 27 15:09:13 2021 +0200
+++ b/pkg/imports/modelconvert.go	Sun May 30 13:18:10 2021 +0200
@@ -45,6 +45,7 @@
 	DSECJobKind:        func() interface{} { return new(models.SectionDelete) },
 	DSTJobKind:         func() interface{} { return new(models.StretchDelete) },
 	DSRJobKind:         func() interface{} { return new(models.SoundingResultDelete) },
+	ReportJobKind:      func() interface{} { return FindJobCreator(ReportJobKind).Create() },
 }
 
 // ImportModelForJobKind returns the constructor function to
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/imports/report.go	Sun May 30 13:18:10 2021 +0200
@@ -0,0 +1,72 @@
+// 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 Report struct {
+	Name string `json:"Name"`
+}
+
+const ReportJobKind JobKind = "report"
+
+type reportJobCreator struct{}
+
+func init() { RegisterJobCreator(ReportJobKind, ReportJobKind{}) }
+
+func (reportJobCreator) Description() string { return "report" }
+
+func (reportJobCreator) AutoAccept() bool { return true }
+
+func (reportJobCreator) Create() Job { return new(Report) }
+
+func (reportJobCreator) Depends() [2][]string { return [2][]string{{}, {}} }
+
+func (reportJobCreator) StageDone(context.Context, *sql.Tx, int64, Feedback) error {
+	return nil
+}
+
+func (r *Report) Description() (string, error) { return r.Name, nil }
+
+func (r *Report) MarshalAttributes(attrs common.Attributes) error {
+	attrs.Set("name", r.Name)
+	return nil
+}
+
+func (r *Report) UnmarshalAttributes(attrs common.Attributes) error {
+	name, found := attrs.Get("name")
+	if !found {
+		return errors.New("missing 'name' attribute")
+	}
+	r.Name = name
+	return nil
+}
+
+func (r *Report) Do(
+	ctx context.Context,
+	importID int64,
+	conn *sql.Conn,
+	feedback Feedback,
+) (interface{}, error) {
+
+	// TODO: Implement me!
+
+	return nil, nil
+}