Mercurial > gemma
diff 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 |
line wrap: on
line diff
--- a/pkg/imports/wfsjob.go Sat Aug 06 00:46:21 2022 +0200 +++ b/pkg/imports/wfsjob.go Sat Aug 06 02:09:57 2022 +0200 @@ -28,12 +28,17 @@ ) var ( - ErrFeatureIgnored = errors.New("feature ignored") - ErrFeatureDuplicated = errors.New("feature duplicated") + // ErrFeatureIgnored indicates if a feature is ignored. + ErrFeatureIgnored = errors.New("feature ignored") + // ErrFeatureDuplicated indicates if a feature is a duplicate. + ErrFeatureDuplicated = errors.New("feature duplicated") + // ErrFeaturesUnmodified indicates if a feature is unmodified. ErrFeaturesUnmodified = errors.New("features unmodified") ) type ( + // WFSFeatureConsumer is an interface to model a transactional + // handling to create new features. WFSFeatureConsumer interface { Commit() error Rollback() error @@ -43,6 +48,7 @@ Consume(geom, properties interface{}, epsg int) error } + // WFSFeatureJobCreator is a factory to create feature consumers. WFSFeatureJobCreator struct { description string depends [2][]string @@ -52,6 +58,7 @@ stageDone func(context.Context, *sql.Tx, int64, Feedback) error } + // WFSFeatureJob is job to do an WFS import. WFSFeatureJob struct { models.WFSImport creator *WFSFeatureJobCreator @@ -74,18 +81,23 @@ } ) +// Description gives a short description of this creator. func (wfjc *WFSFeatureJobCreator) Description() string { return wfjc.description } +// Depends lists the dependencies of this creator. func (wfjc *WFSFeatureJobCreator) Depends() [2][]string { return wfjc.depends } +// AutoAccept auto accepts this job if there +// is no stageDone implementation. func (wfjc *WFSFeatureJobCreator) AutoAccept() bool { return wfjc.stageDone == nil } +// StageDone forwards the StageDone call. func (wfjc *WFSFeatureJobCreator) StageDone( ctx context.Context, tx *sql.Tx, @@ -98,6 +110,7 @@ return wfjc.stageDone(ctx, tx, id, feedback) } +// Create creates the WFS job. func (wfjc *WFSFeatureJobCreator) Create() Job { return &WFSFeatureJob{creator: wfjc} } @@ -112,6 +125,7 @@ return nil } +// Do implements the actual WFS import. func (wfj *WFSFeatureJob) Do( ctx context.Context, importID int64, @@ -279,19 +293,19 @@ return nil, err } -type ( - SQLGeometryConsumer struct { - ctx context.Context - tx *sql.Tx - feedback Feedback - consume func(*SQLGeometryConsumer, interface{}, interface{}, int) error - newFeature func() (string, interface{}) - preCommit func(*SQLGeometryConsumer) error - savepoint func(func() error) error - stmts []*sql.Stmt - } -) +// SQLGeometryConsumer stores a WFS feature into the DB. +type SQLGeometryConsumer struct { + ctx context.Context + tx *sql.Tx + feedback Feedback + consume func(*SQLGeometryConsumer, interface{}, interface{}, int) error + newFeature func() (string, interface{}) + preCommit func(*SQLGeometryConsumer) error + savepoint func(func() error) error + stmts []*sql.Stmt +} +// Rollback rolls back the database state of this consumer. func (sgc *SQLGeometryConsumer) Rollback() error { if tx := sgc.tx; tx != nil { sgc.releaseStmts() @@ -302,6 +316,7 @@ return nil } +// Commit commits the database changes of this consumer to the database. func (sgc *SQLGeometryConsumer) Commit() error { var err error if tx := sgc.tx; tx != nil { @@ -321,10 +336,12 @@ return err } +// NewFeature forwards the feature creation. func (sgc *SQLGeometryConsumer) NewFeature() (string, interface{}) { return sgc.newFeature() } +// Consume forwards the consumption of the given feature. func (sgc *SQLGeometryConsumer) Consume( geom, properties interface{}, epsg int, @@ -332,6 +349,7 @@ return sgc.consume(sgc, geom, properties, epsg) } +// ConsumePolygon forwards the consumption of a polygon. func (sgc *SQLGeometryConsumer) ConsumePolygon( polygon polygonSlice, properties interface{},