Mercurial > gemma
annotate pkg/imports/wfsjob.go @ 5612:a9bcaac49a7e erdms2
Beware of nil interfaces.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 07 Nov 2022 21:03:32 +0100 |
parents | 1222b777f51f |
children | 2dd155cc95ec |
rev | line source |
---|---|
4948
821ae20b6a20
Re-added missing header lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4946
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
821ae20b6a20
Re-added missing header lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4946
diff
changeset
|
2 // without warranty, see README.md and license for details. |
821ae20b6a20
Re-added missing header lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4946
diff
changeset
|
3 // |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2020 by via donau |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Tom Gottfried <tom.gottfried@intevation.de> |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 package imports |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import ( |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "context" |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "database/sql" |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "encoding/json" |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "errors" |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "fmt" |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "io" |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 "time" |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 "gemma.intevation.de/gemma/pkg/models" |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 "gemma.intevation.de/gemma/pkg/wfs" |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 ) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 var ( |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
31 // ErrFeatureIgnored indicates if a feature is ignored. |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
32 ErrFeatureIgnored = errors.New("feature ignored") |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
33 // ErrFeatureDuplicated indicates if a feature is a duplicate. |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
34 ErrFeatureDuplicated = errors.New("feature duplicated") |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
35 // ErrFeaturesUnmodified indicates if a feature is unmodified. |
4961
67d78b74fe43
Be more careful with unchanged errors if features were removed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4960
diff
changeset
|
36 ErrFeaturesUnmodified = errors.New("features unmodified") |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 ) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 type ( |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
40 // WFSFeatureConsumer is an interface to model a transactional |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
41 // handling to create new features. |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
42 WFSFeatureConsumer interface { |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 Commit() error |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 Rollback() error |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
5007
799e8248de8d
First step to move geometry creation for WFS features to loader.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4991
diff
changeset
|
46 NewFeature() (kind string, properties interface{}) |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
47 |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
48 Consume(geom, properties interface{}, epsg int) error |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
51 // WFSFeatureJobCreator is a factory to create feature consumers. |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
52 WFSFeatureJobCreator struct { |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 description string |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 depends [2][]string |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
56 newConsumer func(context.Context, *sql.Conn, Feedback) (WFSFeatureConsumer, error) |
4980
21d2acc080c9
Add the ability to be staged to the WFS feature downloader. This will be needed for FD downloads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4979
diff
changeset
|
57 |
5034
59a99655f34d
Added feedback support for StageDone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5012
diff
changeset
|
58 stageDone func(context.Context, *sql.Tx, int64, Feedback) error |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
61 // WFSFeatureJob is job to do an WFS import. |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
62 WFSFeatureJob struct { |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 models.WFSImport |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
64 creator *WFSFeatureJobCreator |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 ) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
5010
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
68 var ( |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
69 kindToGeometry = map[string]func() interface{}{ |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
70 // TODO: extend me! |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
71 "Point": func() interface{} { return new(pointSlice) }, |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
72 "LineString": func() interface{} { return new(lineSlice) }, |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
73 "MultiLineString": func() interface{} { return new(multiLineSlice) }, |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
74 } |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
75 |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
76 wrapGeomKind = map[[2]string]func(interface{}) interface{}{ |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
77 // TODO: extend me! |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
78 {"LineString", "MultiLineString"}: func(x interface{}) interface{} { |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
79 return &multiLineSlice{*x.(*lineSlice)} |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
80 }, |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
81 } |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
82 ) |
5007
799e8248de8d
First step to move geometry creation for WFS features to loader.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4991
diff
changeset
|
83 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
84 // Description gives a short description of this creator. |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
85 func (wfjc *WFSFeatureJobCreator) Description() string { |
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
86 return wfjc.description |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
89 // Depends lists the dependencies of this creator. |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
90 func (wfjc *WFSFeatureJobCreator) Depends() [2][]string { |
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
91 return wfjc.depends |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
94 // AutoAccept auto accepts this job if there |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
95 // is no stageDone implementation. |
4980
21d2acc080c9
Add the ability to be staged to the WFS feature downloader. This will be needed for FD downloads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4979
diff
changeset
|
96 func (wfjc *WFSFeatureJobCreator) AutoAccept() bool { |
21d2acc080c9
Add the ability to be staged to the WFS feature downloader. This will be needed for FD downloads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4979
diff
changeset
|
97 return wfjc.stageDone == nil |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
100 // StageDone forwards the StageDone call. |
5034
59a99655f34d
Added feedback support for StageDone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5012
diff
changeset
|
101 func (wfjc *WFSFeatureJobCreator) StageDone( |
59a99655f34d
Added feedback support for StageDone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5012
diff
changeset
|
102 ctx context.Context, |
59a99655f34d
Added feedback support for StageDone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5012
diff
changeset
|
103 tx *sql.Tx, |
59a99655f34d
Added feedback support for StageDone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5012
diff
changeset
|
104 id int64, |
59a99655f34d
Added feedback support for StageDone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5012
diff
changeset
|
105 feedback Feedback, |
59a99655f34d
Added feedback support for StageDone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5012
diff
changeset
|
106 ) error { |
4980
21d2acc080c9
Add the ability to be staged to the WFS feature downloader. This will be needed for FD downloads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4979
diff
changeset
|
107 if wfjc.stageDone == nil { |
21d2acc080c9
Add the ability to be staged to the WFS feature downloader. This will be needed for FD downloads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4979
diff
changeset
|
108 return nil |
21d2acc080c9
Add the ability to be staged to the WFS feature downloader. This will be needed for FD downloads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4979
diff
changeset
|
109 } |
5034
59a99655f34d
Added feedback support for StageDone.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5012
diff
changeset
|
110 return wfjc.stageDone(ctx, tx, id, feedback) |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
113 // Create creates the WFS job. |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
114 func (wfjc *WFSFeatureJobCreator) Create() Job { |
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
115 return &WFSFeatureJob{creator: wfjc} |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 // Description gives a short info about relevant facts of this import. |
5565
ade07a3f2cfd
Forget to change signature of some imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5143
diff
changeset
|
119 func (wfj *WFSFeatureJob) Description([]string) (string, error) { |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
120 return wfj.URL + "|" + wfj.FeatureType, nil |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 // CleanUp for WFS imports is a NOP. |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
124 func (*WFSFeatureJob) CleanUp() error { |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 return nil |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
128 // Do implements the actual WFS import. |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
129 func (wfj *WFSFeatureJob) Do( |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 ctx context.Context, |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 importID int64, |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 conn *sql.Conn, |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 feedback Feedback, |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 ) (interface{}, error) { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 start := time.Now() |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
138 feedback.Info("Import %s", wfj.creator.Description()) |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
140 feedback.Info("Loading capabilities from %s", wfj.URL) |
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
141 caps, err := wfs.GetCapabilities(wfj.URL) |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 if err != nil { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 feedback.Error("Loading capabilities failed: %v", err) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 return nil, err |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
147 ft := caps.FindFeatureType(wfj.FeatureType) |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 if ft == nil { |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
149 return nil, fmt.Errorf("unknown feature type '%s'", wfj.FeatureType) |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
152 feedback.Info("Found feature type '%s'", wfj.FeatureType) |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 epsg, err := wfs.CRSToEPSG(ft.DefaultCRS) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 if err != nil { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 feedback.Error("Unsupported CRS: '%s'", ft.DefaultCRS) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 return nil, err |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
160 if nilString(wfj.SortBy) != "" { |
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
161 feedback.Info("Features will be sorted by '%s'", *wfj.SortBy) |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
164 dl, err := wfs.GetFeatures(caps, wfj.FeatureType, nilString(wfj.SortBy)) |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 if err != nil { |
4991
6a48e5c6fe2f
Re-added a import feedback line which was deleted accidently in previous commit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4990
diff
changeset
|
166 feedback.Error("Cannot create GetFeature URLs. %v", err) |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 return nil, err |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 var ( |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 unsupported = stringCounter{} |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 missingProperties int |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 badProperties int |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 dupes int |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 features int |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 ) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
178 consumer, err := wfj.creator.newConsumer(ctx, conn, feedback) |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 if err != nil { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 return nil, err |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 defer consumer.Rollback() |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
184 if err := dl.Download(nilString(wfj.User), nilString(wfj.Password), func(url string, r io.Reader) error { |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 feedback.Info("Get features from: '%s'", url) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 rfc, err := wfs.ParseRawFeatureCollection(r) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 if err != nil { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 return fmt.Errorf("parsing GetFeature document failed: %v", err) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 if rfc.CRS != nil { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 crsName := rfc.CRS.Properties.Name |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 if epsg, err = wfs.CRSToEPSG(crsName); err != nil { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 feedback.Error("Unsupported CRS: %d", crsName) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 return err |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 // No features -> ignore. |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 if rfc.Features == nil { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 return nil |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 feedback.Info("Using EPSG: %d", epsg) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 |
4954
331a59ebaf54
Fix fairway marks import log
Tom Gottfried <tom@intevation.de>
parents:
4953
diff
changeset
|
205 feedback.Info( |
331a59ebaf54
Fix fairway marks import log
Tom Gottfried <tom@intevation.de>
parents:
4953
diff
changeset
|
206 "Found %d features in data source", len(rfc.Features)) |
331a59ebaf54
Fix fairway marks import log
Tom Gottfried <tom@intevation.de>
parents:
4953
diff
changeset
|
207 |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 for _, feature := range rfc.Features { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 if feature.Properties == nil || feature.Geometry.Coordinates == nil { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 missingProperties++ |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 continue |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 |
5007
799e8248de8d
First step to move geometry creation for WFS features to loader.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4991
diff
changeset
|
214 kind, props := consumer.NewFeature() |
799e8248de8d
First step to move geometry creation for WFS features to loader.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4991
diff
changeset
|
215 |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 if err := json.Unmarshal(*feature.Properties, props); err != nil { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 badProperties++ |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 continue |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 |
5011
2d7af72bb7ac
Fix geometry type wrapping
Tom Gottfried <tom@intevation.de>
parents:
5010
diff
changeset
|
221 // Look if we can deserialize given type |
2d7af72bb7ac
Fix geometry type wrapping
Tom Gottfried <tom@intevation.de>
parents:
5010
diff
changeset
|
222 makeGeom := kindToGeometry[feature.Geometry.Type] |
5010
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
223 if makeGeom == nil { |
5011
2d7af72bb7ac
Fix geometry type wrapping
Tom Gottfried <tom@intevation.de>
parents:
5010
diff
changeset
|
224 unsupported[feature.Geometry.Type]++ |
2d7af72bb7ac
Fix geometry type wrapping
Tom Gottfried <tom@intevation.de>
parents:
5010
diff
changeset
|
225 continue |
2d7af72bb7ac
Fix geometry type wrapping
Tom Gottfried <tom@intevation.de>
parents:
5010
diff
changeset
|
226 } |
2d7af72bb7ac
Fix geometry type wrapping
Tom Gottfried <tom@intevation.de>
parents:
5010
diff
changeset
|
227 |
5012
ae3a1392f9d0
Cosmetics: Tightened code a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5011
diff
changeset
|
228 // Optional wrapping |
ae3a1392f9d0
Cosmetics: Tightened code a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5011
diff
changeset
|
229 wrap := func(x interface{}) interface{} { return x } |
5011
2d7af72bb7ac
Fix geometry type wrapping
Tom Gottfried <tom@intevation.de>
parents:
5010
diff
changeset
|
230 if feature.Geometry.Type != kind { |
5010
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
231 // Look if we can wrap it |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
232 if wrap = wrapGeomKind[[2]string{feature.Geometry.Type, kind}]; wrap == nil { |
5011
2d7af72bb7ac
Fix geometry type wrapping
Tom Gottfried <tom@intevation.de>
parents:
5010
diff
changeset
|
233 unsupported[feature.Geometry.Type]++ |
5010
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
234 continue |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
235 } |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
236 } |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 |
5010
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
238 geom := makeGeom() |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
239 if err := json.Unmarshal(*feature.Geometry.Coordinates, geom); err != nil { |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
240 return err |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
241 } |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
242 |
5012
ae3a1392f9d0
Cosmetics: Tightened code a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5011
diff
changeset
|
243 switch err := consumer.Consume(wrap(geom), props, epsg); { |
5010
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
244 case err == ErrFeatureDuplicated: |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
245 dupes++ |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
246 case err == ErrFeatureIgnored: |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
247 // be silent |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
248 case err != nil: |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
249 return err |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
250 default: |
1d1be6bd5304
Wrap geometries if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5007
diff
changeset
|
251 features++ |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 return nil |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 }); err != nil { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 return nil, err |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
257 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 if dupes > 0 { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 feedback.Info( |
4960
fb48bc6415c0
Restore accidentally changed import log
Tom Gottfried <tom@intevation.de>
parents:
4958
diff
changeset
|
261 "Features outside responsibility area, duplicates or unchanged: %d", |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 dupes) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
264 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 if badProperties > 0 { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 feedback.Warn("Bad properties: %d", badProperties) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 if missingProperties > 0 { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 feedback.Warn("Missing properties: %d", missingProperties) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 if len(unsupported) != 0 { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
274 feedback.Warn("Unsupported types found: %s", unsupported) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
275 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
276 |
4961
67d78b74fe43
Be more careful with unchanged errors if features were removed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4960
diff
changeset
|
277 if err = consumer.Commit(); err == nil || err == ErrFeaturesUnmodified { |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
278 feedback.Info("Storing %d features took %s", |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
279 features, time.Since(start)) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
280 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
281 |
4958
6d5d6b27c3c3
Added pre commit hooks before commiting fairway marks to invalidate old.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4956
diff
changeset
|
282 // Commit before eventually returning UnchangedError because we might |
6d5d6b27c3c3
Added pre commit hooks before commiting fairway marks to invalidate old.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4956
diff
changeset
|
283 // have updated last_found |
4961
67d78b74fe43
Be more careful with unchanged errors if features were removed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4960
diff
changeset
|
284 if features == 0 && err == ErrFeaturesUnmodified { |
4956
7cc79c65a9e5
Keep the history of fairway marks
Tom Gottfried <tom@intevation.de>
parents:
4954
diff
changeset
|
285 return nil, UnchangedError("no valid new features found") |
7cc79c65a9e5
Keep the history of fairway marks
Tom Gottfried <tom@intevation.de>
parents:
4954
diff
changeset
|
286 } |
7cc79c65a9e5
Keep the history of fairway marks
Tom Gottfried <tom@intevation.de>
parents:
4954
diff
changeset
|
287 |
4961
67d78b74fe43
Be more careful with unchanged errors if features were removed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4960
diff
changeset
|
288 if err == ErrFeaturesUnmodified { |
67d78b74fe43
Be more careful with unchanged errors if features were removed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4960
diff
changeset
|
289 // It's not really an error. |
67d78b74fe43
Be more careful with unchanged errors if features were removed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4960
diff
changeset
|
290 err = nil |
67d78b74fe43
Be more careful with unchanged errors if features were removed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4960
diff
changeset
|
291 } |
67d78b74fe43
Be more careful with unchanged errors if features were removed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4960
diff
changeset
|
292 |
67d78b74fe43
Be more careful with unchanged errors if features were removed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4960
diff
changeset
|
293 return nil, err |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
294 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
295 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
296 // SQLGeometryConsumer stores a WFS feature into the DB. |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
297 type SQLGeometryConsumer struct { |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
298 ctx context.Context |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
299 tx *sql.Tx |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
300 feedback Feedback |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
301 consume func(*SQLGeometryConsumer, interface{}, interface{}, int) error |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
302 newFeature func() (string, interface{}) |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
303 preCommit func(*SQLGeometryConsumer) error |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
304 savepoint func(func() error) error |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
305 stmts []*sql.Stmt |
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
306 } |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
307 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
308 // Rollback rolls back the database state of this consumer. |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
309 func (sgc *SQLGeometryConsumer) Rollback() error { |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
310 if tx := sgc.tx; tx != nil { |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
311 sgc.releaseStmts() |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
312 sgc.tx = nil |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
313 sgc.ctx = nil |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
314 return tx.Rollback() |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
315 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
316 return nil |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
317 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
318 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
319 // Commit commits the database changes of this consumer to the database. |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
320 func (sgc *SQLGeometryConsumer) Commit() error { |
4961
67d78b74fe43
Be more careful with unchanged errors if features were removed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4960
diff
changeset
|
321 var err error |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
322 if tx := sgc.tx; tx != nil { |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
323 if sgc.preCommit != nil { |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
324 err = sgc.preCommit(sgc) |
4958
6d5d6b27c3c3
Added pre commit hooks before commiting fairway marks to invalidate old.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4956
diff
changeset
|
325 } |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
326 sgc.releaseStmts() |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
327 sgc.tx = nil |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
328 sgc.ctx = nil |
5143
733f7136a30e
Do not mask error with subsequent error on commit
Tom Gottfried <tom@intevation.de>
parents:
5140
diff
changeset
|
329 if err2 := tx.Commit(); err2 != nil && |
733f7136a30e
Do not mask error with subsequent error on commit
Tom Gottfried <tom@intevation.de>
parents:
5140
diff
changeset
|
330 (err == nil || err == ErrFeaturesUnmodified) { |
733f7136a30e
Do not mask error with subsequent error on commit
Tom Gottfried <tom@intevation.de>
parents:
5140
diff
changeset
|
331 // An error on commit that is not induced by the first |
733f7136a30e
Do not mask error with subsequent error on commit
Tom Gottfried <tom@intevation.de>
parents:
5140
diff
changeset
|
332 // overrules the first. |
5140
11c4c5b8041c
Backed out changeset c9bca9a9666c
Tom Gottfried <tom@intevation.de>
parents:
5138
diff
changeset
|
333 err = err2 |
4961
67d78b74fe43
Be more careful with unchanged errors if features were removed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4960
diff
changeset
|
334 } |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
335 } |
4961
67d78b74fe43
Be more careful with unchanged errors if features were removed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4960
diff
changeset
|
336 return err |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
337 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
338 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
339 // NewFeature forwards the feature creation. |
5007
799e8248de8d
First step to move geometry creation for WFS features to loader.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4991
diff
changeset
|
340 func (sgc *SQLGeometryConsumer) NewFeature() (string, interface{}) { |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
341 return sgc.newFeature() |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
342 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
343 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
344 // Consume forwards the consumption of the given feature. |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
345 func (sgc *SQLGeometryConsumer) Consume( |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
346 geom, properties interface{}, |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
347 epsg int, |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
348 ) error { |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
349 return sgc.consume(sgc, geom, properties, epsg) |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
350 } |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
351 |
5601
1222b777f51f
Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5565
diff
changeset
|
352 // ConsumePolygon forwards the consumption of a polygon. |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
353 func (sgc *SQLGeometryConsumer) ConsumePolygon( |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
354 polygon polygonSlice, |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
355 properties interface{}, |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
356 epsg int, |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
357 ) error { |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
358 return sgc.consume(sgc, polygon, properties, epsg) |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
359 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
360 |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
361 func newSQLConsumer( |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
362 init func(*SQLGeometryConsumer) error, |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
363 consume func(*SQLGeometryConsumer, interface{}, interface{}, int) error, |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
364 preCommit func(*SQLGeometryConsumer) error, |
5007
799e8248de8d
First step to move geometry creation for WFS features to loader.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4991
diff
changeset
|
365 newFeature func() (string, interface{}), |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
366 |
4978
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
367 ) func(context.Context, *sql.Conn, Feedback) (WFSFeatureConsumer, error) { |
35a3dc12050f
Give better names to generalized WFS feature downloaders.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4977
diff
changeset
|
368 return func(ctx context.Context, conn *sql.Conn, feedback Feedback) (WFSFeatureConsumer, error) { |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
369 tx, err := conn.BeginTx(ctx, nil) |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
370 if err != nil { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
371 return nil, err |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
372 } |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
373 sgc := &SQLGeometryConsumer{ |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
374 ctx: ctx, |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
375 tx: tx, |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
376 feedback: feedback, |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
377 consume: consume, |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
378 newFeature: newFeature, |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
379 preCommit: preCommit, |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
380 savepoint: Savepoint(ctx, tx, "feature"), |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
381 } |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
382 if err := init(sgc); err != nil { |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
383 tx.Rollback() |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
384 return nil, err |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
385 } |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
386 return sgc, nil |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
387 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
388 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
389 |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
390 func (sgc *SQLGeometryConsumer) releaseStmts() { |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
391 for i := len(sgc.stmts); i > 0; i-- { |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
392 sgc.stmts[i-1].Close() |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
393 sgc.stmts[i-1] = nil |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
394 } |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
395 sgc.stmts = nil |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
396 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
397 |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
398 func prepareStmnts(queries ...string) func(*SQLGeometryConsumer) error { |
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
399 return func(sgc *SQLGeometryConsumer) error { |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
400 for _, query := range queries { |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
401 stmt, err := sgc.tx.PrepareContext(sgc.ctx, query) |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
402 if err != nil { |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
403 return err |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
404 } |
4977
4bf6cde2d996
Generalize WFS point import job to be able to import other geometry types, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4961
diff
changeset
|
405 sgc.stmts = append(sgc.stmts, stmt) |
4946
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
406 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
407 return nil |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
408 } |
b0dbc0f2c748
Simplified importing of fairway marks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
409 } |