comparison pkg/imports/ubn.go @ 2195:3437ceee1529

Uploaded bottleneck import: Implemented in terms of normal bottleneck import.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 12 Feb 2019 11:54:12 +0100
parents 4b9496752d89
children cfc523c70e90
comparison
equal deleted inserted replaced
2194:4d6979dedb11 2195:3437ceee1529
16 import ( 16 import (
17 "context" 17 "context"
18 "database/sql" 18 "database/sql"
19 "errors" 19 "errors"
20 "os" 20 "os"
21 "path/filepath"
22
23 "gemma.intevation.de/gemma/pkg/soap"
24 "gemma.intevation.de/gemma/pkg/soap/ifbn"
21 ) 25 )
22 26
23 type UploadedBottleneck struct { 27 type UploadedBottleneck struct {
24 Dir string `json:"dir"` 28 Dir string `json:"dir"`
25 } 29 }
38 func (ubnJobCreator) AutoAccept() bool { return false } 42 func (ubnJobCreator) AutoAccept() bool { return false }
39 43
40 func (ubnJobCreator) Create() Job { return new(UploadedBottleneck) } 44 func (ubnJobCreator) Create() Job { return new(UploadedBottleneck) }
41 45
42 func (ubnJobCreator) Depends() []string { 46 func (ubnJobCreator) Depends() []string {
43 return []string{ 47 // Same as normal bottleneck import.
44 "gauges", 48 return bnJobCreator{}.Depends()
45 "bottlenecks",
46 }
47 } 49 }
48 50
49 // StageDone moves the imported bottleneck out of the staging area. 51 // StageDone moves the imported bottleneck out of the staging area.
50 func (ubnJobCreator) StageDone( 52 func (ubnJobCreator) StageDone(
51 ctx context.Context, 53 ctx context.Context,
52 tx *sql.Tx, 54 tx *sql.Tx,
53 id int64, 55 id int64,
54 ) error { 56 ) error {
55 // TODO: Implement me! 57 // Same as normal bottleneck import.
56 return nil 58 return bnJobCreator{}.StageDone(ctx, tx, id)
57 } 59 }
58 60
59 // CleanUp of a uploaded bottleneck import removes the temp dir. 61 // CleanUp of a uploaded bottleneck import removes the temp dir.
60 func (ubn *UploadedBottleneck) CleanUp() error { 62 func (ubn *UploadedBottleneck) CleanUp() error {
61 return os.RemoveAll(ubn.Dir) 63 return os.RemoveAll(ubn.Dir)
66 ctx context.Context, 68 ctx context.Context,
67 importID int64, 69 importID int64,
68 conn *sql.Conn, 70 conn *sql.Conn,
69 feedback Feedback, 71 feedback Feedback,
70 ) (interface{}, error) { 72 ) (interface{}, error) {
71 // TODO: Implement me! 73
72 return nil, errors.New("Not implemented, yet!") 74 fetch := func(feedback Feedback) ([]*ifbn.BottleNeckType, error) {
75 var dst ifbn.Export_bn_by_isrsResponse
76 if err := soap.ValidateFile(
77 filepath.Join(ubn.Dir, "data.xml"),
78 "IFBN.xsd",
79 &dst,
80 ); err != nil {
81 return nil, err
82 }
83
84 if dst.Export_bn_by_isrsResult == nil {
85 return nil, errors.New("No bottlenecks found")
86 }
87
88 return dst.Export_bn_by_isrsResult.BottleNeckType, nil
89 }
90
91 return storeBottlenecks(ctx, fetch, importID, conn, feedback)
73 } 92 }