Mercurial > gemma
annotate pkg/controllers/importqueue.go @ 1194:7db850de0952
Added a signer who makes the final decison on an import.
Generate a log entry when the final decison is made.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 18 Nov 2018 18:29:25 +0100 |
parents | 58acc343b1b6 |
children | 486d66a9565c |
rev | line source |
---|---|
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package controllers |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
1189
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
17 "context" |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "database/sql" |
1031
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
19 "fmt" |
1189
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
20 "log" |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "net/http" |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "strconv" |
1189
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
23 "strings" |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 |
1194
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
25 "gemma.intevation.de/gemma/pkg/auth" |
1189
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
26 "gemma.intevation.de/gemma/pkg/imports" |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 "gemma.intevation.de/gemma/pkg/models" |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 "github.com/gorilla/mux" |
1189
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
29 "github.com/jackc/pgx/pgtype" |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 ) |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 const ( |
1189
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
33 selectImportsSQL = ` |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 SELECT |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 id, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 state::varchar, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 enqueued, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 kind, |
1194
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
39 username, |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
40 signer |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 FROM waterway.imports |
1189
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
42 ` |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
43 |
1031
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
44 selectHasImportSQL = ` |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
45 SELECT true FROM Waterway.imports WHERE id = $1` |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
46 |
1037
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
47 selectHasNoRunningImportSQL = ` |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
48 SELECT true FROM Waterway.imports |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
49 WHERE id = $1 AND state <> 'running'::waterway.import_state` |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
50 |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
51 selectImportLogsSQL = ` |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
52 SELECT |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
53 time, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
54 kind::varchar, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
55 msg |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
56 FROM waterway.import_logs |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
57 WHERE import_id = $1 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
58 ORDER BY time` |
1037
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
59 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
60 deleteLogsSQL = ` |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
61 DELETE FROM waterway.import_logs WHERE import_id = $1` |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
62 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
63 deleteImportSQL = ` |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
64 DELETE FROM waterway.imports WHERE id = $1` |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 ) |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 |
1189
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
67 func toTextArray(txt string, allowed []string) *pgtype.TextArray { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
68 parts := strings.Split(txt, ",") |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
69 var accepted []string |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
70 for _, part := range parts { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
71 if part = strings.ToLower(strings.TrimSpace(part)); len(part) == 0 { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
72 continue |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
73 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
74 for _, a := range allowed { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
75 if part == a { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
76 accepted = append(accepted, part) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
77 break |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
78 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
79 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
80 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
81 if len(accepted) == 0 { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
82 return nil |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
83 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
84 var ta pgtype.TextArray |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
85 if err := ta.Set(accepted); err != nil { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
86 log.Printf("warn: %v\n", err) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
87 return nil |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
88 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
89 return &ta |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
90 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
91 |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
92 func queryImportListStmt( |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
93 conn *sql.Conn, |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
94 ctx context.Context, |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
95 vars map[string]string, |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
96 ) (*sql.Rows, error) { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
97 |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
98 var ( |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
99 stmt strings.Builder |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
100 args []interface{} |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
101 states *pgtype.TextArray |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
102 kinds *pgtype.TextArray |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
103 ) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
104 |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
105 if st, found := vars["states"]; found { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
106 states = toTextArray(st, imports.ImportStateNames) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
107 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
108 |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
109 if ks, found := vars["kinds"]; found { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
110 kinds = toTextArray(ks, imports.ImportKindNames) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
111 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
112 |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
113 stmt.WriteString(selectImportsSQL) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
114 if states != nil || kinds != nil { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
115 stmt.WriteString(" WHERE ") |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
116 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
117 |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
118 if states != nil { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
119 fmt.Fprintf(&stmt, " states = ANY($%d) ", len(args)+1) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
120 args = append(args, states) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
121 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
122 |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
123 if states != nil && kinds != nil { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
124 stmt.WriteString("AND") |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
125 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
126 |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
127 if kinds != nil { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
128 fmt.Fprintf(&stmt, " kind = ANY($%d) ", len(args)+1) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
129 args = append(args, kinds) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
130 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
131 |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
132 stmt.WriteString(" ORDER BY enqueued DESC ") |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
133 |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
134 if lim, found := vars["limit"]; found { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
135 fmt.Fprintf(&stmt, " LIMIT $%d ", len(args)+1) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
136 limit, _ := strconv.ParseInt(lim, 10, 64) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
137 args = append(args, limit) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
138 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
139 |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
140 if ofs, found := vars["offset"]; found { |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
141 fmt.Fprintf(&stmt, " OFFSET $%d ", len(args)+1) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
142 offset, _ := strconv.ParseInt(ofs, 10, 64) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
143 args = append(args, offset) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
144 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
145 |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
146 return conn.QueryContext(ctx, stmt.String(), args...) |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
147 } |
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
148 |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 func listImports( |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 _ interface{}, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 req *http.Request, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 conn *sql.Conn, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 ) (jr JSONResult, err error) { |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 var rows *sql.Rows |
1189
3d50f558870c
REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1037
diff
changeset
|
156 rows, err = queryImportListStmt(conn, req.Context(), mux.Vars(req)) |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 if err != nil { |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 return |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 } |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 defer rows.Close() |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 imports := make([]*models.Import, 0, 20) |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 for rows.Next() { |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 var it models.Import |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 if err = rows.Scan( |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 &it.ID, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 &it.State, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 &it.Enqueued, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 &it.Kind, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 &it.User, |
1194
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
172 &it.Signer, |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 ); err != nil { |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 return |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 } |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 imports = append(imports, &it) |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 } |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 if err = rows.Err(); err != nil { |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 return |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 } |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 jr = JSONResult{ |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 Result: struct { |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 Imports []*models.Import `json:"imports"` |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 }{ |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 Imports: imports, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 }, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 } |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 return |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 } |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
192 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
193 func importLogs( |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
194 _ interface{}, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
195 req *http.Request, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
196 conn *sql.Conn, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
197 ) (jr JSONResult, err error) { |
1031
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
198 |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
199 ctx := req.Context() |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
200 |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
201 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
202 |
1031
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
203 // Check if he have such a import job first. |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
204 var dummy bool |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
205 err = conn.QueryRowContext(ctx, selectHasImportSQL, id).Scan(&dummy) |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
206 switch { |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
207 case err == sql.ErrNoRows: |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
208 err = JSONError{ |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
209 Code: http.StatusNotFound, |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
210 Message: fmt.Sprintf("Cannot find import #%d.", id), |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
211 } |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
212 return |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
213 case err != nil: |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
214 return |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
215 } |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
216 |
1031
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
217 // We have it -> generate log entries. |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
218 var rows *sql.Rows |
c0f5dedf5753
Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1026
diff
changeset
|
219 rows, err = conn.QueryContext(ctx, selectImportLogsSQL, id) |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
220 if err != nil { |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
221 return |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
222 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
223 defer rows.Close() |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
224 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
225 entries := make([]*models.ImportLogEntry, 0, 10) |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
226 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
227 for rows.Next() { |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
228 var entry models.ImportLogEntry |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
229 if err = rows.Scan(&entry.Time, &entry.Kind, &entry.Message); err != nil { |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
230 return |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
231 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
232 entries = append(entries, &entry) |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
233 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
234 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
235 if err = rows.Err(); err != nil { |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
236 return |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
237 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
238 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
239 jr = JSONResult{ |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
240 Result: struct { |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
241 Entries []*models.ImportLogEntry `json:"entries"` |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
242 }{ |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
243 Entries: entries, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
244 }, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
245 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
246 return |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
247 } |
1037
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
248 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
249 func deleteImport( |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
250 _ interface{}, |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
251 req *http.Request, |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
252 conn *sql.Conn, |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
253 ) (jr JSONResult, err error) { |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
254 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
255 ctx := req.Context() |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
256 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
257 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
258 var tx *sql.Tx |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
259 tx, err = conn.BeginTx(ctx, nil) |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
260 if err != nil { |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
261 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
262 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
263 defer tx.Rollback() |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
264 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
265 // Check if he have such a import job first. |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
266 var dummy bool |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
267 err = tx.QueryRowContext(ctx, selectHasNoRunningImportSQL, id).Scan(&dummy) |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
268 switch { |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
269 case err == sql.ErrNoRows: |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
270 err = JSONError{ |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
271 Code: http.StatusNotFound, |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
272 Message: fmt.Sprintf("Cannot find import #%d.", id), |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
273 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
274 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
275 case err != nil: |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
276 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
277 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
278 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
279 if _, err = tx.ExecContext(ctx, deleteLogsSQL, id); err != nil { |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
280 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
281 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
282 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
283 if _, err = tx.ExecContext(ctx, deleteImportSQL, id); err != nil { |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
284 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
285 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
286 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
287 if err = tx.Commit(); err != nil { |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
288 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
289 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
290 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
291 jr = JSONResult{Code: http.StatusNoContent} |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
292 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
293 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
294 } |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
295 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
296 const ( |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
297 isPendingSQL = ` |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
298 SELECT state = 'pending'::waterway.import_state, kind WHERE id = $1` |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
299 |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
300 reviewSQL = ` |
1194
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
301 UPDATE waterway.imports SET |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
302 state = $1::waterway.import_state, |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
303 signer = $2 |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
304 WHERE id = $3` |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
305 |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
306 deleteImportDataSQL = `SELECT waterway.del_import($1)` |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
307 |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
308 deleteImportTrackSQL = ` |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
309 DELETE FROM waterway.track_imports WHERE import_id = $1` |
1194
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
310 |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
311 logDecisionSQL = ` |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
312 INSERT INTO waterway.import_logs (import_id, msg) VALUES ($1, $2)` |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
313 ) |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
314 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
315 func reviewImport( |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
316 _ interface{}, |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
317 req *http.Request, |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
318 conn *sql.Conn, |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
319 ) (jr JSONResult, err error) { |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
320 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
321 vars := mux.Vars(req) |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
322 id, _ := strconv.ParseInt(vars["id"], 10, 64) |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
323 state := vars["state"] |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
324 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
325 ctx := req.Context() |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
326 var tx *sql.Tx |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
327 if tx, err = conn.BeginTx(ctx, nil); err != nil { |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
328 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
329 } |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
330 defer tx.Rollback() |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
331 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
332 var pending bool |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
333 var kind string |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
334 |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
335 err = tx.QueryRowContext(ctx, isPendingSQL, id).Scan(&pending, &kind) |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
336 switch { |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
337 case err == sql.ErrNoRows: |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
338 err = JSONError{ |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
339 Code: http.StatusNotFound, |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
340 Message: fmt.Sprintf("Cannot find import #%d.", id), |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
341 } |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
342 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
343 case err != nil: |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
344 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
345 case !pending: |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
346 err = JSONError{ |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
347 Code: http.StatusBadRequest, |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
348 Message: fmt.Sprintf("Import %d is not pending.", id), |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
349 } |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
350 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
351 } |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
352 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
353 if state == "accepted" { |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
354 if jc := imports.FindJobCreator(imports.JobKind(kind)); jc != nil { |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
355 if err = jc.StageDone(tx, ctx, id); err != nil { |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
356 return |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
357 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
358 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
359 |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
360 if _, err = tx.ExecContext(ctx, deleteImportTrackSQL, id); err != nil { |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
361 return |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
362 } |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
363 } else { |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
364 if _, err = tx.ExecContext(ctx, deleteImportDataSQL, id); err != nil { |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
365 return |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
366 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
367 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
368 |
1194
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
369 // Log the decision and set the final state. |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
370 session, _ := auth.GetSession(req) |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
371 who := session.User |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
372 |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
373 if _, err = tx.ExecContext(ctx, logDecisionSQL, id, |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
374 fmt.Sprintf("User '%s' %s import %d.", who, state, id)); err != nil { |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
375 return |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
376 } |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
377 |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
378 if _, err = tx.ExecContext(ctx, reviewSQL, state, who, id); err != nil { |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
379 return |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
380 } |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
381 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
382 if err = tx.Commit(); err != nil { |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
383 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
384 } |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
385 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
386 } |