annotate pkg/controllers/importconfig.go @ 2050:a3ccef8ec304 unify_imports

Imports: Re-enabled /imports/config/{id} DELETE.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 27 Jan 2019 22:03:46 +0100
parents d1a680be7ae4
children 7d627258e045
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1582
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 // This is Free Software under GNU Affero General Public License v >= 3.0
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2 // without warranty, see README.md and license for details.
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 //
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 // SPDX-License-Identifier: AGPL-3.0-or-later
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 // License-Filename: LICENSES/AGPL-3.0.txt
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 //
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 // Copyright (C) 2018 by via donau
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 // Software engineering by Intevation GmbH
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 //
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 // Author(s):
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 package controllers
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import (
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 "database/sql"
2046
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
18 "fmt"
1582
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 "net/http"
2045
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
20 "strconv"
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
21
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
22 "github.com/gorilla/mux"
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
23
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
24 "gemma.intevation.de/gemma/pkg/imports"
2050
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
25 "gemma.intevation.de/gemma/pkg/scheduler"
1583
caedd9b176f2 Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1582
diff changeset
26 )
caedd9b176f2 Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1582
diff changeset
27
caedd9b176f2 Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1582
diff changeset
28 const (
2049
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
29 selectImportConfigurationIDSQL = `
1583
caedd9b176f2 Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1582
diff changeset
30 SELECT
caedd9b176f2 Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1582
diff changeset
31 id,
caedd9b176f2 Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1582
diff changeset
32 username,
2046
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
33 kind
2049
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
34 FROM import.import_configuration
1591
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
35 WHERE id = $1`
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
36
1589
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
37 insertImportConfigurationSQL = `
1995
59055c8301df Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents: 1763
diff changeset
38 INSERT INTO import.import_configuration
2046
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
39 (username, kind)
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
40 VALUES ($1, $2)
1589
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
41 RETURNING id`
1590
2fdd8e57542d Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1589
diff changeset
42
1702
49b89575ab31 Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1654
diff changeset
43 insertImportConfigurationAttributeSQL = `
1995
59055c8301df Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents: 1763
diff changeset
44 INSERT INTO import.import_configuration_attributes
1702
49b89575ab31 Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1654
diff changeset
45 (import_configuration_id, k, v)
49b89575ab31 Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1654
diff changeset
46 VALUES ($1, $2, $3)`
1582
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 )
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
1730
7c54babe10f7 Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1727
diff changeset
49 func runImportConfig(
7c54babe10f7 Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1727
diff changeset
50 _ interface{},
7c54babe10f7 Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1727
diff changeset
51 req *http.Request,
1748
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1739
diff changeset
52 conn *sql.Conn,
1730
7c54babe10f7 Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1727
diff changeset
53 ) (jr JSONResult, err error) {
7c54babe10f7 Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1727
diff changeset
54
2045
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
55 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64)
1730
7c54babe10f7 Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1727
diff changeset
56
2045
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
57 ctx := req.Context()
1748
c11807dc6940 Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1739
diff changeset
58
2045
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
59 var jobID int64
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
60 if jobID, err = imports.RunConfiguredImportContext(ctx, conn, id); err != nil {
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
61 return
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
62 }
1730
7c54babe10f7 Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1727
diff changeset
63
2045
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
64 var result = struct {
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
65 ID int64 `json:"id"`
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
66 }{
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
67 ID: jobID,
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
68 }
1730
7c54babe10f7 Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1727
diff changeset
69
2045
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
70 jr = JSONResult{
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
71 Code: http.StatusCreated,
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
72 Result: &result,
10a1e139d2e8 Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2042
diff changeset
73 }
1730
7c54babe10f7 Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1727
diff changeset
74 return
7c54babe10f7 Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1727
diff changeset
75 }
7c54babe10f7 Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1727
diff changeset
76
1627
b10aa02d7819 Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1592
diff changeset
77 func modifyImportConfig(
1592
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
78 input interface{},
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
79 req *http.Request,
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
80 conn *sql.Conn,
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
81 ) (jr JSONResult, err error) {
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
82
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
83 /*
1592
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
84
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
85 ctx := req.Context()
1592
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
86
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
87 importConfig := input.(*imports.Config)
1592
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
88
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
89 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64)
1592
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
90
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
91 var tx *sql.Tx
1592
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
92
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
93 if tx, err = conn.BeginTx(ctx, nil); err != nil {
1704
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
94 return
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
95 }
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
96 defer tx.Rollback()
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
97
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
98 var (
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
99 entry imports.IDConfig
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
100 kind string
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
101 dummy sql.NullString
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
102 url sql.NullString
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
103 )
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
104
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
105 err = conn.QueryRowContext(ctx, selectImportConfigurationIDSQL, id).Scan(
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
106 &entry.ID,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
107 &entry.User,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
108 &kind,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
109 &entry.SendEMail,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
110 &dummy,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
111 &url,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
112 )
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
113
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
114 switch {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
115 case err == sql.ErrNoRows:
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
116 err = JSONError{
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
117 Code: http.StatusNotFound,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
118 Message: fmt.Sprintf("No schedule %d found", id),
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
119 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
120 return
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
121 case err != nil:
1704
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
122 return
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
123 }
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
124
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
125 session, _ := auth.GetSession(req)
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
126
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
127 entry.SendEMail = importConfig.SendEMail
1704
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
128
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
129 // We always take the cron spec from the input.
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
130 // If there is no spec remove schedule.
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
131 var cron sql.NullString
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
132 if importConfig.Cron != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
133 cron = sql.NullString{String: string(*importConfig.Cron), Valid: true}
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
134 }
1592
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
135
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
136 if importConfig.URL != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
137 url = sql.NullString{String: *importConfig.URL, Valid: true}
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
138 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
139
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
140 if _, err = tx.ExecContext(ctx, updateImportConfigurationSQL,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
141 id,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
142 session.User,
1592
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
143 string(importConfig.Kind),
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
144 cron,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
145 url,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
146 importConfig.SendEMail,
1592
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
147 ); err != nil {
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
148 return
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
149 }
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
150
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
151 if importConfig.Attributes != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
152 if _, err = tx.ExecContext(ctx, deleteImportConfiguationAttributesSQL, id); err != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
153 return
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
154 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
155 if err = storeConfigAttributes(ctx, tx, id, importConfig.Attributes); err != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
156 return
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
157 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
158 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
159
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
160 scheduler.UnbindByID(id)
1592
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
161
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
162 if cron.Valid {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
163 if err = scheduler.BindAction(
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
164 string(importConfig.Kind),
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
165 cron.String,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
166 id,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
167 ); err != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
168 return
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
169 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
170 }
1592
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
171
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
172 if err = tx.Commit(); err != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
173 return
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
174 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
175
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
176 var result = struct {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
177 ID int64 `json:"id"`
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
178 }{
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
179 ID: id,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
180 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
181
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
182 jr = JSONResult{Result: &result}
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
183 */
1592
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
184 return
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
185 }
c12cec1d7692 Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1591
diff changeset
186
1627
b10aa02d7819 Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1592
diff changeset
187 func infoImportConfig(
1591
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
188 _ interface{},
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
189 req *http.Request,
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
190 conn *sql.Conn,
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
191 ) (jr JSONResult, err error) {
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
192
2046
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
193 ctx := req.Context()
1591
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
194
2046
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
195 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64)
1591
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
196
2046
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
197 var cfg *imports.PersistentConfig
1591
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
198
2046
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
199 cfg, err = imports.LoadPersistentConfigContext(ctx, conn, id)
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
200 switch {
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
201 case err != nil:
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
202 return
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
203 case cfg == nil:
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
204 err = JSONError{
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
205 Code: http.StatusNotFound,
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
206 Message: fmt.Sprintf("No schedule %d found", id),
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
207 }
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
208 return
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
209 }
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
210
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
211 kind := imports.JobKind(cfg.Kind)
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
212
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
213 ctor := imports.ImportModelForJobKind(kind)
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
214 if ctor == nil {
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
215 err = JSONError{
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
216 Code: http.StatusInternalServerError,
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
217 Message: fmt.Sprintf("No constructor for kind '%s' found", cfg.Kind),
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
218 }
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
219 }
2047
78002c5e838c Imports: Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2046
diff changeset
220
2046
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
221 what := ctor()
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
222
2047
78002c5e838c Imports: Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2046
diff changeset
223 if err = cfg.Attributes.Unmarshal(what); err != nil {
78002c5e838c Imports: Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2046
diff changeset
224 return
2046
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
225 }
1591
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
226
2046
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
227 jr = JSONResult{Result: &imports.ImportConfigOut{
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
228 ID: id,
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
229 Kind: imports.ImportKind(cfg.Kind),
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
230 Config: what,
725884a4c89a Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2045
diff changeset
231 }}
1591
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
232 return
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
233 }
2d53065c95af Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1590
diff changeset
234
1627
b10aa02d7819 Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1592
diff changeset
235 func deleteImportConfig(
1590
2fdd8e57542d Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1589
diff changeset
236 _ interface{},
2fdd8e57542d Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1589
diff changeset
237 req *http.Request,
2fdd8e57542d Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1589
diff changeset
238 conn *sql.Conn,
2fdd8e57542d Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1589
diff changeset
239 ) (jr JSONResult, err error) {
2fdd8e57542d Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1589
diff changeset
240
2050
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
241 ctx := req.Context()
1590
2fdd8e57542d Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1589
diff changeset
242
2050
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
243 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64)
1590
2fdd8e57542d Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1589
diff changeset
244
2050
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
245 var tx *sql.Tx
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
246 if tx, err = conn.BeginTx(ctx, nil); err != nil {
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
247 return
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
248 }
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
249 defer tx.Rollback()
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
250
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
251 err = imports.DeletePersistentConfigurationContext(
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
252 ctx,
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
253 tx,
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
254 id,
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
255 )
1704
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
256
2050
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
257 switch {
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
258 case err == sql.ErrNoRows:
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
259 err = JSONError{
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
260 Code: http.StatusNotFound,
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
261 Message: fmt.Sprintf("No configuration %d found", id),
2049
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
262 }
2050
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
263 return
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
264 case err != nil:
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
265 return
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
266 }
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
267
2050
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
268 // Remove from running scheduler.
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
269 scheduler.UnbindByID(id)
2049
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
270
2050
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
271 if err = tx.Commit(); err != nil {
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
272 return
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
273 }
1590
2fdd8e57542d Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1589
diff changeset
274
2050
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
275 var result = struct {
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
276 ID int64 `json:"id"`
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
277 }{
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
278 ID: id,
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
279 }
1590
2fdd8e57542d Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1589
diff changeset
280
2050
a3ccef8ec304 Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2049
diff changeset
281 jr = JSONResult{Result: &result}
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
282
1590
2fdd8e57542d Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1589
diff changeset
283 return
2fdd8e57542d Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1589
diff changeset
284 }
2fdd8e57542d Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1589
diff changeset
285
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
286 /*
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
287
1704
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
288 func storeConfigAttributes(
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
289 ctx context.Context,
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
290 tx *sql.Tx,
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
291 id int64,
1708
49e047c2106e Imports: Made imports re-runnable if they fail.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1704
diff changeset
292 attrs common.Attributes,
1704
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
293 ) error {
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
294 if len(attrs) == 0 {
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
295 return nil
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
296 }
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
297 attrStmt, err := tx.PrepareContext(ctx, insertImportConfigurationAttributeSQL)
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
298 if err != nil {
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
299 return err
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
300 }
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
301 defer attrStmt.Close()
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
302 // Sort to make it deterministic
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
303 keys := make([]string, len(attrs))
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
304 i := 0
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
305 for key := range attrs {
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
306 keys[i] = key
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
307 i++
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
308 }
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
309 sort.Strings(keys)
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
310 for _, key := range keys {
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
311 if _, err := attrStmt.ExecContext(ctx, id, key, attrs[key]); err != nil {
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
312 return err
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
313 }
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
314 }
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
315 return nil
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
316 }
897d4d8316ad Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1702
diff changeset
317
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
318 */
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
319
1627
b10aa02d7819 Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1592
diff changeset
320 func addImportConfig(
1589
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
321 input interface{},
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
322 req *http.Request,
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
323 conn *sql.Conn,
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
324 ) (jr JSONResult, err error) {
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
325
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
326 /*
1589
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
327
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
328 importConfig := input.(*imports.Config)
1589
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
329
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
330 session, _ := auth.GetSession(req)
1589
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
331
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
332 var cron, url sql.NullString
1589
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
333
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
334 if importConfig.Cron != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
335 cron = sql.NullString{String: string(*importConfig.Cron), Valid: true}
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
336 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
337 if importConfig.URL != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
338 url = sql.NullString{String: *importConfig.URL, Valid: true}
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
339 }
1589
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
340
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
341 ctx := req.Context()
1702
49b89575ab31 Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1654
diff changeset
342
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
343 var tx *sql.Tx
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
344
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
345 if tx, err = conn.BeginTx(ctx, nil); err != nil {
1589
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
346 return
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
347 }
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
348 defer tx.Rollback()
1589
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
349
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
350 var id int64
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
351 if err = tx.QueryRowContext(
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
352 ctx,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
353 insertImportConfigurationSQL,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
354 session.User,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
355 string(importConfig.Kind),
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
356 cron,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
357 importConfig.SendEMail,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
358 url,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
359 ).Scan(&id); err != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
360 return
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
361 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
362
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
363 // Store extra attributes
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
364 if err = storeConfigAttributes(ctx, tx, id, importConfig.Attributes); err != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
365 return
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
366 }
1589
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
367
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
368 // Need to start a scheduler job right away?
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
369 if importConfig.Cron != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
370 if err = scheduler.BindAction(
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
371 string(importConfig.Kind),
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
372 string(*importConfig.Cron),
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
373 id,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
374 ); err != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
375 return
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
376 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
377 }
1589
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
378
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
379 if err = tx.Commit(); err != nil {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
380 scheduler.UnbindByID(id)
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
381 return
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
382 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
383
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
384 var result = struct {
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
385 ID int64 `json:"id"`
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
386 }{
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
387 ID: id,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
388 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
389
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
390 jr = JSONResult{
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
391 Code: http.StatusCreated,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
392 Result: &result,
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
393 }
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
394 */
1589
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
395 return
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
396 }
e0bd82f6ee14 Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1583
diff changeset
397
1627
b10aa02d7819 Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1592
diff changeset
398 func listImportConfigs(
1582
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
399 _ interface{},
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
400 req *http.Request,
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
401 conn *sql.Conn,
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
402 ) (jr JSONResult, err error) {
1583
caedd9b176f2 Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1582
diff changeset
403
2049
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
404 ctx := req.Context()
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
405 configs := []*imports.ImportConfigOut{}
2042
d29ac997eb34 This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
406
2049
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
407 if err = imports.ListAllPersistentConfigurationsContext(
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
408 ctx, conn,
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
409 func(config *imports.ImportConfigOut) error {
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
410 configs = append(configs, config)
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
411 return nil
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
412 },
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
413 ); err != nil {
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
414 return
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
415 }
d1a680be7ae4 Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2048
diff changeset
416 jr = JSONResult{Result: configs}
1582
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
417 return
dc727824183a Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
418 }