annotate pkg/imports/fm_bcnlat.go @ 4941:df6c8a485979 fairway-marks-import

Improve handling of invalid dirimp values
author Tom Gottfried <tom@intevation.de>
date Mon, 17 Feb 2020 19:00:44 +0100
parents b3b2ba09a450
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
1 // This is Free Software under GNU Affero General Public License v >= 3.0
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
2 // without warranty, see README.md and license for details.
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
3 //
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
4 // SPDX-License-Identifier: AGPL-3.0-or-later
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
5 // License-Filename: LICENSES/AGPL-3.0.txt
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
6 //
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
7 // Copyright (C) 2020 by via donau
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
9 // Software engineering by Intevation GmbH
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
10 //
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
11 // Author(s):
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
12 // * Tom Gottfried <tom.gottfried@intevation.de>
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
13
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
14 package imports
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
15
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
16 import (
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
17 "context"
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
18 "database/sql"
4912
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
19 "strings"
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
20
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
21 "gemma.intevation.de/gemma/pkg/pgxutils"
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
22 )
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
23
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
24 // Bcnlat is an import job to import
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
25 // fairway marks of type BCNLAT in form of point geometries
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
26 // and attribute data from a WFS service.
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
27 type Bcnlat struct {
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
28 FairwayMarks
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
29 }
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
30
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
31 // Description gives a short info about relevant facts of this import.
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
32 func (bcnlat *Bcnlat) Description() (string, error) {
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
33 return bcnlat.URL + "|" + bcnlat.FeatureType, nil
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
34 }
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
35
4911
bcb8b69e4358 Type specific names for fairway marks import
Tom Gottfried <tom@intevation.de>
parents: 4909
diff changeset
36 // BCNLATJobKind is the import queue type identifier.
bcb8b69e4358 Type specific names for fairway marks import
Tom Gottfried <tom@intevation.de>
parents: 4909
diff changeset
37 const BCNLATJobKind JobKind = "fm_bcnlat"
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
38
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
39 type bcnlatJobCreator struct{}
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
40
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
41 func init() {
4911
bcb8b69e4358 Type specific names for fairway marks import
Tom Gottfried <tom@intevation.de>
parents: 4909
diff changeset
42 RegisterJobCreator(BCNLATJobKind, bcnlatJobCreator{})
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
43 }
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
44
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
45 func (bcnlatJobCreator) Description() string { return "fairway marks bcnlat" }
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
46
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
47 func (bcnlatJobCreator) AutoAccept() bool { return true }
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
48
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
49 func (bcnlatJobCreator) Create() Job { return new(Bcnlat) }
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
50
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
51 func (bcnlatJobCreator) Depends() [2][]string {
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
52 return [2][]string{
4909
6f244b5eb716 Use table inheritance to define common fairway marks attributes
Tom Gottfried <tom@intevation.de>
parents: 4908
diff changeset
53 {"fairway_marks_bcnlat"},
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
54 {},
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
55 }
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
56 }
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
57
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
58 // StageDone is a NOP for fairway marks imports.
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
59 func (bcnlatJobCreator) StageDone(context.Context, *sql.Tx, int64) error {
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
60 return nil
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
61 }
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
62
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
63 // CleanUp for fairway marks imports is a NOP.
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
64 func (*Bcnlat) CleanUp() error { return nil }
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
65
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
66 type bcnlatProperties struct {
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
67 fairwayMarksProperties
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
68 Colour *string `json:"hydro_colour"`
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
69 Colpat *string `json:"hydro_colpat"`
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
70 Condtn *int `json:"hydro_condtn"`
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
71 Bcnshp *int `json:"hydro_bcnshp"`
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
72 HydroCatlam *int64 `json:"hydro_catlam,omitempty"`
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
73 IENCCatlam *int64 `json:"ienc_catlam,omitempty"`
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
74 Dirimp *string `json:"ienc_dirimp,omitempty"`
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
75 }
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
76
4907
644cb7c175f3 Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents: 4905
diff changeset
77 type bcnlatFeaturetype struct {
644cb7c175f3 Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents: 4905
diff changeset
78 geom pointSlice
644cb7c175f3 Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents: 4905
diff changeset
79 props *bcnlatProperties
644cb7c175f3 Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents: 4905
diff changeset
80 }
644cb7c175f3 Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents: 4905
diff changeset
81
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
82 const (
4940
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents: 4939
diff changeset
83 insertBcnlatDirimpSQL = `
4912
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
84 INSERT INTO waterway.fairway_marks_bcnlat_dirimps (fm_bcnlat_id, dirimp)
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
85 VALUES ($1, $2)
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
86 `
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
87 )
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
88
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
89 // Do executes the actual import.
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
90 func (fm *Bcnlat) Do(
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
91 ctx context.Context,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
92 importID int64,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
93 conn *sql.Conn,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
94 feedback Feedback,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
95 ) (interface{}, error) {
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
96
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
97 err := getFMFeatures(
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
98 ctx,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
99 conn,
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
100 feedback,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
101 fm.FairwayMarks,
4905
8cb201b551b3 Replace bogus usage of pointer for type intrusion
Tom Gottfried <tom@intevation.de>
parents: 4904
diff changeset
102 func() interface{} { return new(bcnlatProperties) },
4907
644cb7c175f3 Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents: 4905
diff changeset
103 func(p pointSlice, props interface{}) interface{} {
644cb7c175f3 Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents: 4905
diff changeset
104 return &bcnlatFeaturetype{p, props.(*bcnlatProperties)}
644cb7c175f3 Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents: 4905
diff changeset
105 },
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
106 func(
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
107 tx *sql.Tx, epsg int, fms []interface{},
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
108 ) (outsideOrDup int, features int, err error) {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
109
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
110 feedback.Info("Store fairway marks of type BCNLAT/bcnlat")
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
111
4938
9f9d72a1d398 Save some typos and wrong parameter counts when adding new fairway mark types
Tom Gottfried <tom@intevation.de>
parents: 4931
diff changeset
112 insertStmt, err := tx.PrepareContext(
9f9d72a1d398 Save some typos and wrong parameter counts when adding new fairway mark types
Tom Gottfried <tom@intevation.de>
parents: 4931
diff changeset
113 ctx,
4939
39b67b910204 Make getFMInsertSQL variadic
Tom Gottfried <tom@intevation.de>
parents: 4938
diff changeset
114 getFMInsertSQL("bcnlat",
39b67b910204 Make getFMInsertSQL variadic
Tom Gottfried <tom@intevation.de>
parents: 4938
diff changeset
115 "colour", "colpat", "condtn", "bcnshp", "catlam"),
4938
9f9d72a1d398 Save some typos and wrong parameter counts when adding new fairway mark types
Tom Gottfried <tom@intevation.de>
parents: 4931
diff changeset
116 )
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
117 if err != nil {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
118 return
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
119 }
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
120 defer insertStmt.Close()
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
121
4940
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents: 4939
diff changeset
122 insertBcnlatDirimpStmt, err := tx.PrepareContext(
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents: 4939
diff changeset
123 ctx, insertBcnlatDirimpSQL)
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
124 if err != nil {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
125 return
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
126 }
4940
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents: 4939
diff changeset
127 defer insertBcnlatDirimpStmt.Close()
4912
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
128
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
129 savepoint := Savepoint(ctx, tx, "feature")
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
130
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
131 for _, fm := range fms {
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
132
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
133 f := fm.(*bcnlatFeaturetype)
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
134
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
135 var catlam sql.NullInt64
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
136 if f.props.HydroCatlam != nil {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
137 catlam = sql.NullInt64{
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
138 Int64: *f.props.HydroCatlam, Valid: true}
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
139 } else if f.props.IENCCatlam != nil {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
140 catlam = sql.NullInt64{
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
141 Int64: *f.props.IENCCatlam, Valid: true}
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
142 }
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
143
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
144 var fmid int64
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
145 err := savepoint(func() error {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
146 err := insertStmt.QueryRowContext(
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
147 ctx,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
148 f.geom.asWKB(),
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
149 epsg,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
150 f.props.Datsta,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
151 f.props.Datend,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
152 f.props.Persta,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
153 f.props.Perend,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
154 f.props.Objnam,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
155 f.props.Nobjnm,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
156 f.props.Inform,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
157 f.props.Ninfom,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
158 f.props.Scamin,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
159 f.props.Picrep,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
160 f.props.Txtdsc,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
161 f.props.Sordat,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
162 f.props.Sorind,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
163 f.props.Colour,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
164 f.props.Colpat,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
165 f.props.Condtn,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
166 f.props.Bcnshp,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
167 catlam,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
168 ).Scan(&fmid)
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
169 return err
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
170 })
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
171 switch {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
172 case err == sql.ErrNoRows:
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
173 outsideOrDup++
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
174 // ignore -> filtered by responsibility area or a duplicate
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
175 // TODO: handle eventual changes to dirimp
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
176 case err != nil:
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
177 feedback.Error(pgxutils.ReadableError{Err: err}.Error())
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
178 default:
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
179 features++
4912
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
180
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
181 if f.props.Dirimp != nil && *f.props.Dirimp != "" {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
182 dirimps := strings.Split(*f.props.Dirimp, ",")
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
183 for _, dirimp := range dirimps {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
184 if err := savepoint(func() error {
4940
b3b2ba09a450 Add missing fairway mark types
Tom Gottfried <tom@intevation.de>
parents: 4939
diff changeset
185 _, err := insertBcnlatDirimpStmt.ExecContext(
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
186 ctx, fmid, dirimp)
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
187 return err
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
188 }); err != nil {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
189 feedback.Warn(
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
190 pgxutils.ReadableError{Err: err}.Error())
4941
df6c8a485979 Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents: 4940
diff changeset
191 feedback.Info(
df6c8a485979 Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents: 4940
diff changeset
192 "Tried to import '%s' as dirimp value",
df6c8a485979 Improve handling of invalid dirimp values
Tom Gottfried <tom@intevation.de>
parents: 4940
diff changeset
193 dirimp)
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
194 }
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
195 }
4912
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
196 }
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
197 }
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
198 }
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
199 return
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
200 })
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
201
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
202 return nil, err
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
203 }