changeset 4311:f9bb06f2dbe3

Added stub for a shape upload stretch import. POST /api/imports/stsh
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 03 Sep 2019 13:02:09 +0200
parents 3d6941046858
children 8926fc81e4de
files pkg/controllers/routes.go pkg/controllers/uploadedimports.go pkg/imports/st.go pkg/imports/stsh.go
diffstat 4 files changed, 80 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/routes.go	Mon Sep 02 22:36:31 2019 +0200
+++ b/pkg/controllers/routes.go	Tue Sep 03 13:02:09 2019 +0200
@@ -229,6 +229,9 @@
 	api.Handle("/imports/ugm", waterwayAdmin(
 		importUploadedGaugeMeasurement())).Methods(http.MethodPost)
 
+	api.Handle("/imports/stsh", sysAdmin(
+		importUploadedStretchShape())).Methods(http.MethodPost)
+
 	api.Handle("/imports/{kind:st}", sysAdmin(&mw.JSONHandler{
 		Input:  importModel,
 		Handle: manualImport,
--- a/pkg/controllers/uploadedimports.go	Mon Sep 02 22:36:31 2019 +0200
+++ b/pkg/controllers/uploadedimports.go	Tue Sep 03 13:02:09 2019 +0200
@@ -135,6 +135,16 @@
 	)
 }
 
+func importUploadedStretchShape() http.HandlerFunc {
+	return uploadedImport(
+		imports.STSHJobKind,
+		"stretch.zip",
+		func(_ *http.Request, dir string) (imports.Job, error) {
+			return &imports.StretchShape{Dir: dir}, nil
+		},
+	)
+}
+
 func (bup badUploadParameterError) Error() string {
 	return string(bup)
 }
--- a/pkg/imports/st.go	Mon Sep 02 22:36:31 2019 +0200
+++ b/pkg/imports/st.go	Tue Sep 03 13:02:09 2019 +0200
@@ -40,9 +40,7 @@
 
 type stJobCreator struct{}
 
-func init() {
-	RegisterJobCreator(STJobKind, stJobCreator{})
-}
+func init() { RegisterJobCreator(STJobKind, stJobCreator{}) }
 
 func (stJobCreator) Description() string { return "stretch" }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/imports/stsh.go	Tue Sep 03 13:02:09 2019 +0200
@@ -0,0 +1,66 @@
+// 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) 2019 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"
+	"os"
+)
+
+type StretchShape struct {
+	Dir string `json:"dir"`
+}
+
+const STSHJobKind JobKind = "stsh"
+
+type stshJobCreator struct{}
+
+func init() { RegisterJobCreator(STSHJobKind, stshJobCreator{}) }
+
+func (stshJobCreator) Description() string { return "stretch from shape" }
+
+func (stshJobCreator) AutoAccept() bool { return false }
+
+func (stshJobCreator) Create() Job { return new(StretchShape) }
+
+func (stshJobCreator) Depends() [2][]string {
+	return [2][]string{
+		{"stretches", "stretch_countries"},
+		{},
+	}
+}
+
+func (stshJobCreator) StageDone(
+	ctx context.Context,
+	tx *sql.Tx,
+	id int64,
+) error {
+	// TODO: Implement me!
+	return nil
+}
+
+func (stsh *StretchShape) CleanUp() error {
+	return os.RemoveAll(stsh.Dir)
+}
+
+func (stsh *StretchShape) Do(
+	ctx context.Context,
+	importID int64,
+	conn *sql.Conn,
+	feedback Feedback,
+) (interface{}, error) {
+	// TODO: Implement me!
+	return nil, nil
+}