annotate pkg/imports/fa.go @ 3219:4acbee65275d

Import queue: Split locked dependencies in exclusively and multiple uses.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 09 May 2019 12:49:53 +0200
parents cfc523c70e90
children 02951a62e8c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 // This is Free Software under GNU Affero General Public License v >= 3.0
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2 // without warranty, see README.md and license for details.
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 //
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
4 // SPDX-License-Identifier: AGPL-3.0-or-later
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 // License-Filename: LICENSES/AGPL-3.0.txt
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6 //
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 // Copyright (C) 2018 by via donau
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9 // Software engineering by Intevation GmbH
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10 //
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 // Author(s):
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 // * Raimund Renkert <raimund.renkert@intevation.de>
2203
8d1a945d0c3b Uploaded fairway availabilty import: Implemented in terms of normal fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2202
diff changeset
13 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
1694
4a2fad8f57de Imports: Resolved golint issues unrelated to exported symbols commenting.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1676
diff changeset
14
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 package imports
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 import (
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 "context"
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19 "database/sql"
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 "errors"
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
21 "fmt"
2201
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
22 "sort"
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 "time"
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24
1663
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
25 "github.com/jackc/pgx/pgtype"
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
26
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 "gemma.intevation.de/gemma/pkg/soap/ifaf"
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 )
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29
1696
ad5e1cddaa09 Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1694
diff changeset
30 // FairwayAvailability imports fairway availability data
ad5e1cddaa09 Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1694
diff changeset
31 // from an IFAF SOAP service.
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 type FairwayAvailability struct {
1696
ad5e1cddaa09 Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1694
diff changeset
33 // URL is the URL of the SOAP service.
ad5e1cddaa09 Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1694
diff changeset
34 URL string `json:"url"`
ad5e1cddaa09 Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1694
diff changeset
35 // Insecure indicates if HTTPS traffic
ad5e1cddaa09 Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1694
diff changeset
36 // should validate certificates or not.
ad5e1cddaa09 Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1694
diff changeset
37 Insecure bool `json:"insecure"`
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39
2019
aeff01c6edec Moved fairwayavailability to a local model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
40 type uniqueFairwayAvailability struct {
aeff01c6edec Moved fairwayavailability to a local model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
41 BottleneckId string
aeff01c6edec Moved fairwayavailability to a local model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
42 Surdat time.Time
aeff01c6edec Moved fairwayavailability to a local model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
43 }
aeff01c6edec Moved fairwayavailability to a local model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
44
1696
ad5e1cddaa09 Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1694
diff changeset
45 // FAJobKind is import queue type identifier.
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 const FAJobKind JobKind = "fa"
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 const (
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 listBottlenecksSQL = `
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50 SELECT
2201
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
51 bottleneck_id
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 FROM waterway.bottlenecks
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 WHERE responsible_country = users.current_user_country()
1663
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
54 AND staging_done = true
2201
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
55 ORDER BY bottleneck_id
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 `
2201
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
57
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
58 latestMeasureDateSQL = `
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
59 SELECT
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
60 measure_date
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
61 FROM waterway.effective_fairway_availability
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
62 ORDER BY measure_date DESC LIMIT 1
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
63 `
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
64 listFairwayAvailabilitySQL = `
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
65 SELECT
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
66 fa.id,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
67 bn.bottleneck_id,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
68 fa.surdat
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
69 FROM waterway.fairway_availability fa
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
70 JOIN waterway.bottlenecks bn ON bn.id = fa.bottleneck_id
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
71 `
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 insertFASQL = `
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 INSERT INTO waterway.fairway_availability (
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 position_code,
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 bottleneck_id,
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 surdat,
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77 critical,
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 date_info,
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 source_organization
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 ) VALUES (
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 $1,
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82 (SELECT id FROM waterway.bottlenecks WHERE bottleneck_id = $2),
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
83 $3,
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
84 $4,
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85 $5,
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86 $6
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
87 )
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
88 RETURNING id`
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
89
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
90 insertBnPdfsSQL = `
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
91 INSERT INTO waterway.bottleneck_pdfs (
1663
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
92 fairway_availability_id,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
93 profile_pdf_filename,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
94 profile_pdf_url,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
95 pdf_generation_date,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
96 source_organization
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
97 ) VALUES (
1663
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
98 $1,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
99 $2,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
100 $3,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
101 $4,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
102 $5
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
103 ) ON CONFLICT ON CONSTRAINT bottleneck_pdfs_pkey DO NOTHING`
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104 insertEFASQL = `
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 INSERT INTO waterway.effective_fairway_availability (
1663
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
106 fairway_availability_id,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
107 measure_date,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
108 level_of_service,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
109 available_depth_value,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
110 available_width_value,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
111 water_level_value,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
112 measure_type,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
113 source_organization,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
114 forecast_generation_time,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
115 value_lifetime
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
116 ) VALUES (
1663
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
117 $1,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
118 $2,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
119 (SELECT
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
120 level_of_service
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
121 FROM levels_of_service
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
122 WHERE name = $3),
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
123 $4,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
124 $5,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
125 $6,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
126 $7,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
127 $8,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
128 $9,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
129 $10
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
130 ) ON CONFLICT ON CONSTRAINT effective_fairway_availability_pkey DO NOTHING`
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
131 insertFAVSQL = `
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
132 INSERT INTO waterway.fa_reference_values (
1663
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
133 fairway_availability_id,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
134 level_of_service,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
135 fairway_depth,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
136 fairway_width,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
137 fairway_radius,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
138 shallowest_spot
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
139 ) VALUES (
1663
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
140 $1,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
141 (SELECT
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
142 level_of_service
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
143 FROM levels_of_service
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
144 WHERE name = $2),
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
145 $3,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
146 $4,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
147 $5,
10e3dd3b9363 Fairway availability import: Don't use tabs in SQL statements.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1662
diff changeset
148 ST_MakePoint($6, $7)::geography
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
149 )ON CONFLICT ON CONSTRAINT fa_reference_values_pkey DO NOTHING`
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
150 )
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
151
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
152 type faJobCreator struct{}
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
153
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
154 func init() {
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
155 RegisterJobCreator(FAJobKind, faJobCreator{})
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
156 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
157
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
158 func (faJobCreator) Description() string {
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
159 return "fairway availability"
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
160 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
161
2187
7c83b5277c1c Import queue: Removed boilerplate code to deserialize jobs from JSON by making it part of the import queue.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2168
diff changeset
162 func (faJobCreator) Create() Job { return new(FairwayAvailability) }
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
163
3219
4acbee65275d Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2253
diff changeset
164 func (faJobCreator) Depends() [2][]string {
4acbee65275d Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2253
diff changeset
165 return [2][]string{
4acbee65275d Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2253
diff changeset
166 {"effective_fairway_availability", "fa_reference_values",
4acbee65275d Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2253
diff changeset
167 "bottleneck_pdfs", "fairway_availability"},
4acbee65275d Import queue: Split locked dependencies in exclusively and multiple uses.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2253
diff changeset
168 {"bottlenecks", "levels_of_service"},
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
169 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
170 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
171
1754
807569b08513 Import queue: Auto acceptance is now a property of the import kind itself and is not configurable any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1696
diff changeset
172 func (faJobCreator) AutoAccept() bool { return true }
807569b08513 Import queue: Auto acceptance is now a property of the import kind itself and is not configurable any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1696
diff changeset
173
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
174 // StageDone moves the imported fairway availablities out of the staging area.
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
175 // Currently doing nothing.
1676
4407ecaa2192 Imports: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1663
diff changeset
176 func (faJobCreator) StageDone(context.Context, *sql.Tx, int64) error {
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
177 return nil
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
178 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
179
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
180 // CleanUp of a fairway availablities import is a NOP.
1676
4407ecaa2192 Imports: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1663
diff changeset
181 func (*FairwayAvailability) CleanUp() error { return nil }
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
182
2201
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
183 type bottlenecks []string
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
184
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
185 func (bns bottlenecks) contains(bn string) bool {
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
186 idx := sort.SearchStrings(bns, bn)
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
187 return idx < len(bns) && bns[idx] == bn
2016
25967829cf00 Started to simplify the import models.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1756
diff changeset
188 }
25967829cf00 Started to simplify the import models.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1756
diff changeset
189
2201
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
190 func loadBottleneckCountries(ctx context.Context, tx *sql.Tx) (bottlenecks, error) {
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
191
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
192 // Get available bottlenecks from database for use as filter in SOAP request
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
193 rows, err := tx.QueryContext(ctx, listBottlenecksSQL)
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
194 if err != nil {
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
195 return nil, err
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
196 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
197 defer rows.Close()
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
198
2201
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
199 var bns bottlenecks
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
200
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
201 for rows.Next() {
2201
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
202 var bn string
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
203 if err = rows.Scan(&bn); err != nil {
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
204 return nil, err
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
205 }
2201
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
206 bns = append(bns, bn)
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
207 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
208 if err = rows.Err(); err != nil {
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
209 return nil, err
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
210 }
2201
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
211
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
212 return bns, nil
2198
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
213 }
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
214
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
215 func loadFairwayAvailabilities(ctx context.Context, tx *sql.Tx) (map[uniqueFairwayAvailability]int64, error) {
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
216 rows, err := tx.QueryContext(ctx, listFairwayAvailabilitySQL)
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
217 if err != nil {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
218 return nil, err
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
219 }
2198
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
220 defer rows.Close()
2019
aeff01c6edec Moved fairwayavailability to a local model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
221 fairwayAvailabilities := map[uniqueFairwayAvailability]int64{}
2198
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
222 for rows.Next() {
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
223 var id int64
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
224 var bnId string
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
225 var sd time.Time
2198
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
226 if err = rows.Scan(
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
227 &id,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
228 &bnId,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
229 &sd,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
230 ); err != nil {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
231 return nil, err
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
232 }
2019
aeff01c6edec Moved fairwayavailability to a local model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
233 key := uniqueFairwayAvailability{
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
234 BottleneckId: bnId,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
235 Surdat: sd,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
236 }
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
237 fairwayAvailabilities[key] = id
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
238 }
2198
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
239 if err = rows.Err(); err != nil {
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
240 return nil, err
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
241 }
2198
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
242 return fairwayAvailabilities, nil
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
243 }
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
244
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
245 func latestDate(ctx context.Context, tx *sql.Tx) (pgtype.Timestamp, error) {
2198
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
246 var date pgtype.Timestamp
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
247 err := tx.QueryRowContext(ctx, latestMeasureDateSQL).Scan(&date)
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
248 switch {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
249 case err == sql.ErrNoRows:
2198
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
250 date = pgtype.Timestamp{
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
251 // Fill Database with data of the last 5 days. Change this to a more useful value.
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
252 Time: time.Now().AddDate(0, 0, -5),
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
253 }
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
254 case err != nil:
2198
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
255 return pgtype.Timestamp{}, err
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
256 }
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
257 return date, nil
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
258 }
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
259
2202
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
260 func storeFairwayAvailability(
2198
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
261 ctx context.Context,
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
262 conn *sql.Conn,
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
263 feedback Feedback,
2202
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
264 fetch func(context.Context, *sql.Tx, bottlenecks) ([]*ifaf.FairwayAvailability, error),
2198
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
265 ) (interface{}, error) {
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
266
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
267 start := time.Now()
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
268
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
269 tx, err := conn.BeginTx(ctx, nil)
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
270 if err != nil {
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
271 return nil, err
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
272 }
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
273 defer tx.Rollback()
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
274
2201
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
275 bns, err := loadBottleneckCountries(ctx, tx)
2198
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
276 if err != nil {
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
277 return nil, err
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
278 }
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
279
2202
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
280 fas, err := fetch(ctx, tx, bns)
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
281 if err != nil {
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
282 return nil, err
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
283 }
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
284
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
285 fairwayAvailabilities, err := loadFairwayAvailabilities(ctx, tx)
2198
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
286 if err != nil {
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
287 return nil, err
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
288 }
4db1fa4f049c Fairway availabilty import: Fixed row query leak.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2196
diff changeset
289
2202
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
290 faids, err := doForFAs(ctx, bns, fairwayAvailabilities, fas, tx, feedback)
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
291 if err != nil {
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
292 return nil, fmt.Errorf("Error processing data: %v", err)
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
293 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
294 if len(faids) == 0 {
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
295 feedback.Info("No new fairway availablity data found")
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
296 return nil, UnchangedError("No new fairway availablity data found")
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
297 }
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
298 feedback.Info("Processed %d fairway availabilities", len(faids))
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
299
2233
137addc77b1b Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2203
diff changeset
300 if err = tx.Commit(); err != nil {
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
301 feedback.Info(
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
302 "Importing fairway availabilities failed after %s", time.Since(start))
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
303 return nil, err
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
304 }
2233
137addc77b1b Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2203
diff changeset
305 feedback.Info(
137addc77b1b Gauge measurement imports: Do all database ops in one transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2203
diff changeset
306 "Importing fairway availabilities successfully took %s", time.Since(start))
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
307
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
308 // TODO: needs to be filled more useful.
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
309 summary := struct {
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
310 FairwayAvailabilities []string `json:"fairwayAvailabilities"`
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
311 }{
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
312 FairwayAvailabilities: faids,
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
313 }
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
314 return &summary, nil
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
315 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
316
2202
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
317 func doForFAs(
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
318 ctx context.Context,
2201
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
319 bnIds bottlenecks,
2019
aeff01c6edec Moved fairwayavailability to a local model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
320 fairwayAvailabilities map[uniqueFairwayAvailability]int64,
2202
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
321 fas []*ifaf.FairwayAvailability,
2200
64147a137e0a Fairway availability import: Run all db ops in same transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2198
diff changeset
322 tx *sql.Tx,
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
323 feedback Feedback,
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
324 ) ([]string, error) {
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
325
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
326 insertFAStmt, err := tx.PrepareContext(ctx, insertFASQL)
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
327 if err != nil {
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
328 return nil, err
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
329 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
330 defer insertFAStmt.Close()
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
331 insertBnPdfsStmt, err := tx.PrepareContext(ctx, insertBnPdfsSQL)
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
332 if err != nil {
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
333 return nil, err
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
334 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
335 defer insertBnPdfsStmt.Close()
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
336 insertEFAStmt, err := tx.PrepareContext(ctx, insertEFASQL)
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
337 if err != nil {
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
338 return nil, err
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
339 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
340 defer insertEFAStmt.Close()
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
341 insertFAVStmt, err := tx.PrepareContext(ctx, insertFAVSQL)
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
342 if err != nil {
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
343 return nil, err
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
344 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
345 defer insertFAVStmt.Close()
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
346
1694
4a2fad8f57de Imports: Resolved golint issues unrelated to exported symbols commenting.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1676
diff changeset
347 var faIDs []string
4a2fad8f57de Imports: Resolved golint issues unrelated to exported symbols commenting.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1676
diff changeset
348 var faID int64
2202
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
349 feedback.Info("Found %d fairway availabilities", len(fas))
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
350 for _, faRes := range fas {
2201
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
351 if !bnIds.contains(faRes.Bottleneck_id) {
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
352 feedback.Warn("Bottleneck %s not found in database.", faRes.Bottleneck_id)
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
353 continue
cae0b597aefc Fairway availabilty import: There is no need to fetch the responsibility country from the database. Only the bottleneck_ids are needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2200
diff changeset
354 }
2019
aeff01c6edec Moved fairwayavailability to a local model.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2016
diff changeset
355 uniqueFa := uniqueFairwayAvailability{
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
356 BottleneckId: faRes.Bottleneck_id,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
357 Surdat: faRes.SURDAT,
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
358 }
1756
295c82c5bc3e Fairway availability import: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1755
diff changeset
359 var found bool
295c82c5bc3e Fairway availability import: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1755
diff changeset
360 if faID, found = fairwayAvailabilities[uniqueFa]; !found {
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
361 err = insertFAStmt.QueryRowContext(
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
362 ctx,
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
363 faRes.POSITION,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
364 faRes.Bottleneck_id,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
365 faRes.SURDAT,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
366 faRes.Critical,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
367 faRes.Date_Info,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
368 faRes.Source,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
369 ).Scan(&faID)
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
370 if err != nil {
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
371 return nil, err
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
372 }
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
373 fairwayAvailabilities[uniqueFa] = faID
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
374 }
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
375 feedback.Info("Processing for Bottleneck %s", faRes.Bottleneck_id)
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
376 faIDs = append(faIDs, faRes.Bottleneck_id)
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
377 if faRes.Bottleneck_PDFs != nil {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
378 bnPdfCount := 0
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
379 for _, bnPdfs := range faRes.Bottleneck_PDFs.PdfInfo {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
380 res, err := insertBnPdfsStmt.ExecContext(
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
381 ctx,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
382 faID,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
383 bnPdfs.ProfilePdfFilename,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
384 bnPdfs.ProfilePdfURL,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
385 bnPdfs.PDF_Generation_Date,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
386 bnPdfs.Source,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
387 )
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
388 if err != nil {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
389 return nil, err
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
390 }
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
391 affected, err := res.RowsAffected()
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
392 if err == nil {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
393 bnPdfCount += int(affected)
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
394 } else {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
395 bnPdfCount++
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
396 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
397 }
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
398 feedback.Info("Add %d Pdfs", bnPdfCount)
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
399 }
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
400 if faRes.Effective_fairway_availability != nil {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
401 efaCount := 0
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
402 for _, efa := range faRes.Effective_fairway_availability.EffectiveFairwayAvailability {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
403 los := efa.Level_of_Service
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
404 fgt := efa.Forecast_generation_time
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
405 if efa.Forecast_generation_time.Status == pgtype.Undefined {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
406 fgt = pgtype.Timestamp{
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
407 Status: pgtype.Null,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
408 }
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
409 }
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
410 res, err := insertEFAStmt.ExecContext(
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
411 ctx,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
412 faID,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
413 efa.Measure_date,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
414 string(*los),
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
415 efa.Available_depth_value,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
416 efa.Available_width_value,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
417 efa.Water_level_value,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
418 efa.Measure_type,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
419 efa.Source,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
420 fgt.Get(),
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
421 efa.Value_lifetime,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
422 )
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
423 if err != nil {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
424 return nil, err
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
425 }
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
426 affected, err := res.RowsAffected()
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
427 if err == nil {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
428 efaCount += int(affected)
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
429 } else {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
430 efaCount++
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
431 }
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
432 }
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
433 feedback.Info("Add %d Effective Fairway Availability", efaCount)
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
434 }
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
435
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
436 if faRes.Reference_values != nil {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
437 rvCount := 0
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
438 for _, fav := range faRes.Reference_values.ReferenceValue {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
439 res, err := insertFAVStmt.ExecContext(
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
440 ctx,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
441 faID,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
442 fav.Level_of_Service,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
443 fav.Fairway_depth,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
444 fav.Fairway_width,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
445 fav.Fairway_radius,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
446 fav.Shallowest_spot_Lat,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
447 fav.Shallowest_spot_Lon,
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
448 )
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
449 if err != nil {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
450 return nil, err
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
451 }
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
452 affected, err := res.RowsAffected()
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
453 if err == nil {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
454 rvCount += int(affected)
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
455 } else {
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
456 rvCount++
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
457 }
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
458 }
1755
d3fe20a13339 Import: Filter fairway availabilities by period and resolve insert confilcts.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1754
diff changeset
459 feedback.Info("Add %d Reference Values", rvCount)
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
460 }
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
461 }
1694
4a2fad8f57de Imports: Resolved golint issues unrelated to exported symbols commenting.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1676
diff changeset
462 return faIDs, nil
1662
d8ca44615bfc Implemented first version of fairway availability import.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
463 }
2202
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
464
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
465 // Do executes the actual fairway availability import.
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
466 func (fa *FairwayAvailability) Do(
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
467 ctx context.Context,
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
468 importID int64,
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
469 conn *sql.Conn,
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
470 feedback Feedback,
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
471 ) (interface{}, error) {
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
472
2203
8d1a945d0c3b Uploaded fairway availabilty import: Implemented in terms of normal fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2202
diff changeset
473 fetch := func(
8d1a945d0c3b Uploaded fairway availabilty import: Implemented in terms of normal fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2202
diff changeset
474 ctx context.Context,
8d1a945d0c3b Uploaded fairway availabilty import: Implemented in terms of normal fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2202
diff changeset
475 tx *sql.Tx, bns bottlenecks,
8d1a945d0c3b Uploaded fairway availabilty import: Implemented in terms of normal fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2202
diff changeset
476 ) ([]*ifaf.FairwayAvailability, error) {
2202
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
477
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
478 latest, err := latestDate(ctx, tx)
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
479 if err != nil {
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
480 return nil, err
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
481 }
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
482
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
483 client := ifaf.NewFairwayAvailabilityService(fa.URL, fa.Insecure, nil)
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
484
2253
cfc523c70e90 Uploaded imports: Small code clean-ups.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2233
diff changeset
485 period := ifaf.RequestedPeriod{
cfc523c70e90 Uploaded imports: Small code clean-ups.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2233
diff changeset
486 Date_start: latest.Time,
cfc523c70e90 Uploaded imports: Small code clean-ups.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2233
diff changeset
487 Date_end: time.Now(),
cfc523c70e90 Uploaded imports: Small code clean-ups.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2233
diff changeset
488 }
2202
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
489
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
490 ids := ifaf.ArrayOfString{String: bns}
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
491
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
492 req := &ifaf.Get_bottleneck_fa{
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
493 Bottleneck_id: &ids,
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
494 Period: &period,
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
495 }
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
496 resp, err := client.Get_bottleneck_fa(req)
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
497 if err != nil {
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
498 return nil, err
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
499 }
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
500
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
501 if resp.Get_bottleneck_faResult == nil {
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
502 return nil, errors.New("no fairway availabilities found")
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
503 }
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
504
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
505 result := resp.Get_bottleneck_faResult
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
506 return result.FairwayAvailability, nil
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
507 }
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
508
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
509 return storeFairwayAvailability(ctx, conn, feedback, fetch)
0aee7d4954ae Fairway availabilty import: Re-factored to be the base for the uploaded fairway availabilty import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2201
diff changeset
510 }