annotate pkg/imports/fm_bcnlat.go @ 4933:45ef039cf4a8 fairway-marks-import

grant select rights to sys_admin to new group layers tables.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 15 Feb 2020 19:08:02 +0100
parents e41d42be0e13
children 9f9d72a1d398
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 (
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
83 insertBCNLATSQL = `
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
84 with a as (
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
85 select users.current_user_area_utm() AS a
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
86 )
4909
6f244b5eb716 Use table inheritance to define common fairway marks attributes
Tom Gottfried <tom@intevation.de>
parents: 4908
diff changeset
87 INSERT INTO waterway.fairway_marks_bcnlat (
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
88 geom,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
89 datsta,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
90 datend,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
91 persta,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
92 perend,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
93 objnam,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
94 nobjnm,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
95 inform,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
96 ninfom,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
97 scamin,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
98 picrep,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
99 txtdsc,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
100 sordat,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
101 sorind,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
102 colour,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
103 colpat,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
104 condtn,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
105 bcnshp,
4912
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
106 catlam
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
107 )
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
108 SELECT newfm, $3, $4, $5, $6, $7, $8, $9,
4912
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
109 $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
110 FROM ST_Transform(ST_GeomFromWKB($1, $2::integer), 4326) AS newfm (newfm)
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
111 WHERE pg_has_role('sys_admin', 'MEMBER')
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
112 OR ST_Intersects((select a from a),
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
113 ST_Transform(newfm, (select ST_SRID(a) from a)))
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
114 ON CONFLICT (
4909
6f244b5eb716 Use table inheritance to define common fairway marks attributes
Tom Gottfried <tom@intevation.de>
parents: 4908
diff changeset
115 CAST((geom,
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
116 datsta, datend, persta, perend, objnam, nobjnm, inform, ninfom,
4909
6f244b5eb716 Use table inheritance to define common fairway marks attributes
Tom Gottfried <tom@intevation.de>
parents: 4908
diff changeset
117 scamin, picrep, txtdsc, sordat, sorind,
4912
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
118 0, colour, colpat, condtn, bcnshp, catlam
4909
6f244b5eb716 Use table inheritance to define common fairway marks attributes
Tom Gottfried <tom@intevation.de>
parents: 4908
diff changeset
119 ) AS waterway.fairway_marks_bcnlat)
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
120 )
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
121 DO NOTHING
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
122 RETURNING id
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
123 `
4912
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
124 insertDirimpSQL = `
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
125 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
126 VALUES ($1, $2)
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
127 `
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
128 )
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
129
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
130 // Do executes the actual import.
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
131 func (fm *Bcnlat) Do(
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
132 ctx context.Context,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
133 importID int64,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
134 conn *sql.Conn,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
135 feedback Feedback,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
136 ) (interface{}, error) {
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
137
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
138 err := getFMFeatures(
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
139 ctx,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
140 conn,
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
141 feedback,
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
142 fm.FairwayMarks,
4905
8cb201b551b3 Replace bogus usage of pointer for type intrusion
Tom Gottfried <tom@intevation.de>
parents: 4904
diff changeset
143 func() interface{} { return new(bcnlatProperties) },
4907
644cb7c175f3 Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents: 4905
diff changeset
144 func(p pointSlice, props interface{}) interface{} {
644cb7c175f3 Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents: 4905
diff changeset
145 return &bcnlatFeaturetype{p, props.(*bcnlatProperties)}
644cb7c175f3 Use proper type to represent featuretype
Tom Gottfried <tom@intevation.de>
parents: 4905
diff changeset
146 },
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
147 func(
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
148 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
149 ) (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
150
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
151 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
152
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
153 insertStmt, err := tx.PrepareContext(ctx, insertBCNLATSQL)
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
154 if err != nil {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
155 return
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
156 }
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
157 defer insertStmt.Close()
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
158
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
159 insertDirimpStmt, err := tx.PrepareContext(ctx, insertDirimpSQL)
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
160 if err != nil {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
161 return
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
162 }
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
163 defer insertDirimpStmt.Close()
4912
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
164
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
165 savepoint := Savepoint(ctx, tx, "feature")
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
166
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
167 for _, fm := range fms {
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
168
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
169 f := fm.(*bcnlatFeaturetype)
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
170
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
171 var catlam sql.NullInt64
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
172 if f.props.HydroCatlam != nil {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
173 catlam = sql.NullInt64{
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
174 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
175 } 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
176 catlam = sql.NullInt64{
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
177 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
178 }
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
179
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
180 var fmid int64
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
181 err := savepoint(func() error {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
182 err := insertStmt.QueryRowContext(
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
183 ctx,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
184 f.geom.asWKB(),
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
185 epsg,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
186 f.props.Datsta,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
187 f.props.Datend,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
188 f.props.Persta,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
189 f.props.Perend,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
190 f.props.Objnam,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
191 f.props.Nobjnm,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
192 f.props.Inform,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
193 f.props.Ninfom,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
194 f.props.Scamin,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
195 f.props.Picrep,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
196 f.props.Txtdsc,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
197 f.props.Sordat,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
198 f.props.Sorind,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
199 f.props.Colour,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
200 f.props.Colpat,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
201 f.props.Condtn,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
202 f.props.Bcnshp,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
203 catlam,
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
204 ).Scan(&fmid)
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
205 return err
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
206 })
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
207 switch {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
208 case err == sql.ErrNoRows:
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
209 outsideOrDup++
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
210 // 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
211 // 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
212 case err != nil:
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
213 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
214 default:
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
215 features++
4912
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
216
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
217 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
218 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
219 for _, dirimp := range dirimps {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
220 if err := savepoint(func() error {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
221 _, err := insertDirimpStmt.ExecContext(
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
222 ctx, fmid, dirimp)
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
223 return err
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
224 }); err != nil {
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
225 feedback.Warn(
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
226 pgxutils.ReadableError{Err: err}.Error())
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
227 }
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
228 }
4912
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
229 }
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
230 }
bfd8ef836998 Fix handling of attribute dirimp
Tom Gottfried <tom@intevation.de>
parents: 4911
diff changeset
231 }
4931
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
232 return
e41d42be0e13 One more callback to avoid code duplication more consequently
Tom Gottfried <tom@intevation.de>
parents: 4912
diff changeset
233 })
4904
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
234
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
235 return nil, err
53d929f658f3 Separate code common to all types of fairway mark imports
Tom Gottfried <tom@intevation.de>
parents:
diff changeset
236 }