Mercurial > gemma
annotate pkg/controllers/uploadedimports.go @ 2561:4d5f419a2318
client:pdf-gen: improve box drawing
* handle the case when the rectangle is not rounded (rounding=0)
author | Fadi Abbud <fadi.abbud@intevation.de> |
---|---|
date | Fri, 08 Mar 2019 16:49:40 +0100 |
parents | 07f892bc4bb0 |
children | ce39e9954e85 |
rev | line source |
---|---|
2256
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package controllers |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
2537
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
17 "fmt" |
2256
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "log" |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "net/http" |
2536
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
20 "os" |
2537
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
21 "strconv" |
2256
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "time" |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 "gemma.intevation.de/gemma/pkg/auth" |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 "gemma.intevation.de/gemma/pkg/common" |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 "gemma.intevation.de/gemma/pkg/imports" |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 "gemma.intevation.de/gemma/pkg/misc" |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 ) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 const maxUploadSize = 25 * 1024 * 1024 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
2536
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
32 type BadUploadParameterError string |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
33 |
2537
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
34 func importWaterwayProfiles() http.HandlerFunc { |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
35 return uploadedImport( |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
36 imports.WPJobKind, |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
37 "wp.csv", |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
38 func(req *http.Request, dir string) (imports.Job, error) { |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
39 url := req.FormValue("url") |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
40 if url == "" { |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
41 return nil, BadUploadParameterError("missing 'url' parameter") |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
42 } |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
43 |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
44 featureType := req.FormValue("feature-type") |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
45 if featureType == "" { |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
46 return nil, BadUploadParameterError("missing 'feature-type' parameter") |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
47 } |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
48 |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
49 sortBy := req.FormValue("sort-by") |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
50 |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
51 var precision *float64 |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
52 if p := req.FormValue("precision"); p != "" { |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
53 v, err := strconv.ParseFloat(p, 64) |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
54 if err != nil { |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
55 return nil, BadUploadParameterError( |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
56 fmt.Sprintf("Invalid 'precision' parameter: %v", err)) |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
57 } |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
58 precision = &v |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
59 } |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
60 |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
61 return &imports.WaterwayProfiles{ |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
62 Dir: dir, |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
63 URL: url, |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
64 FeatureType: featureType, |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
65 SortBy: sortBy, |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
66 Precision: precision, |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
67 }, nil |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
68 }, |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
69 ) |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
70 } |
07f892bc4bb0
WP import: Made WP import an uploaded import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2536
diff
changeset
|
71 |
2256
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 func importApprovedGaugeMeasurements() http.HandlerFunc { |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 return uploadedImport( |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 imports.AGMJobKind, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 "agm.csv", |
2536
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
76 func(_ *http.Request, dir string) (imports.Job, error) { |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
77 return &imports.ApprovedGaugeMeasurements{Dir: dir}, nil |
2256
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 }, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 ) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 } |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 func importUploadedBottleneck() http.HandlerFunc { |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 return uploadedImport( |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 imports.UBNJobKind, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 "data.xml", |
2536
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
86 func(_ *http.Request, dir string) (imports.Job, error) { |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
87 return &imports.UploadedBottleneck{Dir: dir}, nil |
2256
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 }, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 ) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 } |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 func importUploadedFairwayAvailability() http.HandlerFunc { |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 return uploadedImport( |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 imports.UFAJobKind, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 "data.xml", |
2536
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
96 func(_ *http.Request, dir string) (imports.Job, error) { |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
97 return &imports.UploadedFairwayAvailability{Dir: dir}, nil |
2256
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 }, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 ) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 } |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 func importUploadedGaugeMeasurement() http.HandlerFunc { |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 return uploadedImport( |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 imports.UGMJobKind, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 "data.xml", |
2536
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
106 func(_ *http.Request, dir string) (imports.Job, error) { |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
107 return &imports.UploadedGaugeMeasurement{Dir: dir}, nil |
2256
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 }, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 ) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 } |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 |
2536
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
112 func (bup BadUploadParameterError) Error() string { |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
113 return string(bup) |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
114 } |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
115 |
2256
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 func uploadedImport( |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 kind imports.JobKind, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 fname string, |
2536
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
119 create func(*http.Request, string) (imports.Job, error), |
2256
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 ) http.HandlerFunc { |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 return func(rw http.ResponseWriter, req *http.Request) { |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 dir, err := misc.StoreUploadedFile( |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 req, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 string(kind), |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 fname, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 maxUploadSize) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 if err != nil { |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 log.Printf("error: %v\n", err) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 http.Error(rw, "error: "+err.Error(), http.StatusInternalServerError) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 return |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 } |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 |
2536
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
134 job, err := create(req, dir) |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
135 if err != nil { |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
136 if err2 := os.RemoveAll(dir); err2 != nil { |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
137 log.Printf("warn: %v\n", err2) |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
138 } |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
139 if err2, ok := err.(BadUploadParameterError); ok { |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
140 http.Error(rw, string(err2), http.StatusBadRequest) |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
141 return |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
142 } |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
143 log.Printf("error: %v\n", err) |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
144 http.Error(rw, "error: "+err.Error(), http.StatusInternalServerError) |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
145 return |
0a3debcfbe8f
Upload imports: Increased power of upload imports to be able to cope parameterized imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2256
diff
changeset
|
146 } |
2256
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 serialized, err := common.ToJSONString(job) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 if err != nil { |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 log.Printf("error: %v\n", err) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 http.Error(rw, "error: "+err.Error(), http.StatusInternalServerError) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 return |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 } |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 session, _ := auth.GetSession(req) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 sendEmail := req.FormValue("email") != "" |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 jobID, err := imports.AddJob( |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 kind, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 time.Time{}, // due |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 nil, // trys |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 nil, // retry wait |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 session.User, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 sendEmail, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 serialized) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 if err != nil { |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 log.Printf("error: %v\n", err) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 http.Error(rw, "error: "+err.Error(), http.StatusInternalServerError) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 return |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 } |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 log.Printf("info: added import #%d to queue\n", jobID) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 result := struct { |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 ID int64 `json:"id"` |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 }{ |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 ID: jobID, |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 } |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 SendJSON(rw, http.StatusCreated, &result) |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 } |
0d272d7bcfb9
Uploaded imports: Unified agm, ubn, ufa and ugm import endpoints and removed a lot c&p code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 } |