Mercurial > gemma
view pkg/controllers/manualimports.go @ 1840:e3311c18a8e3
Translated using Weblate (Romanian)
Currently translated at 5.7% (7 of 123 strings)
Translation: Gemma/client
Translate-URL: https://hosted.weblate.org/projects/gemma/client/ro/
author | Fadi Abbud <fadi.abbud@intevation.de> |
---|---|
date | Thu, 17 Jan 2019 11:19:15 +0000 |
parents | 614c6c766691 |
children | 77582da3adb0 |
line wrap: on
line source
// This is Free Software under GNU Affero General Public License v >= 3.0 // without warranty, see README.md and license for details. // // SPDX-License-Identifier: AGPL-3.0-or-later // License-Filename: LICENSES/AGPL-3.0.txt // // Copyright (C) 2018 by via donau // – Österreichische Wasserstraßen-Gesellschaft mbH // Software engineering by Intevation GmbH // // Author(s): // * Sascha L. Teichmann <sascha.teichmann@intevation.de> // * Raimund Renkert <raimund.renkert@intevation.de> package controllers import ( "database/sql" "log" "net/http" "time" "gemma.intevation.de/gemma/pkg/auth" "gemma.intevation.de/gemma/pkg/common" "gemma.intevation.de/gemma/pkg/imports" "gemma.intevation.de/gemma/pkg/models" ) func retry(a common.Attributes) (time.Time, int) { due, _ := a.Time("due") retries, ok := a.Int("retries") if !ok { retries = -1 } return due, retries } func importBottleneck(input interface{}) (interface{}, time.Time, int, bool) { bi := input.(*models.BottleneckImport) bn := &imports.Bottleneck{ URL: bi.URL, Insecure: bi.Insecure, } due, retries := retry(bi.Attributes) return bn, due, retries, bi.SendEmail } func importGaugeMeasurement(input interface{}) (interface{}, time.Time, int, bool) { gi := input.(*models.GaugeMeasurementImport) gm := &imports.GaugeMeasurement{ URL: gi.URL, Insecure: gi.Insecure, } due, retries := retry(gi.Attributes) return gm, due, retries, gi.SendEmail } func importFairwayAvailability(input interface{}) (interface{}, time.Time, int, bool) { fai := input.(*models.FairwayAvailabilityImport) fa := &imports.FairwayAvailability{ URL: fai.URL, Insecure: fai.Insecure, } due, retries := retry(fai.Attributes) return fa, due, retries, fai.SendEmail } func importWaterwayAxis(input interface{}) (interface{}, time.Time, int, bool) { wxi := input.(*models.WaterwayAxisImport) wx := &imports.WaterwayAxis{ URL: wxi.URL, FeatureType: wxi.FeatureType, SortBy: wxi.SortBy, } due, retries := retry(wxi.Attributes) return wx, due, retries, wxi.SendEmail } func importWaterwayArea(input interface{}) (interface{}, time.Time, int, bool) { wai := input.(*models.WaterwayAreaImport) wa := &imports.WaterwayArea{ URL: wai.URL, FeatureType: wai.FeatureType, SortBy: wai.SortBy, } due, retries := retry(wai.Attributes) return wa, due, retries, wai.SendEmail } func manualImport( kind imports.JobKind, setup func(interface{}) (interface{}, time.Time, int, bool), ) func(interface{}, *http.Request, *sql.Conn) (JSONResult, error) { return func(input interface{}, req *http.Request, _ *sql.Conn) ( jr JSONResult, err error) { what, due, retries, sendEmail := setup(input) var serialized string if serialized, err = common.ToJSONString(what); err != nil { return } session, _ := auth.GetSession(req) var jobID int64 if jobID, err = imports.AddJob( kind, due, retries, session.User, sendEmail, serialized, ); err != nil { return } log.Printf("info: added import #%d to queue\n", jobID) result := struct { ID int64 `json:"id"` }{ ID: jobID, } jr = JSONResult{ Code: http.StatusCreated, Result: &result, } return } }