comparison pkg/imports/wfsjob.go @ 5601:1222b777f51f

Made golint finally happy.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 06 Aug 2022 02:09:57 +0200
parents ade07a3f2cfd
children 2dd155cc95ec
comparison
equal deleted inserted replaced
5600:9967a78e43f4 5601:1222b777f51f
26 "gemma.intevation.de/gemma/pkg/models" 26 "gemma.intevation.de/gemma/pkg/models"
27 "gemma.intevation.de/gemma/pkg/wfs" 27 "gemma.intevation.de/gemma/pkg/wfs"
28 ) 28 )
29 29
30 var ( 30 var (
31 ErrFeatureIgnored = errors.New("feature ignored") 31 // ErrFeatureIgnored indicates if a feature is ignored.
32 ErrFeatureDuplicated = errors.New("feature duplicated") 32 ErrFeatureIgnored = errors.New("feature ignored")
33 // ErrFeatureDuplicated indicates if a feature is a duplicate.
34 ErrFeatureDuplicated = errors.New("feature duplicated")
35 // ErrFeaturesUnmodified indicates if a feature is unmodified.
33 ErrFeaturesUnmodified = errors.New("features unmodified") 36 ErrFeaturesUnmodified = errors.New("features unmodified")
34 ) 37 )
35 38
36 type ( 39 type (
40 // WFSFeatureConsumer is an interface to model a transactional
41 // handling to create new features.
37 WFSFeatureConsumer interface { 42 WFSFeatureConsumer interface {
38 Commit() error 43 Commit() error
39 Rollback() error 44 Rollback() error
40 45
41 NewFeature() (kind string, properties interface{}) 46 NewFeature() (kind string, properties interface{})
42 47
43 Consume(geom, properties interface{}, epsg int) error 48 Consume(geom, properties interface{}, epsg int) error
44 } 49 }
45 50
51 // WFSFeatureJobCreator is a factory to create feature consumers.
46 WFSFeatureJobCreator struct { 52 WFSFeatureJobCreator struct {
47 description string 53 description string
48 depends [2][]string 54 depends [2][]string
49 55
50 newConsumer func(context.Context, *sql.Conn, Feedback) (WFSFeatureConsumer, error) 56 newConsumer func(context.Context, *sql.Conn, Feedback) (WFSFeatureConsumer, error)
51 57
52 stageDone func(context.Context, *sql.Tx, int64, Feedback) error 58 stageDone func(context.Context, *sql.Tx, int64, Feedback) error
53 } 59 }
54 60
61 // WFSFeatureJob is job to do an WFS import.
55 WFSFeatureJob struct { 62 WFSFeatureJob struct {
56 models.WFSImport 63 models.WFSImport
57 creator *WFSFeatureJobCreator 64 creator *WFSFeatureJobCreator
58 } 65 }
59 ) 66 )
72 return &multiLineSlice{*x.(*lineSlice)} 79 return &multiLineSlice{*x.(*lineSlice)}
73 }, 80 },
74 } 81 }
75 ) 82 )
76 83
84 // Description gives a short description of this creator.
77 func (wfjc *WFSFeatureJobCreator) Description() string { 85 func (wfjc *WFSFeatureJobCreator) Description() string {
78 return wfjc.description 86 return wfjc.description
79 } 87 }
80 88
89 // Depends lists the dependencies of this creator.
81 func (wfjc *WFSFeatureJobCreator) Depends() [2][]string { 90 func (wfjc *WFSFeatureJobCreator) Depends() [2][]string {
82 return wfjc.depends 91 return wfjc.depends
83 } 92 }
84 93
94 // AutoAccept auto accepts this job if there
95 // is no stageDone implementation.
85 func (wfjc *WFSFeatureJobCreator) AutoAccept() bool { 96 func (wfjc *WFSFeatureJobCreator) AutoAccept() bool {
86 return wfjc.stageDone == nil 97 return wfjc.stageDone == nil
87 } 98 }
88 99
100 // StageDone forwards the StageDone call.
89 func (wfjc *WFSFeatureJobCreator) StageDone( 101 func (wfjc *WFSFeatureJobCreator) StageDone(
90 ctx context.Context, 102 ctx context.Context,
91 tx *sql.Tx, 103 tx *sql.Tx,
92 id int64, 104 id int64,
93 feedback Feedback, 105 feedback Feedback,
96 return nil 108 return nil
97 } 109 }
98 return wfjc.stageDone(ctx, tx, id, feedback) 110 return wfjc.stageDone(ctx, tx, id, feedback)
99 } 111 }
100 112
113 // Create creates the WFS job.
101 func (wfjc *WFSFeatureJobCreator) Create() Job { 114 func (wfjc *WFSFeatureJobCreator) Create() Job {
102 return &WFSFeatureJob{creator: wfjc} 115 return &WFSFeatureJob{creator: wfjc}
103 } 116 }
104 117
105 // Description gives a short info about relevant facts of this import. 118 // Description gives a short info about relevant facts of this import.
110 // CleanUp for WFS imports is a NOP. 123 // CleanUp for WFS imports is a NOP.
111 func (*WFSFeatureJob) CleanUp() error { 124 func (*WFSFeatureJob) CleanUp() error {
112 return nil 125 return nil
113 } 126 }
114 127
128 // Do implements the actual WFS import.
115 func (wfj *WFSFeatureJob) Do( 129 func (wfj *WFSFeatureJob) Do(
116 ctx context.Context, 130 ctx context.Context,
117 importID int64, 131 importID int64,
118 conn *sql.Conn, 132 conn *sql.Conn,
119 feedback Feedback, 133 feedback Feedback,
277 } 291 }
278 292
279 return nil, err 293 return nil, err
280 } 294 }
281 295
282 type ( 296 // SQLGeometryConsumer stores a WFS feature into the DB.
283 SQLGeometryConsumer struct { 297 type SQLGeometryConsumer struct {
284 ctx context.Context 298 ctx context.Context
285 tx *sql.Tx 299 tx *sql.Tx
286 feedback Feedback 300 feedback Feedback
287 consume func(*SQLGeometryConsumer, interface{}, interface{}, int) error 301 consume func(*SQLGeometryConsumer, interface{}, interface{}, int) error
288 newFeature func() (string, interface{}) 302 newFeature func() (string, interface{})
289 preCommit func(*SQLGeometryConsumer) error 303 preCommit func(*SQLGeometryConsumer) error
290 savepoint func(func() error) error 304 savepoint func(func() error) error
291 stmts []*sql.Stmt 305 stmts []*sql.Stmt
292 } 306 }
293 ) 307
294 308 // Rollback rolls back the database state of this consumer.
295 func (sgc *SQLGeometryConsumer) Rollback() error { 309 func (sgc *SQLGeometryConsumer) Rollback() error {
296 if tx := sgc.tx; tx != nil { 310 if tx := sgc.tx; tx != nil {
297 sgc.releaseStmts() 311 sgc.releaseStmts()
298 sgc.tx = nil 312 sgc.tx = nil
299 sgc.ctx = nil 313 sgc.ctx = nil
300 return tx.Rollback() 314 return tx.Rollback()
301 } 315 }
302 return nil 316 return nil
303 } 317 }
304 318
319 // Commit commits the database changes of this consumer to the database.
305 func (sgc *SQLGeometryConsumer) Commit() error { 320 func (sgc *SQLGeometryConsumer) Commit() error {
306 var err error 321 var err error
307 if tx := sgc.tx; tx != nil { 322 if tx := sgc.tx; tx != nil {
308 if sgc.preCommit != nil { 323 if sgc.preCommit != nil {
309 err = sgc.preCommit(sgc) 324 err = sgc.preCommit(sgc)
319 } 334 }
320 } 335 }
321 return err 336 return err
322 } 337 }
323 338
339 // NewFeature forwards the feature creation.
324 func (sgc *SQLGeometryConsumer) NewFeature() (string, interface{}) { 340 func (sgc *SQLGeometryConsumer) NewFeature() (string, interface{}) {
325 return sgc.newFeature() 341 return sgc.newFeature()
326 } 342 }
327 343
344 // Consume forwards the consumption of the given feature.
328 func (sgc *SQLGeometryConsumer) Consume( 345 func (sgc *SQLGeometryConsumer) Consume(
329 geom, properties interface{}, 346 geom, properties interface{},
330 epsg int, 347 epsg int,
331 ) error { 348 ) error {
332 return sgc.consume(sgc, geom, properties, epsg) 349 return sgc.consume(sgc, geom, properties, epsg)
333 } 350 }
334 351
352 // ConsumePolygon forwards the consumption of a polygon.
335 func (sgc *SQLGeometryConsumer) ConsumePolygon( 353 func (sgc *SQLGeometryConsumer) ConsumePolygon(
336 polygon polygonSlice, 354 polygon polygonSlice,
337 properties interface{}, 355 properties interface{},
338 epsg int, 356 epsg int,
339 ) error { 357 ) error {