generated from noi-techpark/java-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Implemented configurable Operators (for Parking)
- Parking map new metadatafields
- Loading branch information
Showing
9 changed files
with
176 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ Upstream-Contact: NOI Techpark <[email protected]> | |
Source: https://github.com/noi-techpark/sta-nap-export | ||
|
||
Files: .github/* infrastructure .gitignore .gitmodules .pre-commit-config.yaml LICENSE.md .env.example mvnw mvnw.cmd .mvn/* | ||
*.properties src/main/resources/db/migration/* src/go.mod src/go.sum calls.http | ||
*.properties src/main/resources/db/migration/* src/go.mod src/go.sum calls.http src/resources/*.csv | ||
Copyright: (c) NOI Techpark <[email protected]> | ||
License: CC0-1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// SPDX-FileCopyrightText: 2024 NOI Techpark <[email protected]> | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
package netex | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
|
||
"github.com/gocarina/gocsv" | ||
) | ||
|
||
type operatorCfg struct { | ||
Origin string `csv:"origin"` | ||
Email string `csv:"email"` | ||
Phone string `csv:"phone"` | ||
Url string `csv:"url"` | ||
Street string `csv:"street"` | ||
Town string `csv:"town"` | ||
Postcode string `csv:"postcode"` | ||
Country string `csv:"country"` | ||
} | ||
|
||
func readOps(path string) []operatorCfg { | ||
f, err := os.Open(path) | ||
if err != nil { | ||
wd, _ := os.Getwd() | ||
log.Panicln("Cannot open Operators csv.", wd, err) | ||
} | ||
defer f.Close() | ||
|
||
ops := []operatorCfg{} | ||
if err := gocsv.UnmarshalFile(f, &ops); err != nil { | ||
log.Panic("Cannot unmarshal Operators csv", err) | ||
} | ||
return ops | ||
} | ||
|
||
var ops []operatorCfg | ||
|
||
func getCsvPath() string { | ||
// https://stackoverflow.com/questions/31873396/is-it-possible-to-get-the-current-root-of-package-structure-as-a-string-in-golan | ||
// Relative paths are a pain in the butt because unit tests always execute from the directory they are in | ||
// This is a hack to always start from root folder and compose the full "absolute" path | ||
|
||
_, b, _, _ := runtime.Caller(0) | ||
root := filepath.Join(filepath.Dir(b), "../..") | ||
return filepath.Join(root, "src", "resources", "operators.csv") | ||
} | ||
|
||
func mapByOrigin(p []operatorCfg) map[string]operatorCfg { | ||
ret := make(map[string]operatorCfg) | ||
for _, o := range p { | ||
ret[o.Origin] = o | ||
} | ||
return ret | ||
} | ||
func opsByOrigin() map[string]operatorCfg { | ||
if ops == nil { | ||
ops = readOps(getCsvPath()) | ||
} | ||
return mapByOrigin(ops) | ||
} | ||
|
||
func GetOperator(id string) Operator { | ||
cfg, found := opsByOrigin()[id] | ||
if !found { | ||
log.Panic("Unable to map operator. Probably got some origin that we shouldn't have?") | ||
} | ||
|
||
o := Operator{} | ||
o.Id = CreateID("Operator", id) | ||
o.Version = "1" | ||
o.PrivateCode = id | ||
o.Name = id | ||
o.ShortName = id | ||
o.LegalName = id | ||
o.TradingName = id | ||
o.ContactDetails.Email = cfg.Email | ||
o.ContactDetails.Phone = cfg.Phone | ||
o.ContactDetails.Url = cfg.Url | ||
o.OrganisationType = "operator" | ||
o.Address.Id = CreateID("Address", id) | ||
o.Address.CountryName = cfg.Country | ||
o.Address.Street = cfg.Street | ||
o.Address.Town = cfg.Town | ||
o.Address.PostCode = cfg.Postcode | ||
return o | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-FileCopyrightText: 2024 NOI Techpark <[email protected]> | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
package netex | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestReadOps(t *testing.T) { | ||
ops := readOps(getCsvPath()) | ||
if len(ops) == 0 { | ||
t.Log("Operators loaded empty") | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestOpsContent(t *testing.T) { | ||
ops := readOps(getCsvPath()) | ||
mapped := mapByOrigin(ops) | ||
|
||
bsb := mapped["BIKE_SHARING_BOLZANO"] | ||
assert.Equal(t, "[email protected]", bsb.Email) | ||
assert.Equal(t, "0471997111", bsb.Phone) | ||
|
||
hal := mapped["HAL-API"] | ||
assert.Equal(t, "https://www.carsharing.bz.it/it/", hal.Url) | ||
assert.Equal(t, "Via Beda Weber 1", hal.Street) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
origin,email,phone,url,street,town,postcode,country | ||
BIKE_SHARING_BOLZANO,[email protected],0471997111,https://opencity.comune.bolzano.it/Servizi/Bike-Sharing-Bici-Bolzano,Vicolo Gumer 7,Bolzano,39100,Italy | ||
BIKE_SHARING_MERANO,[email protected],0473250111,https://www.comune.merano.bz.it/it/Bikesharing,Via Portici 192,Merano,39012,Italy | ||
BIKE_SHARING_PAPIN,[email protected],0474913450,https://www.papinsport.com/rent-a-bike/,Via Freising 9,San Candido,39038,Italy | ||
HAL-API,[email protected],0471061319,https://www.carsharing.bz.it/it/,Via Beda Weber 1,Bolzano,39100,Italy | ||
FAMAS,[email protected],0471997111,https://opencity.comune.bolzano.it/Documenti-e-dati/Documenti-tecnici-di-supporto/Parcheggiare-in-citta,Vicolo Gumer 7,Bolzano,39100,Italy | ||
Municipality Merano,[email protected],0473250111,https://www.comune.merano.bz.it/it/Parcheggi,Via Portici 192,Merano,39012,Italy | ||
FBK-Trento,[email protected],0461884111,https://www.comune.trento.it/Citta/Come-orientarsi/Parcheggi,Via Belenzani 19,Trento,38122,Italy | ||
FBK-Rovereto,[email protected],0464452111,https://www.comune.rovereto.tn.it/Servizi/Sosta-e-parcheggi,Piazza Podestà 11,Rovereto,38068,Italy | ||
A22,[email protected],0461212611,https://www.autobrennero.it/it/in-viaggio/sosta-e-servizi/aree-di-servizio/,Via Berlino 10,Trento,38121,Italy | ||
skidata,[email protected],0471312888,https://www.sta.bz.it,Via dei Conciapelli 60,Bolzano,39100,Italy | ||
bicincitta,[email protected],0471312888,https://www.sta.bz.it,Via dei Conciapelli 60,Bolzano,39100,Italy |