Mercurial > gemma
annotate pkg/controllers/importqueue.go @ 2665:fea12fc850d2 import-overview-rework
Simplified warnings filtering.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 14 Mar 2019 15:44:02 +0100 |
parents | 386ff766dfcd |
children | 5ece2c51d1f0 |
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 ( |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
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" |
1392
0e1d89241cda
Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1359
diff
changeset
|
19 "encoding/json" |
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
|
20 "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
|
21 "log" |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "net/http" |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "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
|
24 "strings" |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
25 "time" |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
1392
0e1d89241cda
Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1359
diff
changeset
|
27 "github.com/gorilla/mux" |
0e1d89241cda
Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1359
diff
changeset
|
28 "github.com/jackc/pgx/pgtype" |
0e1d89241cda
Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1359
diff
changeset
|
29 |
1194
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
30 "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
|
31 "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
|
32 "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
|
33 ) |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 const ( |
2627
3a242e6aa56d
Import log: Add filter for log entries with warnings only: GET /api/imports?warnings=true
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2179
diff
changeset
|
36 warningSQLPrefix = ` |
3a242e6aa56d
Import log: Add filter for log entries with warnings only: GET /api/imports?warnings=true
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2179
diff
changeset
|
37 ` |
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
|
38 selectImportsSQL = ` |
2627
3a242e6aa56d
Import log: Add filter for log entries with warnings only: GET /api/imports?warnings=true
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2179
diff
changeset
|
39 WITH warned AS ( |
3a242e6aa56d
Import log: Add filter for log entries with warnings only: GET /api/imports?warnings=true
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2179
diff
changeset
|
40 SELECT distinct(import_id) AS id |
3a242e6aa56d
Import log: Add filter for log entries with warnings only: GET /api/imports?warnings=true
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2179
diff
changeset
|
41 FROM import.import_logs |
3a242e6aa56d
Import log: Add filter for log entries with warnings only: GET /api/imports?warnings=true
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2179
diff
changeset
|
42 WHERE kind = 'warn'::log_type |
3a242e6aa56d
Import log: Add filter for log entries with warnings only: GET /api/imports?warnings=true
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2179
diff
changeset
|
43 ) |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 SELECT |
2627
3a242e6aa56d
Import log: Add filter for log entries with warnings only: GET /api/imports?warnings=true
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2179
diff
changeset
|
45 imports.id AS id, |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 state::varchar, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 enqueued, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 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
|
49 username, |
1392
0e1d89241cda
Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1359
diff
changeset
|
50 signer, |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
51 summary IS NOT NULL AS has_summary, |
2665
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
52 imports.id IN (SELECT id FROM warned) AS has_warnings |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
53 FROM import.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
|
54 ` |
2662
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
55 selectImportSummaySQL = ` |
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
56 SELECT summary FROM import.imports WHERE id = $1` |
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
|
57 |
1037
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
58 selectHasNoRunningImportSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
59 SELECT true FROM import.imports |
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
60 WHERE id = $1 AND state <> 'running'::import_state` |
1037
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
61 |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
62 selectImportLogsSQL = ` |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
63 SELECT |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
64 time, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
65 kind::varchar, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
66 msg |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
67 FROM import.import_logs |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
68 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
|
69 ORDER BY time` |
1037
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
70 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
71 deleteLogsSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
72 DELETE FROM import.import_logs WHERE import_id = $1` |
1037
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
73 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
74 deleteImportSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
75 DELETE FROM import.imports WHERE id = $1` |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
76 |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
77 selectBeforeSQL = ` |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
78 SELECT enqueued FROM import.imports |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
79 WHERE enqueued < $1 ORDER BY enqueued LIMIT 1` |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
80 |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
81 selectAfterSQL = ` |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
82 SELECT enqueued FROM import.imports |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
83 WHERE enqueued > $1 ORDER BY enqueued LIMIT 1` |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 ) |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 |
1655
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
86 func toInt8Array(txt string) *pgtype.Int8Array { |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
87 parts := strings.Split(txt, ",") |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
88 var ints []int64 |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
89 for _, part := range parts { |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
90 part = strings.TrimSpace(part) |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
91 v, err := strconv.ParseInt(part, 10, 64) |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
92 if err != nil { |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
93 continue |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
94 } |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
95 ints = append(ints, v) |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
96 } |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
97 var ia pgtype.Int8Array |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
98 if err := ia.Set(ints); err != nil { |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
99 log.Printf("warn: %v\n", err) |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
100 return nil |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
101 } |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
102 return &ia |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
103 } |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
104 |
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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
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 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
|
113 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
|
114 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
|
115 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
|
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 } |
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 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
|
120 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
|
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 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
|
123 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
|
124 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
|
125 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
|
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 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
|
128 } |
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 |
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 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
|
131 conn *sql.Conn, |
1315
24e4c60c2606
Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1195
diff
changeset
|
132 req *http.Request, |
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
|
133 ) (*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
|
134 |
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 var ( |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
136 stmt strings.Builder |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
137 args []interface{} |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
138 states *pgtype.TextArray |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
139 kinds *pgtype.TextArray |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
140 ids *pgtype.Int8Array |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
141 hasCond bool |
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
|
142 ) |
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 |
2665
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
144 arg := func(format string, v ...interface{}) { |
1315
24e4c60c2606
Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1195
diff
changeset
|
145 fmt.Fprintf(&stmt, format, len(args)+1) |
2665
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
146 args = append(args, v...) |
1315
24e4c60c2606
Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1195
diff
changeset
|
147 } |
24e4c60c2606
Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1195
diff
changeset
|
148 |
2665
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
149 cond := func(format string, v ...interface{}) { |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
150 if hasCond { |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
151 stmt.WriteString(" AND ") |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
152 } else { |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
153 hasCond = true |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
154 } |
2665
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
155 arg(format, v...) |
2627
3a242e6aa56d
Import log: Add filter for log entries with warnings only: GET /api/imports?warnings=true
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2179
diff
changeset
|
156 } |
3a242e6aa56d
Import log: Add filter for log entries with warnings only: GET /api/imports?warnings=true
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2179
diff
changeset
|
157 |
1315
24e4c60c2606
Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1195
diff
changeset
|
158 if st := req.FormValue("states"); st != "" { |
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
|
159 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
|
160 } |
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
|
161 |
1315
24e4c60c2606
Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1195
diff
changeset
|
162 if ks := req.FormValue("kinds"); ks != "" { |
1495
d26e3e1fcff1
The global import queue already knows which kinds of imports it supports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1473
diff
changeset
|
163 kinds = toTextArray(ks, imports.ImportKindNames()) |
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
|
164 } |
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
|
165 |
1655
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
166 if idss := req.FormValue("ids"); idss != "" { |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
167 ids = toInt8Array(idss) |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
168 } |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
169 |
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
|
170 stmt.WriteString(selectImportsSQL) |
2627
3a242e6aa56d
Import log: Add filter for log entries with warnings only: GET /api/imports?warnings=true
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2179
diff
changeset
|
171 |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
172 stmt.WriteString(" WHERE ") |
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
|
173 |
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
|
174 if states != nil { |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
175 cond(" state = ANY($%d) ", states) |
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
|
176 } |
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
|
177 |
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
|
178 if kinds != nil { |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
179 cond(" kind = ANY($%d) ", kinds) |
1655
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
180 } |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
181 |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
182 if ids != nil { |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
183 cond(" id = ANY($%d) ", ids) |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
184 } |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
185 |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
186 if from := req.FormValue("from"); from != "" { |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
187 fromTime, err := time.Parse(models.ImportTimeFormat, from) |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
188 if err != nil { |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
189 return nil, err |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
190 } |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
191 cond(" enqueued >= $%d ", fromTime) |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
192 } |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
193 |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
194 if to := req.FormValue("to"); to != "" { |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
195 toTime, err := time.Parse(models.ImportTimeFormat, to) |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
196 if err != nil { |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
197 return nil, err |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
198 } |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
199 cond(" enqueued <= $%d ", toTime) |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
200 } |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
201 |
2665
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
202 switch warn := strings.ToLower(req.FormValue("warnings")); warn { |
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
203 case "1", "t", "true": |
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
204 cond(" id IN (SELECT id FROM warned) ") |
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
205 } |
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
206 |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
207 if !hasCond { |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
208 stmt.WriteString(" TRUE ") |
1655
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
209 } |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
210 |
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
|
211 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
|
212 |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
213 return conn.QueryContext(req.Context(), stmt.String(), args...) |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
214 } |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
215 |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
216 func enqueued(ctx context.Context, conn *sql.Conn, what, query string) *models.ImportTime { |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
217 if what == "" { |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
218 return nil |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
219 } |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
220 |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
221 t, err := time.Parse(models.ImportTimeFormat, what) |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
222 if err != nil { |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
223 log.Printf("warn: %v\n", err) |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
224 return nil |
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
|
225 } |
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
|
226 |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
227 var when time.Time |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
228 err = conn.QueryRowContext(ctx, query, t).Scan(&when) |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
229 switch { |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
230 case err == sql.ErrNoRows: |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
231 return nil |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
232 case err != nil: |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
233 log.Printf("warn: %v\n", err) |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
234 return nil |
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
|
235 } |
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
|
236 |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
237 return &models.ImportTime{when} |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
238 } |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
239 func enqueuedBefore(conn *sql.Conn, req *http.Request) *models.ImportTime { |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
240 return enqueued(req.Context(), conn, req.FormValue("from"), selectBeforeSQL) |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
241 } |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
242 |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
243 func enqueuedAfter(conn *sql.Conn, req *http.Request) *models.ImportTime { |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
244 return enqueued(req.Context(), conn, req.FormValue("to"), selectAfterSQL) |
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
|
245 } |
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
|
246 |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 func listImports( |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 _ interface{}, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 req *http.Request, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 conn *sql.Conn, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 ) (jr JSONResult, err error) { |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 var rows *sql.Rows |
1315
24e4c60c2606
Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1195
diff
changeset
|
254 rows, err = queryImportListStmt(conn, req) |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 if err != nil { |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 return |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
257 } |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 defer rows.Close() |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 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
|
261 |
2662
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
262 var signer sql.NullString |
1195
486d66a9565c
Be aware that the signer is null till the final decision is made about an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1194
diff
changeset
|
263 |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
264 for rows.Next() { |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 var it models.Import |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 if err = rows.Scan( |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 &it.ID, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 &it.State, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 &it.Enqueued, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 &it.Kind, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 &it.User, |
1195
486d66a9565c
Be aware that the signer is null till the final decision is made about an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1194
diff
changeset
|
272 &signer, |
2662
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
273 &it.Summary, |
2179
20d9b71f4125
Import queue listing: Add another column 'warnings' (bool) to listing output which indicates if an import has warnings or not.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1995
diff
changeset
|
274 &it.Warnings, |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
275 ); err != nil { |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
276 return |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
277 } |
1195
486d66a9565c
Be aware that the signer is null till the final decision is made about an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1194
diff
changeset
|
278 if signer.Valid { |
486d66a9565c
Be aware that the signer is null till the final decision is made about an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1194
diff
changeset
|
279 it.Signer = signer.String |
486d66a9565c
Be aware that the signer is null till the final decision is made about an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1194
diff
changeset
|
280 } |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
281 imports = append(imports, &it) |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
282 } |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
283 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
284 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
|
285 return |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
286 } |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
287 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
288 jr = JSONResult{ |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
289 Result: struct { |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
290 Prev *models.ImportTime `json:"prev,omitempty"` |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
291 Next *models.ImportTime `json:"next,omitempty"` |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
292 Imports []*models.Import `json:"imports"` |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
293 }{ |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
294 Imports: imports, |
2663
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
295 Prev: enqueuedBefore(conn, req), |
386ff766dfcd
Replaced limit/offset filters with from/to as timestamps (format '2006-01-02T15:04:05.000').The output document also contains 'prev' and 'next' fields (if there is any matching data) from the times before and after 'from' and 'to'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2662
diff
changeset
|
296 Next: enqueuedAfter(conn, req), |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
297 }, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
298 } |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
299 return |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
300 } |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
301 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
302 func importLogs( |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
303 _ interface{}, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
304 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
|
305 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
|
306 ) (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
|
307 |
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
|
308 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
|
309 |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
310 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
|
311 |
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
|
312 // Check if he have such a import job first. |
2662
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
313 var summary sql.NullString |
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
314 err = conn.QueryRowContext(ctx, selectImportSummaySQL, id).Scan(&summary) |
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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 } |
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
|
321 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
|
322 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
|
323 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
|
324 } |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
325 |
2662
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
326 var sum interface{} |
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
327 if summary.Valid { |
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
328 if err = json.NewDecoder( |
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
329 strings.NewReader(summary.String)).Decode(&sum); err != nil { |
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
330 return |
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
331 } |
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
332 } |
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
333 |
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
|
334 // 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
|
335 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
|
336 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
|
337 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
|
338 return |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
339 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
340 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
|
341 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
342 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
|
343 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 return |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
348 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
349 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
|
350 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
351 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
352 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
|
353 return |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
354 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
355 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
356 jr = JSONResult{ |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
357 Result: struct { |
2662
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
358 Summary interface{} `json:"summary,omitempty"` |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
359 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
|
360 }{ |
2662
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
361 Summary: sum, |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
362 Entries: entries, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
363 }, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
364 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
365 return |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
366 } |
1037
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
367 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
368 func deleteImport( |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
369 _ interface{}, |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
370 req *http.Request, |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
371 conn *sql.Conn, |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
372 ) (jr JSONResult, err error) { |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
373 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
374 ctx := req.Context() |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
375 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
|
376 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
377 var tx *sql.Tx |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
378 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
|
379 if err != nil { |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
380 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
381 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
382 defer tx.Rollback() |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
383 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
384 // 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
|
385 var dummy bool |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
386 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
|
387 switch { |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
388 case err == sql.ErrNoRows: |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
389 err = JSONError{ |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
390 Code: http.StatusNotFound, |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
391 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
|
392 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
393 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
394 case err != nil: |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
395 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
396 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
397 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
398 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
|
399 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
400 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
401 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
402 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
|
403 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
404 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
405 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
406 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
|
407 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
408 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
409 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
410 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
|
411 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
412 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
413 } |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
414 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
415 const ( |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
416 isPendingSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
417 SELECT state = 'pending'::import_state, kind |
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
418 FROM import.imports |
1351
89d013d55ec9
Fixed SQL in accepting/declining imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1328
diff
changeset
|
419 WHERE id = $1` |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
420 |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
421 reviewSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
422 UPDATE import.imports SET |
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
423 state = $1::import_state, |
1194
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
424 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
|
425 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
|
426 |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
427 deleteImportDataSQL = `SELECT import.del_import($1)` |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
428 |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
429 deleteImportTrackSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
430 DELETE FROM import.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
|
431 |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
432 logDecisionSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
433 INSERT INTO import.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
|
434 ) |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
435 |
1468 | 436 func reviewImports( |
1469
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
437 reviews interface{}, |
1468 | 438 req *http.Request, |
439 conn *sql.Conn, | |
1469
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
440 ) (JSONResult, error) { |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
441 |
1473
d349618c6b50
Import bulk review: Fixed handling of input document.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1472
diff
changeset
|
442 rs := *reviews.(*[]models.Review) |
1469
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
443 |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
444 type reviewResult struct { |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
445 ID int64 `json:"id"` |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
446 Message string `json:"message,omitempty"` |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
447 Error string `json:"error,omitempty"` |
1468 | 448 } |
1469
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
449 |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
450 results := make([]reviewResult, len(rs)) |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
451 |
1472
702671b76eae
Import bulk review: Use an slice of models.Review as input.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1471
diff
changeset
|
452 for i := range rs { |
702671b76eae
Import bulk review: Use an slice of models.Review as input.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1471
diff
changeset
|
453 rev := &rs[i] |
1469
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
454 msg, err := decideImport(req, conn, rev.ID, string(rev.State)) |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
455 var errString string |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
456 if err != nil { |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
457 errString = err.Error() |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
458 } |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
459 results[i] = reviewResult{ |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
460 ID: rev.ID, |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
461 Message: msg, |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
462 Error: errString, |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
463 } |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
464 } |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
465 |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
466 return JSONResult{Result: results}, nil |
1468 | 467 } |
468 | |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
469 func reviewImport( |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
470 _ interface{}, |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
471 req *http.Request, |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
472 conn *sql.Conn, |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
473 ) (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
|
474 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
475 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
|
476 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
|
477 state := vars["state"] |
1469
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
478 |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
479 var msg string |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
480 if msg, err = decideImport(req, conn, id, state); err != nil { |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
481 return |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
482 } |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
483 |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
484 result := struct { |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
485 Message string `json:"message"` |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
486 }{ |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
487 Message: msg, |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
488 } |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
489 |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
490 jr = JSONResult{Result: &result} |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
491 return |
1468 | 492 } |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
493 |
1469
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
494 func decideImport( |
1468 | 495 req *http.Request, |
496 conn *sql.Conn, | |
497 id int64, | |
498 state string, | |
1469
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
499 ) (message string, err error) { |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
500 ctx := req.Context() |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
501 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
|
502 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
|
503 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
504 } |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
505 defer tx.Rollback() |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
506 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
507 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
|
508 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
|
509 |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
510 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
|
511 switch { |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
512 case err == sql.ErrNoRows: |
1693
cdc8933949f2
Controllers: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1655
diff
changeset
|
513 err = fmt.Errorf("cannot find import #%d", id) |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
514 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
515 case err != nil: |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
516 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
517 case !pending: |
1693
cdc8933949f2
Controllers: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1655
diff
changeset
|
518 err = fmt.Errorf("import %d is not pending", id) |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
519 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
520 } |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
521 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
522 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
|
523 if jc := imports.FindJobCreator(imports.JobKind(kind)); jc != nil { |
1328
d753ce6cf588
To make golint happier made context.Context to be the first argument in all calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1315
diff
changeset
|
524 if err = jc.StageDone(ctx, tx, 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
|
525 return |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
526 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
527 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
528 |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
529 } else { |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
530 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
|
531 return |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
532 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
533 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
534 |
1359
3ff916e853d4
Remove the import track in both cases accepted/declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1355
diff
changeset
|
535 // Remove the import track |
3ff916e853d4
Remove the import track in both cases accepted/declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1355
diff
changeset
|
536 if _, err = tx.ExecContext(ctx, deleteImportTrackSQL, id); err != nil { |
3ff916e853d4
Remove the import track in both cases accepted/declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1355
diff
changeset
|
537 return |
3ff916e853d4
Remove the import track in both cases accepted/declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1355
diff
changeset
|
538 } |
3ff916e853d4
Remove the import track in both cases accepted/declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1355
diff
changeset
|
539 |
1194
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
540 // 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
|
541 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
|
542 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
|
543 |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
544 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
|
545 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
|
546 return |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
547 } |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
548 |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
549 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
|
550 return |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
551 } |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
552 |
1355
b0ebb77f4ab0
Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1351
diff
changeset
|
553 if err = tx.Commit(); err != nil { |
b0ebb77f4ab0
Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1351
diff
changeset
|
554 return |
b0ebb77f4ab0
Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1351
diff
changeset
|
555 } |
b0ebb77f4ab0
Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1351
diff
changeset
|
556 |
1469
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
557 message = fmt.Sprintf( |
286a3306f6bf
Import bulk review: Cleaned up input JSON document handling. Added proper error handling.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1468
diff
changeset
|
558 "Import #%d successfully changed to state '%s'.", id, state) |
1355
b0ebb77f4ab0
Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1351
diff
changeset
|
559 |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
560 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
561 } |