Mercurial > gemma
annotate pkg/controllers/importqueue.go @ 4243:d776110b4db0 json-handler-middleware
Made the de-serialized input of the JSON handler accessible via the context of the request.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 22 Aug 2019 10:54:08 +0200 |
parents | 1458c9b0fdaa |
children | 4394daeea96a |
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 |
1194
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
29 "gemma.intevation.de/gemma/pkg/auth" |
4078
80bdcd137a1d
Parse timezones from time inputs and send timezones in results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3776
diff
changeset
|
30 "gemma.intevation.de/gemma/pkg/common" |
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 ( |
4187
65a5501dc13d
Enable faster access to import logs
Tom Gottfried <tom@intevation.de>
parents:
4148
diff
changeset
|
36 selectImportsCountSQL = ` |
2682
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
37 SELECT count(*) |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
38 FROM import.imports |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
39 WHERE |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
40 ` |
4187
65a5501dc13d
Enable faster access to import logs
Tom Gottfried <tom@intevation.de>
parents:
4148
diff
changeset
|
41 selectImportsSQL = ` |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 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
|
43 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
|
44 state::varchar, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 enqueued, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 summary IS NOT NULL AS has_summary, |
4187
65a5501dc13d
Enable faster access to import logs
Tom Gottfried <tom@intevation.de>
parents:
4148
diff
changeset
|
50 EXISTS(SELECT 1 FROM import.import_logs |
4196
948e312e87bc
Add flag and filter for imports having errors
Tom Gottfried <tom@intevation.de>
parents:
4195
diff
changeset
|
51 WHERE kind = 'error'::log_type and import_id = imports.id) AS has_errors, |
948e312e87bc
Add flag and filter for imports having errors
Tom Gottfried <tom@intevation.de>
parents:
4195
diff
changeset
|
52 EXISTS(SELECT 1 FROM import.import_logs |
4187
65a5501dc13d
Enable faster access to import logs
Tom Gottfried <tom@intevation.de>
parents:
4148
diff
changeset
|
53 WHERE kind = 'warn'::log_type and import_id = imports.id) AS has_warnings |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
54 FROM import.imports |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
55 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
|
56 ` |
4187
65a5501dc13d
Enable faster access to import logs
Tom Gottfried <tom@intevation.de>
parents:
4148
diff
changeset
|
57 selectEnqueuedSQL = ` |
2672
b997e1fd1d3d
Fixed warning SQL prefix for selection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2671
diff
changeset
|
58 SELECT enqueued FROM import.imports |
b997e1fd1d3d
Fixed warning SQL prefix for selection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2671
diff
changeset
|
59 WHERE |
b997e1fd1d3d
Fixed warning SQL prefix for selection.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2671
diff
changeset
|
60 ` |
2795
241e7f05a538
/api/imports/{id} result now also contains the 'enqueued' time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2772
diff
changeset
|
61 selectImportSummarySQL = ` |
241e7f05a538
/api/imports/{id} result now also contains the 'enqueued' time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2772
diff
changeset
|
62 SELECT summary, enqueued 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
|
63 |
1037
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
64 selectHasNoRunningImportSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
65 SELECT true FROM import.imports |
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
66 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
|
67 |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
68 selectImportLogsSQL = ` |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
69 SELECT |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
70 time, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
71 kind::varchar, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
72 msg |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
73 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
|
74 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
|
75 ORDER BY time` |
1037
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
76 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
77 deleteLogsSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
78 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
|
79 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
80 deleteImportSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
81 DELETE FROM import.imports WHERE id = $1` |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 ) |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
84 type filledStmt struct { |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
85 stmt strings.Builder |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
86 args []interface{} |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
87 } |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
88 |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
89 func buildFilters(req *http.Request) (*filledStmt, *filledStmt, *filledStmt, error) { |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
90 |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
91 var l, a, b filterAnd |
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
|
92 |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
93 var noBefore, noAfter 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
|
94 |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
95 cond := func(format string, args ...interface{}) { |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
96 term := &filterTerm{format: format, args: args} |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
97 l = append(l, term) |
4195
ad13c581de7c
Fixed building filters for listing import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4187
diff
changeset
|
98 a = append(a, term) |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
99 b = append(b, term) |
2677
fe93c48f76c9
Add /api/imports?query=TXT to search TXT in kind, username, signer or logs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2673
diff
changeset
|
100 } |
fe93c48f76c9
Add /api/imports?query=TXT to search TXT in kind, username, signer or logs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2673
diff
changeset
|
101 |
fe93c48f76c9
Add /api/imports?query=TXT to search TXT in kind, username, signer or logs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2673
diff
changeset
|
102 if query := req.FormValue("query"); query != "" { |
fe93c48f76c9
Add /api/imports?query=TXT to search TXT in kind, username, signer or logs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2673
diff
changeset
|
103 query = "%" + query + "%" |
fe93c48f76c9
Add /api/imports?query=TXT to search TXT in kind, username, signer or logs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2673
diff
changeset
|
104 cond(` (kind ILIKE $%d OR username ILIKE $%d OR signer ILIKE $%d OR `+ |
fe93c48f76c9
Add /api/imports?query=TXT to search TXT in kind, username, signer or logs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2673
diff
changeset
|
105 `id IN (SELECT import_id FROM import.import_logs WHERE msg ILIKE $%d)) `, |
fe93c48f76c9
Add /api/imports?query=TXT to search TXT in kind, username, signer or logs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2673
diff
changeset
|
106 query, query, query, query) |
fe93c48f76c9
Add /api/imports?query=TXT to search TXT in kind, username, signer or logs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2673
diff
changeset
|
107 } |
fe93c48f76c9
Add /api/imports?query=TXT to search TXT in kind, username, signer or logs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2673
diff
changeset
|
108 |
3776
6521c962a7b6
Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
109 if cc := req.FormValue("cc"); cc != "" { |
6521c962a7b6
Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
110 codes := sliceToTextArray(splitUpper(cc)) |
6521c962a7b6
Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
111 cond(" username IN "+ |
6521c962a7b6
Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
112 "(SELECT username FROM internal.user_profiles "+ |
6521c962a7b6
Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
113 "WHERE country = ANY($%d)) ", |
6521c962a7b6
Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
114 codes) |
6521c962a7b6
Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
115 } |
6521c962a7b6
Add 'cc' parameter to search imports for a comma separated list of country codes for the the importing person.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3217
diff
changeset
|
116 |
2667
5ece2c51d1f0
More filter simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2665
diff
changeset
|
117 if st := req.FormValue("states"); st != "" { |
5ece2c51d1f0
More filter simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2665
diff
changeset
|
118 states := toTextArray(st, imports.ImportStateNames) |
2677
fe93c48f76c9
Add /api/imports?query=TXT to search TXT in kind, username, signer or logs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2673
diff
changeset
|
119 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
|
120 } |
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 |
2667
5ece2c51d1f0
More filter simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2665
diff
changeset
|
122 if ks := req.FormValue("kinds"); ks != "" { |
5ece2c51d1f0
More filter simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2665
diff
changeset
|
123 kinds := toTextArray(ks, imports.ImportKindNames()) |
2677
fe93c48f76c9
Add /api/imports?query=TXT to search TXT in kind, username, signer or logs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2673
diff
changeset
|
124 cond(" kind = ANY($%d) ", kinds) |
1655
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
125 } |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
126 |
2667
5ece2c51d1f0
More filter simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2665
diff
changeset
|
127 if idss := req.FormValue("ids"); idss != "" { |
5ece2c51d1f0
More filter simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2665
diff
changeset
|
128 ids := toInt8Array(idss) |
2677
fe93c48f76c9
Add /api/imports?query=TXT to search TXT in kind, username, signer or logs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2673
diff
changeset
|
129 cond(" id = ANY($%d) ", ids) |
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
|
130 } |
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
|
131 |
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
|
132 if from := req.FormValue("from"); from != "" { |
4078
80bdcd137a1d
Parse timezones from time inputs and send timezones in results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3776
diff
changeset
|
133 fromTime, err := common.ParseTime(from) |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
134 if err != nil { |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
135 return nil, nil, nil, err |
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 } |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
137 l = append(l, buildFilterTerm("enqueued >= $%d", fromTime)) |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
138 b = append(b, buildFilterTerm("enqueued < $%d", fromTime)) |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
139 } else { |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
140 noBefore = true |
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
|
141 } |
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
|
142 |
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
|
143 if to := req.FormValue("to"); to != "" { |
4078
80bdcd137a1d
Parse timezones from time inputs and send timezones in results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3776
diff
changeset
|
144 toTime, err := common.ParseTime(to) |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
145 if err != nil { |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
146 return nil, nil, nil, err |
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
|
147 } |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
148 l = append(l, buildFilterTerm("enqueued <= $%d", toTime)) |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
149 a = append(a, buildFilterTerm("enqueued > $%d", toTime)) |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
150 } else { |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
151 noAfter = true |
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
|
152 } |
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 |
2665
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
154 switch warn := strings.ToLower(req.FormValue("warnings")); warn { |
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
155 case "1", "t", "true": |
4187
65a5501dc13d
Enable faster access to import logs
Tom Gottfried <tom@intevation.de>
parents:
4148
diff
changeset
|
156 cond(` EXISTS(SELECT 1 FROM import.import_logs |
65a5501dc13d
Enable faster access to import logs
Tom Gottfried <tom@intevation.de>
parents:
4148
diff
changeset
|
157 WHERE kind = 'warn'::log_type and import_id = imports.id)`) |
2665
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
158 } |
fea12fc850d2
Simplified warnings filtering.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2663
diff
changeset
|
159 |
4196
948e312e87bc
Add flag and filter for imports having errors
Tom Gottfried <tom@intevation.de>
parents:
4195
diff
changeset
|
160 switch errors := strings.ToLower(req.FormValue("errors")); errors { |
948e312e87bc
Add flag and filter for imports having errors
Tom Gottfried <tom@intevation.de>
parents:
4195
diff
changeset
|
161 case "1", "t", "true": |
948e312e87bc
Add flag and filter for imports having errors
Tom Gottfried <tom@intevation.de>
parents:
4195
diff
changeset
|
162 cond(` EXISTS(SELECT 1 FROM import.import_logs |
948e312e87bc
Add flag and filter for imports having errors
Tom Gottfried <tom@intevation.de>
parents:
4195
diff
changeset
|
163 WHERE kind = 'error'::log_type and import_id = imports.id)`) |
948e312e87bc
Add flag and filter for imports having errors
Tom Gottfried <tom@intevation.de>
parents:
4195
diff
changeset
|
164 } |
948e312e87bc
Add flag and filter for imports having errors
Tom Gottfried <tom@intevation.de>
parents:
4195
diff
changeset
|
165 |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
166 fl := &filledStmt{} |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
167 fa := &filledStmt{} |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
168 fb := &filledStmt{} |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
169 |
4187
65a5501dc13d
Enable faster access to import logs
Tom Gottfried <tom@intevation.de>
parents:
4148
diff
changeset
|
170 fa.stmt.WriteString(selectEnqueuedSQL) |
65a5501dc13d
Enable faster access to import logs
Tom Gottfried <tom@intevation.de>
parents:
4148
diff
changeset
|
171 fb.stmt.WriteString(selectEnqueuedSQL) |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
172 |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
173 var counting bool |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
174 |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
175 switch count := strings.ToLower(req.FormValue("count")); count { |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
176 case "1", "t", "true": |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
177 counting = true |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
178 fl.stmt.WriteString(selectImportsCountSQL) |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
179 default: |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
180 fl.stmt.WriteString(selectImportsSQL) |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
181 } |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
182 |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
183 if len(l) == 0 { |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
184 fl.stmt.WriteString(" TRUE ") |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
185 } else { |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
186 l.serialize(&fl.stmt, &fl.args) |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
187 } |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
188 |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
189 if len(b) == 0 { |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
190 fb.stmt.WriteString(" TRUE ") |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
191 } else { |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
192 b.serialize(&fb.stmt, &fb.args) |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
193 } |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
194 |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
195 if len(a) == 0 { |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
196 fa.stmt.WriteString(" TRUE ") |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
197 } else { |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
198 a.serialize(&fa.stmt, &fa.args) |
1655
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
199 } |
34315277f2d6
Added ids filter to importqueue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1495
diff
changeset
|
200 |
2682
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
201 if !counting { |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
202 fl.stmt.WriteString(" ORDER BY enqueued DESC ") |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
203 fa.stmt.WriteString(" ORDER BY enqueued LIMIT 1") |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
204 fb.stmt.WriteString(" ORDER BY enqueued DESC LIMIT 1") |
2682
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
205 } |
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
|
206 |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
207 if noBefore { |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
208 fb = nil |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
209 } |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
210 if noAfter { |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
211 fa = nil |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
212 } |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
213 |
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
214 return fl, fb, fa, 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
|
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 |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
217 func neighbored(ctx context.Context, conn *sql.Conn, fb *filledStmt) *models.ImportTime { |
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
|
218 |
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
|
219 var when time.Time |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
220 err := conn.QueryRowContext(ctx, fb.stmt.String(), fb.args...).Scan(&when) |
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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 } |
4084
350a24c92848
Deliver times from import queue in UTC.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
228 return &models.ImportTime{Time: when.UTC()} |
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
|
229 } |
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
|
230 |
4243
d776110b4db0
Made the de-serialized input of the JSON handler accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4242
diff
changeset
|
231 func listImports(req *http.Request) (jr JSONResult, err error) { |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 |
3194
eeff2cc4ff9d
controllers: re-factored the SQL filter to a tree like structure to be of more general use.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3190
diff
changeset
|
233 var list, before, after *filledStmt |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
234 |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
235 if list, before, after, err = buildFilters(req); err != nil { |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
236 return |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
237 } |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
238 |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
239 ctx := req.Context() |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
240 |
4242
1458c9b0fdaa
Made the sql.Conn in function accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4196
diff
changeset
|
241 conn := JSONConn(req) |
1458c9b0fdaa
Made the sql.Conn in function accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4196
diff
changeset
|
242 |
2682
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
243 // Fast path for counting |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
244 |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
245 switch count := strings.ToLower(req.FormValue("count")); count { |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
246 case "1", "t", "true": |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
247 var count int64 |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
248 err = conn.QueryRowContext(ctx, list.stmt.String(), list.args...).Scan(&count) |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
249 switch { |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
250 case err == sql.ErrNoRows: |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
251 count, err = 0, nil |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
252 case err != nil: |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
253 return |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
254 } |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
255 jr = JSONResult{Result: count} |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
256 return |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
257 } |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
258 |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
259 // Generate the list |
9a493d27bf3f
Added /api/imports?count=true to only count the results.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2681
diff
changeset
|
260 |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 var rows *sql.Rows |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
262 if rows, err = conn.QueryContext(ctx, list.stmt.String(), list.args...); err != nil { |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 return |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
264 } |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 defer rows.Close() |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 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
|
268 |
2662
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
269 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
|
270 |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 for rows.Next() { |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 var it models.Import |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
273 var enqueued time.Time |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
274 if err = rows.Scan( |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
275 &it.ID, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
276 &it.State, |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
277 &enqueued, |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
278 &it.Kind, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
279 &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
|
280 &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
|
281 &it.Summary, |
4196
948e312e87bc
Add flag and filter for imports having errors
Tom Gottfried <tom@intevation.de>
parents:
4195
diff
changeset
|
282 &it.Errors, |
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
|
283 &it.Warnings, |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
284 ); 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 } |
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
|
287 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
|
288 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
|
289 } |
4084
350a24c92848
Deliver times from import queue in UTC.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
290 it.Enqueued = models.ImportTime{Time: enqueued.UTC()} |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
291 imports = append(imports, &it) |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
292 } |
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 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
|
295 return |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
296 } |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
297 |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
298 var prev, next *models.ImportTime |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
299 |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
300 if before != nil { |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
301 prev = neighbored(ctx, conn, before) |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
302 } |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
303 |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
304 if after != nil { |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
305 next = neighbored(ctx, conn, after) |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
306 } |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
307 |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
308 jr = JSONResult{ |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
309 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
|
310 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
|
311 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
|
312 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
|
313 }{ |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
314 Imports: imports, |
2671
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
315 Prev: prev, |
8f3facf902dd
Filter prev/next, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2670
diff
changeset
|
316 Next: next, |
1023
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
317 }, |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
318 } |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
319 return |
337a7f4c8a16
Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
320 } |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
321 |
4243
d776110b4db0
Made the de-serialized input of the JSON handler accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4242
diff
changeset
|
322 func importLogs(req *http.Request) (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
|
323 |
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 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
|
325 |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
326 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
|
327 |
4242
1458c9b0fdaa
Made the sql.Conn in function accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4196
diff
changeset
|
328 conn := JSONConn(req) |
1458c9b0fdaa
Made the sql.Conn in function accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4196
diff
changeset
|
329 |
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
|
330 // 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
|
331 var summary sql.NullString |
2795
241e7f05a538
/api/imports/{id} result now also contains the 'enqueued' time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2772
diff
changeset
|
332 var enqueued time.Time |
241e7f05a538
/api/imports/{id} result now also contains the 'enqueued' time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2772
diff
changeset
|
333 err = conn.QueryRowContext(ctx, selectImportSummarySQL, id).Scan( |
241e7f05a538
/api/imports/{id} result now also contains the 'enqueued' time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2772
diff
changeset
|
334 &summary, |
241e7f05a538
/api/imports/{id} result now also contains the 'enqueued' time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2772
diff
changeset
|
335 &enqueued, |
241e7f05a538
/api/imports/{id} result now also contains the 'enqueued' time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2772
diff
changeset
|
336 ) |
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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 } |
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
|
343 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
|
344 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
|
345 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
|
346 } |
4084
350a24c92848
Deliver times from import queue in UTC.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
347 enqueued = enqueued.UTC() |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
348 |
2662
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
349 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
|
350 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
|
351 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
|
352 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
|
353 return |
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
354 } |
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
355 } |
f90557a8c960
Moved summary from /api/imports overview to /api/imports/{id} details.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2627
diff
changeset
|
356 |
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
|
357 // 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
|
358 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
|
359 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
|
360 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
|
361 return |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
362 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
363 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
|
364 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
365 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
|
366 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
367 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
|
368 var entry models.ImportLogEntry |
4084
350a24c92848
Deliver times from import queue in UTC.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
369 var t time.Time |
350a24c92848
Deliver times from import queue in UTC.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4078
diff
changeset
|
370 if err = rows.Scan(&t, &entry.Kind, &entry.Message); err != nil { |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
371 return |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
372 } |
4148
1b1218bbd414
Made 'go vet' happy with controllers again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
373 entry.Time = models.ImportTime{Time: t.UTC()} |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
374 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
|
375 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
376 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
377 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
|
378 return |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
379 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
380 |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
381 jr = JSONResult{ |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
382 Result: struct { |
2795
241e7f05a538
/api/imports/{id} result now also contains the 'enqueued' time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2772
diff
changeset
|
383 Enqueued models.ImportTime `json:"enqueued"` |
241e7f05a538
/api/imports/{id} result now also contains the 'enqueued' time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2772
diff
changeset
|
384 Summary interface{} `json:"summary,omitempty"` |
241e7f05a538
/api/imports/{id} result now also contains the 'enqueued' time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2772
diff
changeset
|
385 Entries []*models.ImportLogEntry `json:"entries"` |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
386 }{ |
3089
813309225e35
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2954
diff
changeset
|
387 Enqueued: models.ImportTime{Time: enqueued}, |
2795
241e7f05a538
/api/imports/{id} result now also contains the 'enqueued' time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2772
diff
changeset
|
388 Summary: sum, |
241e7f05a538
/api/imports/{id} result now also contains the 'enqueued' time.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2772
diff
changeset
|
389 Entries: entries, |
1026
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
390 }, |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
391 } |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
392 return |
3de54d7b7d30
Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1023
diff
changeset
|
393 } |
1037
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
394 |
4243
d776110b4db0
Made the de-serialized input of the JSON handler accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4242
diff
changeset
|
395 func deleteImport(req *http.Request) (jr JSONResult, err error) { |
1037
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 ctx := req.Context() |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
398 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
|
399 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
400 var tx *sql.Tx |
4242
1458c9b0fdaa
Made the sql.Conn in function accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4196
diff
changeset
|
401 tx, err = JSONConn(req).BeginTx(ctx, nil) |
1037
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
402 if 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 defer tx.Rollback() |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
406 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
407 // 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
|
408 var dummy bool |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
409 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
|
410 switch { |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
411 case err == sql.ErrNoRows: |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
412 err = JSONError{ |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
413 Code: http.StatusNotFound, |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
414 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
|
415 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
416 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
417 case err != nil: |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
418 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
419 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
420 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
421 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
|
422 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
423 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
424 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
425 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
|
426 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
427 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
428 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
429 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
|
430 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
431 } |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
432 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
433 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
|
434 |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
435 return |
a04126989d91
Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1031
diff
changeset
|
436 } |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
437 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
438 const ( |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
439 isPendingSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
440 SELECT state = 'pending'::import_state, kind |
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
441 FROM import.imports |
1351
89d013d55ec9
Fixed SQL in accepting/declining imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1328
diff
changeset
|
442 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
|
443 |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
444 reviewSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
445 UPDATE import.imports SET |
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
446 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
|
447 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
|
448 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
|
449 |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
450 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
|
451 |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
452 deleteImportTrackSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
453 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
|
454 |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
455 logDecisionSQL = ` |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1693
diff
changeset
|
456 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
|
457 ) |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
458 |
4243
d776110b4db0
Made the de-serialized input of the JSON handler accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4242
diff
changeset
|
459 func reviewImports(req *http.Request) (JSONResult, error) { |
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
|
460 |
4243
d776110b4db0
Made the de-serialized input of the JSON handler accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4242
diff
changeset
|
461 rs := *JSONInput(req).(*[]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
|
462 |
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 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
|
464 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
|
465 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
|
466 Error string `json:"error,omitempty"` |
1468 | 467 } |
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
|
468 |
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
|
469 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
|
470 |
4242
1458c9b0fdaa
Made the sql.Conn in function accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4196
diff
changeset
|
471 conn := JSONConn(req) |
1458c9b0fdaa
Made the sql.Conn in function accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4196
diff
changeset
|
472 |
1472
702671b76eae
Import bulk review: Use an slice of models.Review as input.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1471
diff
changeset
|
473 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
|
474 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
|
475 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
|
476 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
|
477 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
|
478 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
|
479 } |
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 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
|
481 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
|
482 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
|
483 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
|
484 } |
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 } |
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 return JSONResult{Result: results}, nil |
1468 | 488 } |
489 | |
4243
d776110b4db0
Made the de-serialized input of the JSON handler accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4242
diff
changeset
|
490 func reviewImport(req *http.Request) (jr JSONResult, err error) { |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
491 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
492 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
|
493 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
|
494 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
|
495 |
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
|
496 var msg string |
4242
1458c9b0fdaa
Made the sql.Conn in function accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4196
diff
changeset
|
497 if msg, err = decideImport(req, JSONConn(req), id, state); err != nil { |
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
|
498 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
|
499 } |
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
|
500 |
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
|
501 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
|
502 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
|
503 }{ |
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
|
504 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
|
505 } |
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
|
506 |
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
|
507 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
|
508 return |
1468 | 509 } |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
510 |
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
|
511 func decideImport( |
1468 | 512 req *http.Request, |
513 conn *sql.Conn, | |
514 id int64, | |
515 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
|
516 ) (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
|
517 ctx := req.Context() |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
518 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
|
519 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
|
520 return |
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 defer tx.Rollback() |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
523 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
524 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
|
525 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
|
526 |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
527 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
|
528 switch { |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
529 case err == sql.ErrNoRows: |
2954
972400e56e4a
Do not report client errors as server error
Tom Gottfried <tom@intevation.de>
parents:
2795
diff
changeset
|
530 err = JSONError{ |
972400e56e4a
Do not report client errors as server error
Tom Gottfried <tom@intevation.de>
parents:
2795
diff
changeset
|
531 Code: http.StatusNotFound, |
972400e56e4a
Do not report client errors as server error
Tom Gottfried <tom@intevation.de>
parents:
2795
diff
changeset
|
532 Message: fmt.Sprintf("cannot find import #%d", id), |
972400e56e4a
Do not report client errors as server error
Tom Gottfried <tom@intevation.de>
parents:
2795
diff
changeset
|
533 } |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
534 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
535 case err != nil: |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
536 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
537 case !pending: |
2954
972400e56e4a
Do not report client errors as server error
Tom Gottfried <tom@intevation.de>
parents:
2795
diff
changeset
|
538 err = JSONError{ |
972400e56e4a
Do not report client errors as server error
Tom Gottfried <tom@intevation.de>
parents:
2795
diff
changeset
|
539 Code: http.StatusConflict, |
972400e56e4a
Do not report client errors as server error
Tom Gottfried <tom@intevation.de>
parents:
2795
diff
changeset
|
540 Message: fmt.Sprintf("import #%d is not pending", id), |
972400e56e4a
Do not report client errors as server error
Tom Gottfried <tom@intevation.de>
parents:
2795
diff
changeset
|
541 } |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
542 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
543 } |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
544 |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
545 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
|
546 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
|
547 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
|
548 return |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
549 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
550 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
551 |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
552 } else { |
1193
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
553 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
|
554 return |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
555 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
556 } |
58acc343b1b6
Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1192
diff
changeset
|
557 |
1359
3ff916e853d4
Remove the import track in both cases accepted/declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1355
diff
changeset
|
558 // 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
|
559 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
|
560 return |
3ff916e853d4
Remove the import track in both cases accepted/declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1355
diff
changeset
|
561 } |
3ff916e853d4
Remove the import track in both cases accepted/declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1355
diff
changeset
|
562 |
1194
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
563 // 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
|
564 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
|
565 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
|
566 |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
567 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
|
568 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
|
569 return |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
570 } |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
571 |
7db850de0952
Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1193
diff
changeset
|
572 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
|
573 return |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
574 } |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
575 |
1355
b0ebb77f4ab0
Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1351
diff
changeset
|
576 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
|
577 return |
b0ebb77f4ab0
Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1351
diff
changeset
|
578 } |
b0ebb77f4ab0
Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1351
diff
changeset
|
579 |
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
|
580 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
|
581 "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
|
582 |
1192
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
583 return |
3afa71405b87
Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1189
diff
changeset
|
584 } |