annotate pkg/controllers/importqueue.go @ 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'.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 28 Nov 2018 09:52:34 +0100
parents 3ff916e853d4
children 5e1218b5a123
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 (
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 "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
18 "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
19 "fmt"
1189
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
20 "log"
1023
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 "net/http"
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 "strconv"
1189
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
23 "strings"
1023
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
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
25 "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
26 "github.com/jackc/pgx/pgtype"
0e1d89241cda Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1359
diff changeset
27
1194
7db850de0952 Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
28 "gemma.intevation.de/gemma/pkg/auth"
1189
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
29 "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
30 "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
31 )
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 const (
1189
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
34 selectImportsSQL = `
1023
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 SELECT
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 id,
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 state::varchar,
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 enqueued,
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 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
40 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
41 signer,
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
42 summary
1023
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 FROM waterway.imports
1189
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
44 `
1026
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
45
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
46 selectHasImportSQL = `
c0f5dedf5753 Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1026
diff changeset
47 SELECT true FROM Waterway.imports WHERE id = $1`
c0f5dedf5753 Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1026
diff changeset
48
1037
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
49 selectHasNoRunningImportSQL = `
1351
89d013d55ec9 Fixed SQL in accepting/declining imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1328
diff changeset
50 SELECT true FROM waterway.imports
1037
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
51 WHERE id = $1 AND state <> 'running'::waterway.import_state`
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
52
1026
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
53 selectImportLogsSQL = `
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
54 SELECT
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
55 time,
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
56 kind::varchar,
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
57 msg
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
58 FROM waterway.import_logs
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
59 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
60 ORDER BY time`
1037
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
61
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
62 deleteLogsSQL = `
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
63 DELETE FROM waterway.import_logs WHERE import_id = $1`
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
64
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
65 deleteImportSQL = `
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
66 DELETE FROM waterway.imports WHERE id = $1`
1023
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 )
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68
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
69 func toTextArray(txt string, allowed []string) *pgtype.TextArray {
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
70 parts := strings.Split(txt, ",")
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
71 var accepted []string
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
72 for _, part := range parts {
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
73 if part = strings.ToLower(strings.TrimSpace(part)); len(part) == 0 {
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
74 continue
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
75 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
76 for _, a := range allowed {
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
77 if part == a {
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
78 accepted = append(accepted, part)
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
79 break
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
80 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
81 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
82 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
83 if len(accepted) == 0 {
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
84 return nil
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
85 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
86 var ta pgtype.TextArray
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
87 if err := ta.Set(accepted); err != nil {
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
88 log.Printf("warn: %v\n", err)
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
89 return nil
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
90 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
91 return &ta
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
92 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
93
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 func queryImportListStmt(
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
95 conn *sql.Conn,
1315
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
96 req *http.Request,
1189
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
97 ) (*sql.Rows, error) {
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
98
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
99 var (
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
100 stmt strings.Builder
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
101 args []interface{}
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
102 states *pgtype.TextArray
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
103 kinds *pgtype.TextArray
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
104 )
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
105
1315
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
106 arg := func(format string, v interface{}) {
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
107 fmt.Fprintf(&stmt, format, len(args)+1)
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
108 args = append(args, v)
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
109 }
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
110
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
111 if st := req.FormValue("states"); st != "" {
1189
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
112 states = toTextArray(st, imports.ImportStateNames)
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
113 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
114
1315
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
115 if ks := req.FormValue("kinds"); ks != "" {
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
116 kinds = toTextArray(ks, imports.ImportKindNames)
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
117 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
118
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
119 stmt.WriteString(selectImportsSQL)
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
120 if states != nil || kinds != nil {
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
121 stmt.WriteString(" WHERE ")
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
122 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
123
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
124 if states != nil {
1315
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
125 arg(" 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
126 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
127
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
128 if states != nil && kinds != nil {
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
129 stmt.WriteString("AND")
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
130 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
131
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
132 if kinds != nil {
1315
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
133 arg(" kind = ANY($%d) ", kinds)
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
134 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
135
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
136 stmt.WriteString(" ORDER BY enqueued DESC ")
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
137
1315
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
138 if lim := req.FormValue("limit"); lim != "" {
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
139 limit, err := strconv.ParseInt(lim, 10, 64)
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
140 if err != nil {
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
141 return nil, err
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
142 }
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
143 arg(" LIMIT $%d ", limit)
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
144 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
145
1315
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
146 if ofs := req.FormValue("offset"); ofs != "" {
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
147 offset, err := strconv.ParseInt(ofs, 10, 64)
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
148 if err != nil {
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
149 return nil, err
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
150 }
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
151 arg(" OFFSET $%d ", offset)
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
152 }
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
153
1315
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
154 return conn.QueryContext(req.Context(), stmt.String(), args...)
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
155 }
3d50f558870c REST GET call to /imports now has the ability to be filtered by kinds or states.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1037
diff changeset
156
1023
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 func listImports(
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 _ interface{},
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 req *http.Request,
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 conn *sql.Conn,
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 ) (jr JSONResult, err error) {
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 var rows *sql.Rows
1315
24e4c60c2606 Simplified and fixed filtering of import queue listing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1195
diff changeset
164 rows, err = queryImportListStmt(conn, req)
1023
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 if err != nil {
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 return
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167 }
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 defer rows.Close()
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 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
171
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
172 var signer, summary 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
173
1023
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 for rows.Next() {
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 var it models.Import
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 if err = rows.Scan(
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 &it.ID,
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 &it.State,
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 &it.Enqueued,
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 &it.Kind,
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181 &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
182 &signer,
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
183 &summary,
1023
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 ); err != nil {
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 return
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 }
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
187 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
188 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
189 }
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
190 if summary.Valid {
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
191 if err = json.NewDecoder(
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
192 strings.NewReader(summary.String)).Decode(&it.Summary); err != nil {
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
193 return
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
194 }
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
195 }
1023
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 imports = append(imports, &it)
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 }
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
199 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
200 return
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
201 }
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
202
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
203 jr = JSONResult{
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
204 Result: struct {
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
205 Imports []*models.Import `json:"imports"`
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
206 }{
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
207 Imports: imports,
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
208 },
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
209 }
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
210 return
337a7f4c8a16 Add endpoint to list all or some import jobs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
211 }
1026
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
212
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
213 func importLogs(
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
214 _ interface{},
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
215 req *http.Request,
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
216 conn *sql.Conn,
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
217 ) (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
218
c0f5dedf5753 Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1026
diff changeset
219 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
220
1026
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
221 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
222
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
223 // Check if he have such a import job first.
c0f5dedf5753 Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1026
diff changeset
224 var dummy bool
c0f5dedf5753 Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1026
diff changeset
225 err = conn.QueryRowContext(ctx, selectHasImportSQL, id).Scan(&dummy)
c0f5dedf5753 Check first if we have a import before generating log import entries list.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1026
diff changeset
226 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
227 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
228 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
229 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
230 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
231 }
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
232 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
233 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
234 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
235 }
1026
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
236
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
237 // 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
238 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
239 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
240 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
241 return
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
242 }
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
243 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
244
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
245 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
246
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
247 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
248 var entry models.ImportLogEntry
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
249 if err = rows.Scan(&entry.Time, &entry.Kind, &entry.Message); err != nil {
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
250 return
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
251 }
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
252 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
253 }
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
254
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
255 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
256 return
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
257 }
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
258
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
259 jr = JSONResult{
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
260 Result: struct {
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
261 Entries []*models.ImportLogEntry `json:"entries"`
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
262 }{
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
263 Entries: entries,
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
264 },
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
265 }
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
266 return
3de54d7b7d30 Added endpoint to show the detail logs of an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1023
diff changeset
267 }
1037
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
268
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
269 func deleteImport(
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
270 _ interface{},
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
271 req *http.Request,
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
272 conn *sql.Conn,
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
273 ) (jr JSONResult, err error) {
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
274
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
275 ctx := req.Context()
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
276 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
277
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
278 var tx *sql.Tx
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
279 tx, err = conn.BeginTx(ctx, nil)
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
280 if err != nil {
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
281 return
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
282 }
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
283 defer tx.Rollback()
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
284
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
285 // 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
286 var dummy bool
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
287 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
288 switch {
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
289 case err == sql.ErrNoRows:
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
290 err = JSONError{
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
291 Code: http.StatusNotFound,
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
292 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
293 }
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
294 return
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
295 case err != nil:
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
296 return
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
297 }
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
298
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
299 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
300 return
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
301 }
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
302
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
303 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
304 return
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
305 }
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
306
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
307 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
308 return
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
309 }
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
310
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
311 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
312
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
313 return
a04126989d91 Added endpoint to delete job from import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1031
diff changeset
314 }
1192
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
315
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
316 const (
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
317 isPendingSQL = `
1351
89d013d55ec9 Fixed SQL in accepting/declining imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1328
diff changeset
318 SELECT state = 'pending'::waterway.import_state, kind
89d013d55ec9 Fixed SQL in accepting/declining imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1328
diff changeset
319 FROM waterway.imports
89d013d55ec9 Fixed SQL in accepting/declining imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1328
diff changeset
320 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
321
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1192
diff changeset
322 reviewSQL = `
1194
7db850de0952 Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
323 UPDATE waterway.imports SET
7db850de0952 Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
324 state = $1::waterway.import_state,
7db850de0952 Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
325 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
326 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
327
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1192
diff changeset
328 deleteImportDataSQL = `SELECT waterway.del_import($1)`
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1192
diff changeset
329
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1192
diff changeset
330 deleteImportTrackSQL = `
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1192
diff changeset
331 DELETE FROM waterway.track_imports WHERE import_id = $1`
1194
7db850de0952 Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
332
7db850de0952 Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
333 logDecisionSQL = `
7db850de0952 Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
334 INSERT INTO waterway.import_logs (import_id, msg) VALUES ($1, $2)`
1192
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
335 )
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
336
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
337 func reviewImport(
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
338 _ interface{},
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
339 req *http.Request,
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
340 conn *sql.Conn,
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
341 ) (jr JSONResult, err error) {
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
342
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
343 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
344 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
345 state := vars["state"]
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
346
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
347 ctx := req.Context()
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
348 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
349 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
350 return
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
351 }
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
352 defer tx.Rollback()
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
353
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
354 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
355 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
356
1193
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1192
diff changeset
357 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
358 switch {
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
359 case err == sql.ErrNoRows:
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
360 err = JSONError{
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
361 Code: http.StatusNotFound,
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
362 Message: fmt.Sprintf("Cannot find import #%d.", id),
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
363 }
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
364 return
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
365 case err != nil:
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
366 return
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
367 case !pending:
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
368 err = JSONError{
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
369 Code: http.StatusBadRequest,
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
370 Message: fmt.Sprintf("Import %d is not pending.", id),
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
371 }
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
372 return
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
373 }
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
374
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
375 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
376 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
377 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
378 return
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1192
diff changeset
379 }
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1192
diff changeset
380 }
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1192
diff changeset
381
1192
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
382 } else {
1193
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1192
diff changeset
383 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
384 return
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1192
diff changeset
385 }
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1192
diff changeset
386 }
58acc343b1b6 Implemented the db stuff of the review process. Needs testing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1192
diff changeset
387
1359
3ff916e853d4 Remove the import track in both cases accepted/declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1355
diff changeset
388 // 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
389 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
390 return
3ff916e853d4 Remove the import track in both cases accepted/declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1355
diff changeset
391 }
3ff916e853d4 Remove the import track in both cases accepted/declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1355
diff changeset
392
1194
7db850de0952 Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
393 // 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
394 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
395 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
396
7db850de0952 Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
397 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
398 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
399 return
7db850de0952 Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
400 }
7db850de0952 Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
401
7db850de0952 Added a signer who makes the final decison on an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1193
diff changeset
402 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
403 return
1192
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
404 }
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
405
1355
b0ebb77f4ab0 Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1351
diff changeset
406 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
407 return
b0ebb77f4ab0 Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1351
diff changeset
408 }
b0ebb77f4ab0 Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1351
diff changeset
409
b0ebb77f4ab0 Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1351
diff changeset
410 result := struct {
b0ebb77f4ab0 Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1351
diff changeset
411 Message string `json:"message"`
b0ebb77f4ab0 Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1351
diff changeset
412 }{
b0ebb77f4ab0 Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1351
diff changeset
413 Message: fmt.Sprintf("Import #%d successfully changed to state '%s'.",
b0ebb77f4ab0 Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1351
diff changeset
414 id, state),
b0ebb77f4ab0 Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1351
diff changeset
415 }
b0ebb77f4ab0 Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1351
diff changeset
416
b0ebb77f4ab0 Return nice JSON result if import was accepted or declined.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1351
diff changeset
417 jr = JSONResult{Result: &result}
1192
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
418 return
3afa71405b87 Added REST endpoint to accept or decline an import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1189
diff changeset
419 }