Mercurial > gemma
changeset 2046:725884a4c89a unify_imports
Imports: Re-enabled /imports/config/{id} GET-
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 25 Jan 2019 18:17:37 +0100 |
parents | 10a1e139d2e8 |
children | 78002c5e838c |
files | pkg/controllers/importconfig.go |
diffstat | 1 files changed, 41 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/importconfig.go Fri Jan 25 18:01:35 2019 +0100 +++ b/pkg/controllers/importconfig.go Fri Jan 25 18:17:37 2019 +0100 @@ -15,11 +15,13 @@ import ( "database/sql" + "fmt" "net/http" "strconv" "github.com/gorilla/mux" + "gemma.intevation.de/gemma/pkg/common" "gemma.intevation.de/gemma/pkg/imports" ) @@ -28,10 +30,7 @@ SELECT id, username, - kind, - send_email, - cron, - url + kind FROM import.import_configuration` selectImportConfigurationSQL = selectImportConfigurationPrefix + ` @@ -42,8 +41,8 @@ insertImportConfigurationSQL = ` INSERT INTO import.import_configuration -(username, kind, cron, send_email) -VALUES ($1, $2, $3, $4, $5) +(username, kind) +VALUES ($1, $2) RETURNING id` insertImportConfigurationAttributeSQL = ` @@ -66,11 +65,8 @@ updateImportConfigurationSQL = ` UPDATE import.import_configuration SET username = $2, - kind = $3, - cron = $4, - send_email = $5 -WHERE id = $1 -` + kind = $3 +WHERE id = $1` ) func runImportConfig( @@ -217,28 +213,46 @@ conn *sql.Conn, ) (jr JSONResult, err error) { - /* - - ctx := req.Context() + ctx := req.Context() - id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) + id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) - var entry *imports.IDConfig + var cfg *imports.PersistentConfig - entry, err = imports.LoadIDConfigContext(ctx, conn, id) - switch { - case err != nil: - return - case entry == nil: - err = JSONError{ - Code: http.StatusNotFound, - Message: fmt.Sprintf("No schedule %d found", id), - } + cfg, err = imports.LoadPersistentConfigContext(ctx, conn, id) + switch { + case err != nil: + return + case cfg == nil: + err = JSONError{ + Code: http.StatusNotFound, + Message: fmt.Sprintf("No schedule %d found", id), + } + return + } + + kind := imports.JobKind(cfg.Kind) + + ctor := imports.ImportModelForJobKind(kind) + if ctor == nil { + err = JSONError{ + Code: http.StatusInternalServerError, + Message: fmt.Sprintf("No constructor for kind '%s' found", cfg.Kind), + } + } + what := ctor() + + if um, ok := what.(common.AttributesUnmarshaler); ok { + if err = um.UnmarshalAttributes(cfg.Attributes); err != nil { return } + } - jr = JSONResult{Result: &entry} - */ + jr = JSONResult{Result: &imports.ImportConfigOut{ + ID: id, + Kind: imports.ImportKind(cfg.Kind), + Config: what, + }} return }