Mercurial > gemma
annotate pkg/controllers/importconfig.go @ 1791:0f98ef2531a5
importschedule: frontend for waterway gauges etd
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 14 Jan 2019 12:09:34 +0100 |
parents | 4c21ff668b01 |
children | 59055c8301df |
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 ( |
1704
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
17 "context" |
1582
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "database/sql" |
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
|
19 "errors" |
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
|
20 "fmt" |
1582
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "net/http" |
1702
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1654
diff
changeset
|
22 "sort" |
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
|
23 "strconv" |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
24 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
25 "github.com/gorilla/mux" |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
26 |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
27 "gemma.intevation.de/gemma/pkg/auth" |
1708
49e047c2106e
Imports: Made imports re-runnable if they fail.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1704
diff
changeset
|
28 "gemma.intevation.de/gemma/pkg/common" |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
29 "gemma.intevation.de/gemma/pkg/imports" |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
30 "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
|
31 ) |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
32 |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
33 const ( |
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
|
34 selectImportConfigurationPrefix = ` |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
35 SELECT |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
36 id, |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
37 username, |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
38 kind, |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
39 send_email, |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
40 cron, |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
41 url |
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
|
42 FROM waterway.import_configuration` |
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
|
43 |
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
|
44 selectImportConfigurationSQL = selectImportConfigurationPrefix + ` |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
45 ORDER by id` |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
46 |
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
|
47 selectImportConfigurationIDSQL = selectImportConfigurationPrefix + ` |
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
|
48 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
|
49 |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
50 insertImportConfigurationSQL = ` |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
51 INSERT INTO waterway.import_configuration |
1754
807569b08513
Import queue: Auto acceptance is now a property of the import kind itself and is not configurable any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1748
diff
changeset
|
52 (username, kind, cron, send_email, url) |
1763
4c21ff668b01
Configured imports: Fixed SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1754
diff
changeset
|
53 VALUES ($1, $2, $3, $4, $5) |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
54 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
|
55 |
1702
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1654
diff
changeset
|
56 insertImportConfigurationAttributeSQL = ` |
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1654
diff
changeset
|
57 INSERT INTO waterway.import_configuration_attributes |
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1654
diff
changeset
|
58 (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
|
59 VALUES ($1, $2, $3)` |
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1654
diff
changeset
|
60 |
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
|
61 hasImportConfigurationSQL = ` |
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
|
62 SELECT true FROM waterway.import_configuration |
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
|
63 WHERE id = $1` |
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
|
64 |
1704
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
65 deleteImportConfiguationAttributesSQL = ` |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
66 DELETE FROM waterway.import_configuration_attributes |
1727
3adb834ed55e
Import extra attributes: Use right id column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
67 WHERE import_configuration_id = $1` |
1704
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
68 |
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
|
69 deleteImportConfiguationSQL = ` |
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
|
70 DELETE FROM waterway.import_configuration |
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
|
71 WHERE id = $1` |
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
|
72 |
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
|
73 updateImportConfigurationSQL = ` |
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
|
74 UPDATE waterway.import_configuration SET |
1733
4cf4d31eae0a
Configured imports: Fixed SQL statement when updating configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1730
diff
changeset
|
75 username = $2, |
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
|
76 kind = $3, |
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
|
77 cron = $4, |
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 url = $5, |
1763
4c21ff668b01
Configured imports: Fixed SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1754
diff
changeset
|
79 send_email = $6 |
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
|
80 WHERE id = $1 |
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 ` |
1582
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 ) |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 |
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
|
84 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
|
85 _ 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
|
86 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
|
87 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
|
88 ) (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
|
89 |
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
|
90 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
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
|
91 |
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
|
92 ctx := req.Context() |
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
|
93 |
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
|
94 var jobID int64 |
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
|
95 if jobID, err = imports.RunConfiguredImportContext(ctx, conn, id); err != nil { |
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
|
96 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
|
97 } |
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
|
98 |
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
|
99 var result = struct { |
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
|
100 ID int64 `json:"id"` |
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
|
101 }{ |
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
|
102 ID: jobID, |
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
|
103 } |
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
|
104 |
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
|
105 jr = JSONResult{ |
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
|
106 Code: http.StatusCreated, |
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
|
107 Result: &result, |
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
|
108 } |
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
|
109 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
|
110 } |
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
|
111 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 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
|
116 ) (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
|
117 |
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
|
118 ctx := req.Context() |
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
|
119 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
120 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
|
121 |
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
|
122 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
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
|
123 |
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
|
124 var tx *sql.Tx |
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
|
125 |
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
|
126 if tx, err = conn.BeginTx(ctx, nil); 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
|
127 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
|
128 } |
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
|
129 defer tx.Rollback() |
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
|
130 |
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
|
131 var ( |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
132 entry imports.IDConfig |
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
|
133 kind string |
1737
abcf21649bd1
Configured imports: Always take cron spec from input document when modifying a configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1735
diff
changeset
|
134 dummy sql.NullString |
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 url sql.NullString |
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
|
136 ) |
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
|
137 |
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
|
138 err = conn.QueryRowContext(ctx, selectImportConfigurationIDSQL, id).Scan( |
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
|
139 &entry.ID, |
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
|
140 &entry.User, |
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
|
141 &kind, |
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
|
142 &entry.SendEMail, |
1737
abcf21649bd1
Configured imports: Always take cron spec from input document when modifying a configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1735
diff
changeset
|
143 &dummy, |
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
|
144 &url, |
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
|
145 ) |
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
|
146 |
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 switch { |
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 case err == sql.ErrNoRows: |
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 err = JSONError{ |
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 Code: http.StatusNotFound, |
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
|
151 Message: fmt.Sprintf("No schedule %d found", id), |
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
|
152 } |
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
|
153 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
|
154 case 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
|
155 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
|
156 } |
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
|
157 |
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
|
158 session, _ := auth.GetSession(req) |
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
|
159 |
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
|
160 entry.SendEMail = importConfig.SendEMail |
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 |
1737
abcf21649bd1
Configured imports: Always take cron spec from input document when modifying a configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1735
diff
changeset
|
162 // We always take the cron spec from the input. |
abcf21649bd1
Configured imports: Always take cron spec from input document when modifying a configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1735
diff
changeset
|
163 // If there is no spec remove schedule. |
abcf21649bd1
Configured imports: Always take cron spec from input document when modifying a configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1735
diff
changeset
|
164 var cron sql.NullString |
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
|
165 if importConfig.Cron != 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
|
166 cron = sql.NullString{String: string(*importConfig.Cron), Valid: true} |
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
|
167 } |
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
|
168 |
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
|
169 if importConfig.URL != 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
|
170 url = sql.NullString{String: *importConfig.URL, Valid: true} |
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 } |
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
|
172 |
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
|
173 if _, err = tx.ExecContext(ctx, updateImportConfigurationSQL, |
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
|
174 id, |
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
|
175 session.User, |
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
|
176 string(importConfig.Kind), |
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
|
177 cron, |
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
|
178 url, |
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
|
179 importConfig.SendEMail, |
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
|
180 ); 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
|
181 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
|
182 } |
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
|
183 |
1704
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
184 if importConfig.Attributes != nil { |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
185 if _, err = tx.ExecContext(ctx, deleteImportConfiguationAttributesSQL, id); err != nil { |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
186 return |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
187 } |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
188 if err = storeConfigAttributes(ctx, tx, id, importConfig.Attributes); err != nil { |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
189 return |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
190 } |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
191 } |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
192 |
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
|
193 scheduler.UnbindByID(id) |
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
|
194 |
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
|
195 if cron.Valid { |
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
|
196 if err = scheduler.BindAction( |
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
|
197 string(importConfig.Kind), |
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
|
198 cron.String, |
1652
f39957ea08aa
Scheduled imports: The configuration id is not optional as it used to load the concrete configuration from the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
199 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
|
200 ); 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
|
201 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
|
202 } |
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
|
203 } |
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
|
204 |
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
|
205 if err = tx.Commit(); 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
|
206 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
|
207 } |
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
|
208 |
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
|
209 var result = struct { |
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
|
210 ID int64 `json:"id"` |
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
|
211 }{ |
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
|
212 ID: id, |
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
|
213 } |
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
|
214 |
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
|
215 jr = JSONResult{Result: &result} |
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
|
216 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
|
217 } |
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
|
218 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
219 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
|
220 _ 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
|
221 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
|
222 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
|
223 ) (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
|
224 |
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
|
225 ctx := req.Context() |
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 |
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
|
227 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
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
|
228 |
1739
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1737
diff
changeset
|
229 var entry *imports.IDConfig |
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
|
230 |
1739
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1737
diff
changeset
|
231 entry, err = imports.LoadIDConfigContext(ctx, conn, id) |
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 switch { |
1739
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1737
diff
changeset
|
233 case err != nil: |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1737
diff
changeset
|
234 return |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1737
diff
changeset
|
235 case entry == nil: |
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
|
236 err = JSONError{ |
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
|
237 Code: http.StatusNotFound, |
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
|
238 Message: fmt.Sprintf("No schedule %d found", id), |
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
|
239 } |
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
|
240 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
|
241 } |
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
|
242 |
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
|
243 jr = JSONResult{Result: &entry} |
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
|
244 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
|
245 } |
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
|
246 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
247 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
|
248 _ 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
|
249 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
|
250 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
|
251 ) (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
|
252 |
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
|
253 ctx := req.Context() |
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
|
254 |
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
|
255 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
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
|
256 |
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
|
257 var tx *sql.Tx |
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
|
258 if tx, err = conn.BeginTx(ctx, nil); err != nil { |
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
|
259 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
|
260 } |
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
|
261 defer tx.Rollback() |
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
|
262 |
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
|
263 var found bool |
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
|
264 err = tx.QueryRowContext(ctx, hasImportConfigurationSQL, id).Scan(&found) |
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
|
265 switch { |
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
|
266 case err == sql.ErrNoRows: |
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
|
267 err = JSONError{ |
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
|
268 Code: http.StatusNotFound, |
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
|
269 Message: fmt.Sprintf("No schedule %d found", id), |
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
|
270 } |
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
|
271 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
|
272 case err != nil: |
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
|
273 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
|
274 case !found: |
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
|
275 err = errors.New("Unexpected result") |
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
|
276 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
|
277 } |
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
|
278 |
1704
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
279 if _, err = tx.ExecContext(ctx, deleteImportConfiguationAttributesSQL, id); err != nil { |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
280 return |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
281 } |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
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 if _, err = tx.ExecContext(ctx, deleteImportConfiguationSQL, id); err != nil { |
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 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
|
285 } |
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
|
286 |
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
|
287 // Remove from running scheduler. |
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
|
288 scheduler.UnbindByID(id) |
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
|
289 |
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
|
290 if err = tx.Commit(); err != nil { |
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
|
291 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
|
292 } |
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
|
293 |
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
|
294 var result = struct { |
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
|
295 ID int64 `json:"id"` |
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
|
296 }{ |
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
|
297 ID: id, |
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
|
298 } |
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
|
299 |
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
|
300 jr = JSONResult{Result: &result} |
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
|
301 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
|
302 } |
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
|
303 |
1704
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
304 func storeConfigAttributes( |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
305 ctx context.Context, |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
306 tx *sql.Tx, |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
307 id int64, |
1708
49e047c2106e
Imports: Made imports re-runnable if they fail.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1704
diff
changeset
|
308 attrs common.Attributes, |
1704
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
309 ) error { |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
310 if len(attrs) == 0 { |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
311 return nil |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
312 } |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
313 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
|
314 if err != nil { |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
315 return err |
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 defer attrStmt.Close() |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
318 // Sort to make it deterministic |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
319 keys := make([]string, len(attrs)) |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
320 i := 0 |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
321 for key := range attrs { |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
322 keys[i] = key |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
323 i++ |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
324 } |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
325 sort.Strings(keys) |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
326 for _, key := range keys { |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
327 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
|
328 return err |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
329 } |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
330 } |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
331 return nil |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
332 } |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
333 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
334 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
|
335 input interface{}, |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
336 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
|
337 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
|
338 ) (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
|
339 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
340 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
|
341 |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
342 session, _ := auth.GetSession(req) |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
343 |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
344 var cron, url sql.NullString |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
345 |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
346 if importConfig.Cron != nil { |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
347 cron = sql.NullString{String: string(*importConfig.Cron), Valid: true} |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
348 } |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
349 if importConfig.URL != nil { |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
350 url = sql.NullString{String: *importConfig.URL, Valid: true} |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
351 } |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
352 |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
353 ctx := req.Context() |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
354 |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
355 var tx *sql.Tx |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
356 |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
357 if tx, err = conn.BeginTx(ctx, nil); err != nil { |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
358 return |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
359 } |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
360 defer tx.Rollback() |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
361 |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
362 var id int64 |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
363 if err = tx.QueryRowContext( |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
364 ctx, |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
365 insertImportConfigurationSQL, |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
366 session.User, |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
367 string(importConfig.Kind), |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
368 cron, |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
369 importConfig.SendEMail, |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
370 url, |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
371 ).Scan(&id); err != nil { |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
372 return |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
373 } |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
374 |
1702
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1654
diff
changeset
|
375 // Store extra attributes |
1704
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
376 if err = storeConfigAttributes(ctx, tx, id, importConfig.Attributes); err != nil { |
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
377 return |
1702
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1654
diff
changeset
|
378 } |
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1654
diff
changeset
|
379 |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
380 // Need to start a scheduler job right away? |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
381 if importConfig.Cron != nil { |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
382 if err = scheduler.BindAction( |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
383 string(importConfig.Kind), |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
384 string(*importConfig.Cron), |
1652
f39957ea08aa
Scheduled imports: The configuration id is not optional as it used to load the concrete configuration from the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
385 id, |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
386 ); err != nil { |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
387 return |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
388 } |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
389 } |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
390 |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
391 if err = tx.Commit(); err != nil { |
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
|
392 scheduler.UnbindByID(id) |
1735
eeb291c3f9b0
Configured imports: Allow sys_admin access to import_configuation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1733
diff
changeset
|
393 return |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
394 } |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
395 |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
396 var result = struct { |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
397 ID int64 `json:"id"` |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
398 }{ |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
399 ID: id, |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
400 } |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
401 |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
402 jr = JSONResult{ |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
403 Code: http.StatusCreated, |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
404 Result: &result, |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
405 } |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
406 return |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
407 } |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
408 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
409 func listImportConfigs( |
1582
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
410 _ interface{}, |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
411 req *http.Request, |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
412 conn *sql.Conn, |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
413 ) (jr JSONResult, err error) { |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
414 |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
415 ctx := req.Context() |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
416 var rows *sql.Rows |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
417 |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
418 if rows, err = conn.QueryContext(ctx, selectImportConfigurationSQL); err != nil { |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
419 return |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
420 } |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
421 defer rows.Close() |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
422 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
423 list := []*imports.IDConfig{} |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
424 |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
425 for rows.Next() { |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
426 var ( |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
427 entry imports.IDConfig |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
428 kind string |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
429 cron sql.NullString |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
430 url sql.NullString |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
431 ) |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
432 if err = rows.Scan( |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
433 &entry.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
|
434 &entry.User, |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
435 &kind, |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
436 &entry.SendEMail, |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
437 &cron, |
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
|
438 &url, |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
439 ); err != nil { |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
440 return |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
441 } |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
442 entry.Kind = imports.ImportKind(kind) |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
443 if cron.Valid { |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
444 cs := imports.CronSpec(cron.String) |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
445 entry.Cron = &cs |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
446 } |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
447 if url.Valid { |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
448 entry.URL = &url.String |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
449 } |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
450 list = append(list, &entry) |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
451 } |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
452 |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
453 if err = rows.Err(); err != nil { |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
454 return |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
455 } |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
456 |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
457 jr = JSONResult{Result: list} |
1582
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
458 return |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
459 } |