Mercurial > gemma
comparison pkg/imports/ugm.go @ 2245:7d784840a9a7
Uploaded gauge measurements: Initial commit. TODO: Add endpoint.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 13 Feb 2019 16:12:38 +0100 |
parents | |
children | 2cba13653a58 |
comparison
equal
deleted
inserted
replaced
2244:52093f82a786 | 2245:7d784840a9a7 |
---|---|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 | |
2 // without warranty, see README.md and license for details. | |
3 // | |
4 // SPDX-License-Identifier: AGPL-3.0-or-later | |
5 // License-Filename: LICENSES/AGPL-3.0.txt | |
6 // | |
7 // Copyright (C) 2018 by via donau | |
8 // – Österreichische Wasserstraßen-Gesellschaft mbH | |
9 // Software engineering by Intevation GmbH | |
10 // | |
11 // Author(s): | |
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> | |
13 | |
14 package imports | |
15 | |
16 import ( | |
17 "context" | |
18 "database/sql" | |
19 "errors" | |
20 "os" | |
21 "path/filepath" | |
22 | |
23 "gemma.intevation.de/gemma/pkg/soap" | |
24 "gemma.intevation.de/gemma/pkg/soap/nts" | |
25 ) | |
26 | |
27 type UploadGaugeMeasurement struct { | |
28 Dir string `json:"dir"` | |
29 } | |
30 | |
31 const UGMJobKind JobKind = "ugm" | |
32 | |
33 type ugmJobCreator struct{} | |
34 | |
35 func init() { RegisterJobCreator(UGMJobKind, ugmJobCreator{}) } | |
36 | |
37 func (ugmJobCreator) Description() string { return "uploaded gauge measurements" } | |
38 | |
39 func (ugmJobCreator) Create() Job { return new(UploadGaugeMeasurement) } | |
40 | |
41 func (ugmJobCreator) Depends() []string { return gmJobCreator{}.Depends() } | |
42 | |
43 func (ugmJobCreator) AutoAccept() bool { return true } | |
44 | |
45 func (ugmJobCreator) StageDone(context.Context, *sql.Tx, int64) error { return nil } | |
46 | |
47 func (ugm *UploadGaugeMeasurement) CleanUp() error { return os.RemoveAll(ugm.Dir) } | |
48 | |
49 // Do executes the actual bottleneck import. | |
50 func (ugm *UploadGaugeMeasurement) Do( | |
51 ctx context.Context, | |
52 importID int64, | |
53 conn *sql.Conn, | |
54 feedback Feedback, | |
55 ) (interface{}, error) { | |
56 | |
57 fetch := func() ([]*nts.RIS_Message_Type, error) { | |
58 | |
59 var dst nts.Get_messages_result | |
60 | |
61 if err := soap.ValidateFile( | |
62 filepath.Join(ugm.Dir, "data.xml"), | |
63 "NtS_XSD_V.4.0.4.0.xsd", | |
64 &dst, | |
65 ); err != nil { | |
66 return nil, err | |
67 } | |
68 | |
69 result := dst.Result_message | |
70 if len(result) > 0 { | |
71 return nil, errors.New("No gauge measurements found") | |
72 } | |
73 | |
74 return result, nil | |
75 } | |
76 | |
77 return storeGaugeMeasurements( | |
78 ctx, | |
79 importID, | |
80 fetch, | |
81 conn, | |
82 feedback, | |
83 ) | |
84 } |