comparison pkg/imports/ufa.go @ 2203:8d1a945d0c3b

Uploaded fairway availabilty import: Implemented in terms of normal fairway availabilty import.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 12 Feb 2019 23:24:09 +0100
parents
children 25f73251a6ac
comparison
equal deleted inserted replaced
2202:0aee7d4954ae 2203:8d1a945d0c3b
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/ifaf"
25 )
26
27 type UploadedFairwayAvailability struct {
28 Dir string
29 }
30
31 const UFAJobKind JobKind = "ufa"
32
33 type ufaJobCreator struct{}
34
35 func init() {
36 RegisterJobCreator(UFAJobKind, ufaJobCreator{})
37 }
38
39 func (ufaJobCreator) Description() string {
40 return "uploaded fairway availability"
41 }
42
43 func (ufaJobCreator) Create() Job { return new(UploadedFairwayAvailability) }
44
45 func (ufaJobCreator) Depends() []string {
46 // Same as faJobCreator
47 return faJobCreator{}.Depends()
48 }
49
50 func (ufaJobCreator) AutoAccept() bool { return true }
51
52 func (ufaJobCreator) StageDone(context.Context, *sql.Tx, int64) error {
53 return nil
54 }
55
56 func (ufa *UploadedFairwayAvailability) CleanUp() error {
57 return os.RemoveAll(ufa.Dir)
58 }
59
60 // Do executes the actual uploaded fairway availability import.
61 func (ufa *UploadedFairwayAvailability) Do(
62 ctx context.Context,
63 importID int64,
64 conn *sql.Conn,
65 feedback Feedback,
66 ) (interface{}, error) {
67
68 fetch := func(
69 ctx context.Context,
70 tx *sql.Tx,
71 bns bottlenecks,
72 ) ([]*ifaf.FairwayAvailability, error) {
73
74 var response ifaf.Get_bottleneck_faResponse
75
76 if err := soap.ValidateFile(
77 filepath.Join(ufa.Dir, "data.xml"),
78 "IFAF.xsd",
79 &response,
80 ); err != nil {
81 return nil, err
82 }
83
84 if response.Get_bottleneck_faResult == nil {
85 return nil, errors.New("No bottlenecks found")
86 }
87
88 result := response.Get_bottleneck_faResult
89 return result.FairwayAvailability, nil
90 }
91
92 return storeFairwayAvailability(ctx, conn, feedback, fetch)
93 }