Mercurial > gemma
annotate pkg/controllers/bnimports.go @ 1639:3c9e33b4cea0
fix: make length check explicit
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Thu, 20 Dec 2018 12:50:20 +0100 |
parents | 165f31b71042 |
children | 49c04bb64e0a |
rev | line source |
---|---|
1534
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package controllers |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "database/sql" |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "log" |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "net/http" |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "gemma.intevation.de/gemma/pkg/auth" |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "gemma.intevation.de/gemma/pkg/common" |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "gemma.intevation.de/gemma/pkg/imports" |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 "gemma.intevation.de/gemma/pkg/models" |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 ) |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 func importBottleneck( |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 input interface{}, |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 req *http.Request, |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 conn *sql.Conn, |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 ) (jr JSONResult, err error) { |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 bi := input.(*models.BottleneckImport) |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 bn := &imports.Bottleneck{ |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 URL: bi.URL, |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 Insecure: bi.Insecure, |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 } |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 var serialized string |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 serialized, err = common.ToJSONString(bn) |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 if err != nil { |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 return |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 } |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 session, _ := auth.GetSession(req) |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 jobID, err := imports.AddJob(imports.BNJobKind, session.User, serialized) |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 if err != nil { |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 return |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 } |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 log.Printf("info: added import #%d to queue\n", jobID) |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 result := struct { |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 ID int64 `json:"id"` |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 }{ |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 ID: jobID, |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 } |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 jr = JSONResult{ |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 Code: http.StatusCreated, |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 Result: &result, |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 } |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 return |
165f31b71042
Bottleneck import: Added /api/imports/bottleneck POST endpoint.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 } |