# HG changeset patch # User Sascha L. Teichmann # Date 1549968852 -3600 # Node ID 3437ceee1529b086dde312a6efc975b29e604d38 # Parent 4d6979dedb1172c6def23d6dab83e4f14b499c2c Uploaded bottleneck import: Implemented in terms of normal bottleneck import. diff -r 4d6979dedb11 -r 3437ceee1529 pkg/imports/bn.go --- a/pkg/imports/bn.go Tue Feb 12 11:09:55 2019 +0100 +++ b/pkg/imports/bn.go Tue Feb 12 11:54:12 2019 +0100 @@ -143,23 +143,41 @@ conn *sql.Conn, feedback Feedback, ) (interface{}, error) { - client := ifbn.NewIBottleneckService(bn.URL, bn.Insecure, nil) + + fetch := func(feedback Feedback) ([]*ifbn.BottleNeckType, error) { + client := ifbn.NewIBottleneckService(bn.URL, bn.Insecure, nil) + + req := &ifbn.Export_bn_by_isrs{} - req := &ifbn.Export_bn_by_isrs{} + resp, err := client.Export_bn_by_isrs(req) + if err != nil { + return nil, err + } + + if resp.Export_bn_by_isrsResult == nil { + return nil, errors.New("no Bottlenecks found") + } - resp, err := client.Export_bn_by_isrs(req) + return resp.Export_bn_by_isrsResult.BottleNeckType, nil + } + + return storeBottlenecks(ctx, fetch, importID, conn, feedback) +} + +func storeBottlenecks( + ctx context.Context, + fetch func(Feedback) ([]*ifbn.BottleNeckType, error), + importID int64, + conn *sql.Conn, + feedback Feedback, +) (interface{}, error) { + start := time.Now() + + bns, err := fetch(feedback) if err != nil { - feedback.Error("%v", err) return nil, err } - if resp.Export_bn_by_isrsResult == nil { - err := errors.New("no Bottlenecks found") - feedback.Error("%v", err) - return nil, err - } - - bns := resp.Export_bn_by_isrsResult.BottleNeckType feedback.Info("Found %d bottlenecks for import", len(bns)) tx, err := conn.BeginTx(ctx, nil) @@ -187,8 +205,6 @@ var nids []string - start := time.Now() - nextBN: for _, bn := range bns { diff -r 4d6979dedb11 -r 3437ceee1529 pkg/imports/ubn.go --- a/pkg/imports/ubn.go Tue Feb 12 11:09:55 2019 +0100 +++ b/pkg/imports/ubn.go Tue Feb 12 11:54:12 2019 +0100 @@ -18,6 +18,10 @@ "database/sql" "errors" "os" + "path/filepath" + + "gemma.intevation.de/gemma/pkg/soap" + "gemma.intevation.de/gemma/pkg/soap/ifbn" ) type UploadedBottleneck struct { @@ -40,10 +44,8 @@ func (ubnJobCreator) Create() Job { return new(UploadedBottleneck) } func (ubnJobCreator) Depends() []string { - return []string{ - "gauges", - "bottlenecks", - } + // Same as normal bottleneck import. + return bnJobCreator{}.Depends() } // StageDone moves the imported bottleneck out of the staging area. @@ -52,8 +54,8 @@ tx *sql.Tx, id int64, ) error { - // TODO: Implement me! - return nil + // Same as normal bottleneck import. + return bnJobCreator{}.StageDone(ctx, tx, id) } // CleanUp of a uploaded bottleneck import removes the temp dir. @@ -68,6 +70,23 @@ conn *sql.Conn, feedback Feedback, ) (interface{}, error) { - // TODO: Implement me! - return nil, errors.New("Not implemented, yet!") + + fetch := func(feedback Feedback) ([]*ifbn.BottleNeckType, error) { + var dst ifbn.Export_bn_by_isrsResponse + if err := soap.ValidateFile( + filepath.Join(ubn.Dir, "data.xml"), + "IFBN.xsd", + &dst, + ); err != nil { + return nil, err + } + + if dst.Export_bn_by_isrsResult == nil { + return nil, errors.New("No bottlenecks found") + } + + return dst.Export_bn_by_isrsResult.BottleNeckType, nil + } + + return storeBottlenecks(ctx, fetch, importID, conn, feedback) }