Mercurial > gemma
annotate pkg/controllers/importconfig.go @ 3019:4b9e83cf82ea
client: removed unnecessary css class
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Thu, 11 Apr 2019 17:47:04 +0200 |
parents | 0b203a3b3e8e |
children | c64c47ff2ab1 |
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" |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
18 "encoding/json" |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
19 "fmt" |
1582
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "net/http" |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
21 "strconv" |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
22 |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
23 "github.com/gorilla/mux" |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
24 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
25 "gemma.intevation.de/gemma/pkg/auth" |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
26 "gemma.intevation.de/gemma/pkg/common" |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
27 "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
|
28 "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
|
29 ) |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
30 |
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
|
31 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
|
32 _ 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
|
33 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
|
34 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
|
35 ) (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
|
36 |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
37 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
|
38 |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
39 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
|
40 |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
41 var jobID int64 |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
42 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
|
43 return |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
44 } |
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
|
45 |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
46 var result = struct { |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
47 ID int64 `json:"id"` |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
48 }{ |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
49 ID: jobID, |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
50 } |
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
|
51 |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
52 jr = JSONResult{ |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
53 Code: http.StatusCreated, |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
54 Result: &result, |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
55 } |
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 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
|
57 } |
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
|
58 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 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
|
63 ) (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
|
64 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
65 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
|
66 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
67 raw := input.(*json.RawMessage) |
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
|
68 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
69 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
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
|
70 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
71 var pc *imports.PersistentConfig |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
72 pc, err = imports.LoadPersistentConfigContext(ctx, conn, id) |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
73 switch { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
74 case err == sql.ErrNoRows: |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
75 err = JSONError{ |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
76 Code: http.StatusNotFound, |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
77 Message: fmt.Sprintf("No configuration %d found", id), |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
78 } |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
79 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
80 case err != nil: |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
81 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
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 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
84 kind := imports.JobKind(pc.Kind) |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
85 ctor := imports.ImportModelForJobKind(kind) |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
86 if ctor == nil { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
87 err = JSONError{ |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
88 Code: http.StatusInternalServerError, |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
89 Message: fmt.Sprintf("No constructor for kind '%s' found", pc.Kind), |
1704
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
90 } |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
91 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
92 } |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
93 config := ctor() |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
94 if err = json.Unmarshal(*raw, config); err != nil { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
95 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
96 } |
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
|
97 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
98 _, oldCron := pc.Attributes.Get("cron") |
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
|
99 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
100 session, _ := auth.GetSession(req) |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
101 pc.User = session.User |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
102 pc.Attributes = common.Attributes{} |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
103 pc.Attributes.Marshal(config) |
1704
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
104 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
105 cron, newCron := pc.Attributes.Get("cron") |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
106 |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
107 var tx *sql.Tx |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
108 if tx, err = conn.BeginTx(ctx, nil); err != nil { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
109 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
110 } |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
111 defer tx.Rollback() |
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
|
112 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
113 if err = pc.UpdateContext(ctx, tx); err != nil { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
114 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
115 } |
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
|
116 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
117 if oldCron { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
118 scheduler.UnbindByID(id) |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
119 } |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
120 |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
121 if newCron { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
122 if err = scheduler.BindAction( |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
123 string(pc.Kind), |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
124 cron, |
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
|
125 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
|
126 ); 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 } |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
129 } |
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
|
130 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
131 if err = tx.Commit(); err != nil { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
132 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
133 } |
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
|
134 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
135 var result = struct { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
136 ID int64 `json:"id"` |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
137 }{ |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
138 ID: id, |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
139 } |
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
|
140 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
141 jr = JSONResult{Result: &result} |
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
|
142 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
|
143 } |
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 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
145 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
|
146 _ 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
|
147 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
|
148 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
|
149 ) (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
|
150 |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
151 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
|
152 |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
153 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
|
154 |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
155 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
|
156 |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
157 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
|
158 switch { |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
159 case err != nil: |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
160 return |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
161 case cfg == nil: |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
162 err = JSONError{ |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
163 Code: http.StatusNotFound, |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
164 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
|
165 } |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
166 return |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
167 } |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
168 |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
169 kind := imports.JobKind(cfg.Kind) |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
170 |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
171 ctor := imports.ImportModelForJobKind(kind) |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
172 if ctor == nil { |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
173 err = JSONError{ |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
174 Code: http.StatusInternalServerError, |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
175 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
|
176 } |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
177 return |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
178 } |
2047
78002c5e838c
Imports: Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2046
diff
changeset
|
179 |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
180 what := ctor() |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
181 |
2047
78002c5e838c
Imports: Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2046
diff
changeset
|
182 if err = cfg.Attributes.Unmarshal(what); err != nil { |
78002c5e838c
Imports: Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2046
diff
changeset
|
183 return |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
184 } |
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
|
185 |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
186 jr = JSONResult{Result: &imports.ImportConfigOut{ |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
187 ID: id, |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
188 Kind: imports.ImportKind(cfg.Kind), |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
189 Config: what, |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
190 }} |
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
|
191 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
|
192 } |
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
|
193 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
194 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
|
195 _ 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
|
196 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
|
197 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
|
198 ) (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
|
199 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
200 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
|
201 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
202 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
|
203 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
204 var tx *sql.Tx |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
205 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
|
206 return |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
207 } |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
208 defer tx.Rollback() |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
209 |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
210 err = imports.DeletePersistentConfigurationContext( |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
211 ctx, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
212 tx, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
213 id, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
214 ) |
1704
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
215 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
216 switch { |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
217 case err == sql.ErrNoRows: |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
218 err = JSONError{ |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
219 Code: http.StatusNotFound, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
220 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
|
221 } |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
222 return |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
223 case err != nil: |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
224 return |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
225 } |
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
|
226 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
227 // Remove from running scheduler. |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
228 scheduler.UnbindByID(id) |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
229 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
230 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
|
231 return |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
232 } |
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
|
233 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
234 var result = struct { |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
235 ID int64 `json:"id"` |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
236 }{ |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
237 ID: id, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
238 } |
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
|
239 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
240 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
|
241 |
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 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
|
243 } |
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 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
245 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
|
246 input interface{}, |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
247 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
|
248 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
|
249 ) (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
|
250 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
251 cfg := input.(*imports.ImportConfigIn) |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
252 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
253 kind := imports.JobKind(cfg.Kind) |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
254 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
255 ctor := imports.ImportModelForJobKind(kind) |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
256 if ctor == nil { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
257 err = JSONError{ |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
258 Code: http.StatusBadRequest, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
259 Message: fmt.Sprintf("No kind %s found", string(cfg.Kind)), |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
260 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
261 return |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
262 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
263 config := ctor() |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
264 if err = json.Unmarshal(cfg.Config, config); err != nil { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
265 return |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
266 } |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
267 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
268 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
|
269 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
270 pc := imports.PersistentConfig{ |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
271 User: session.User, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
272 Kind: string(cfg.Kind), |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
273 Attributes: common.Attributes{}, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
274 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
275 pc.Attributes.Marshal(config) |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
276 |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
277 ctx := req.Context() |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
278 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
279 var tx *sql.Tx |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
280 if tx, err = conn.BeginTx(ctx, nil); err != nil { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
281 return |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
282 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
283 defer tx.Rollback() |
1702
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1654
diff
changeset
|
284 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
285 var id int64 |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
286 if id, err = pc.StoreContext(ctx, tx); err != nil { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
287 return |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
288 } |
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
|
289 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
290 // Need to start a scheduler job right away? |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
291 if cron, ok := pc.Attributes.Get("cron"); ok { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
292 if err = scheduler.BindAction(string(cfg.Kind), cron, id); 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
|
293 return |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
294 } |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
295 } |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
296 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
297 if err = tx.Commit(); err != nil { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
298 scheduler.UnbindByID(id) |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
299 return |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
300 } |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
301 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
302 var result = struct { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
303 ID int64 `json:"id"` |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
304 }{ |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
305 ID: id, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
306 } |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
307 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
308 jr = JSONResult{ |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
309 Code: http.StatusCreated, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
310 Result: &result, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
311 } |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
312 return |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
313 } |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
314 |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1592
diff
changeset
|
315 func listImportConfigs( |
1582
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
316 _ interface{}, |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
317 req *http.Request, |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
318 conn *sql.Conn, |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
319 ) (jr JSONResult, err error) { |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
320 |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
321 ctx := req.Context() |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
322 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
|
323 |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
324 if err = imports.ListAllPersistentConfigurationsContext( |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
325 ctx, conn, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
326 func(config *imports.ImportConfigOut) error { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
327 configs = append(configs, config) |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
328 return nil |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
329 }, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
330 ); err != nil { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
331 return |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
332 } |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
333 jr = JSONResult{Result: configs} |
1582
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
334 return |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
335 } |