comparison pkg/imports/sr.go @ 978:544a5cfe07cd

Started with endpoint for uploading sounding result and trigger respective import job.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 18 Oct 2018 18:37:19 +0200
parents 4a2ca0e20006
children 7934b5c1a910
comparison
equal deleted inserted replaced
977:4a2ca0e20006 978:544a5cfe07cd
12 "fmt" 12 "fmt"
13 "io" 13 "io"
14 "log" 14 "log"
15 "os" 15 "os"
16 "path" 16 "path"
17 "path/filepath"
17 "strconv" 18 "strconv"
18 "strings" 19 "strings"
19 "time" 20 "time"
20 21
21 shp "github.com/jonas-p/go-shp" 22 shp "github.com/jonas-p/go-shp"
23 "gemma.intevation.de/gemma/pkg/octree" 24 "gemma.intevation.de/gemma/pkg/octree"
24 ) 25 )
25 26
26 type SoundingResult struct { 27 type SoundingResult struct {
27 who string 28 who string
28 zip string 29 dir string
29 } 30 }
30 31
31 const SoundingResultDateFormat = "2006-01-02" 32 const SoundingResultDateFormat = "2006-01-02"
32 33
33 type ( 34 type (
130 func (sr *SoundingResult) Who() string { 131 func (sr *SoundingResult) Who() string {
131 return sr.who 132 return sr.who
132 } 133 }
133 134
134 func (sr *SoundingResult) CleanUp() error { 135 func (sr *SoundingResult) CleanUp() error {
135 return os.RemoveAll(sr.zip) 136 return os.RemoveAll(sr.dir)
136 } 137 }
137 138
138 func find(needle string, haystack []*zip.File) *zip.File { 139 func find(needle string, haystack []*zip.File) *zip.File {
139 needle = strings.ToLower(needle) 140 needle = strings.ToLower(needle)
140 for _, straw := range haystack { 141 for _, straw := range haystack {
273 return shapeToPolygon(s) 274 return shapeToPolygon(s)
274 } 275 }
275 276
276 func (sr *SoundingResult) Do(conn *sql.Conn) error { 277 func (sr *SoundingResult) Do(conn *sql.Conn) error {
277 278
278 z, err := zip.OpenReader(sr.zip) 279 z, err := zip.OpenReader(filepath.Join(sr.dir, "sr.zip"))
279 if err != nil { 280 if err != nil {
280 return err 281 return err
281 } 282 }
282 defer z.Close() 283 defer z.Close()
283 284