view pkg/imports/report.go @ 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
children bc8c082487b2
line wrap: on
line source

// 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
}