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.
extract netex model as external dependency
- Loading branch information
Showing
19 changed files
with
245 additions
and
694 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 |
---|---|---|
@@ -1,27 +1,29 @@ | ||
// SPDX-FileCopyrightText: NOI Techpark <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
package netex | ||
package comp | ||
|
||
import "github.com/noi-techpark/go-netex" | ||
|
||
type StFlightData struct { | ||
Operators []Operator | ||
StopPlaces []StopPlace | ||
ServiceCalendars []ServiceCalendar | ||
Routes []Route | ||
Lines []Line | ||
ScheduledStopPoints []ScheduledStopPoint | ||
ServiceLinks []ServiceLink | ||
StopAssignments []PassengerStopAssignment | ||
JourneyPatterns []ServiceJourneyPattern | ||
VehicleJourneys []ServiceJourney | ||
Operators []netex.Operator | ||
StopPlaces []netex.StopPlace | ||
ServiceCalendars []netex.ServiceCalendar | ||
Routes []netex.Route | ||
Lines []netex.Line | ||
ScheduledStopPoints []netex.ScheduledStopPoint | ||
ServiceLinks []netex.ServiceLink | ||
StopAssignments []netex.PassengerStopAssignment | ||
JourneyPatterns []netex.ServiceJourneyPattern | ||
VehicleJourneys []netex.ServiceJourney | ||
} | ||
|
||
type StFlights interface { | ||
StFlights() (StFlightData, error) | ||
} | ||
|
||
func GetFlights(ps []StFlights) ([]CompositeFrame, error) { | ||
ret := []CompositeFrame{} | ||
func GetFlights(ps []StFlights) ([]netex.CompositeFrame, error) { | ||
ret := []netex.CompositeFrame{} | ||
|
||
apd := StFlightData{} | ||
|
||
|
@@ -47,24 +49,23 @@ func GetFlights(ps []StFlights) ([]CompositeFrame, error) { | |
return ret, nil | ||
} | ||
|
||
func compFlights(pd StFlightData) CompositeFrame { | ||
var ret CompositeFrame | ||
ret.Defaults() | ||
func compFlights(pd StFlightData) netex.CompositeFrame { | ||
ret := DefaultCompositFrame() | ||
ret.Id = CreateFrameId("CompositeFrame_EU_PI_STOP_OFFER", "FLIGHTS", "ita") | ||
ret.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_LINE_OFFER") | ||
|
||
site := siteFrame() | ||
site.StopPlaces = pd.StopPlaces | ||
ret.Frames.Frames = append(ret.Frames.Frames, &site) | ||
|
||
res := ResourceFrame{} | ||
res := netex.ResourceFrame{} | ||
res.Id = CreateFrameId("ResourceFrame_EU_PI_MOBILITY", "ita") | ||
res.Version = "1" | ||
res.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_COMMON") | ||
res.Operators = &pd.Operators | ||
ret.Frames.Frames = append(ret.Frames.Frames, &res) | ||
|
||
ser := ServiceFrame{} | ||
ser := netex.ServiceFrame{} | ||
ser.Id = CreateFrameId("ServiceFrame_EU_PI_NETWORK", "ita") | ||
ser.Version = "1" | ||
ser.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_NETWORK") | ||
|
@@ -76,14 +77,14 @@ func compFlights(pd StFlightData) CompositeFrame { | |
ser.StopAssignments = append(ser.StopAssignments, pd.StopAssignments...) | ||
ret.Frames.Frames = append(ret.Frames.Frames, ser) | ||
|
||
cal := ServiceCalendarFrame{} | ||
cal := netex.ServiceCalendarFrame{} | ||
cal.Id = CreateFrameId("ServiceCalendarFrame_EU_PI_CALENDAR", "ita") | ||
cal.Version = "1" | ||
cal.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_CALENDAR") | ||
cal.ServiceCalendar = append(cal.ServiceCalendar, pd.ServiceCalendars...) | ||
ret.Frames.Frames = append(ret.Frames.Frames, cal) | ||
|
||
tim := TimetableFrame{} | ||
tim := netex.TimetableFrame{} | ||
tim.Id = CreateFrameId("TimetableFrame_EU_PI_TIMETABLE", "ita") | ||
tim.Version = "1" | ||
tim.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_TIMETABLE") | ||
|
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
// SPDX-FileCopyrightText: NOI Techpark <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
package netex | ||
package comp | ||
|
||
import ( | ||
"regexp" | ||
"time" | ||
|
||
"github.com/noi-techpark/go-netex" | ||
) | ||
|
||
// As per NeTEx spec, IDs must only contain non-accented charaters, numbers, hyphens and underscores | ||
|
@@ -23,25 +25,27 @@ func CreateFrameId(segments ...string) string { | |
return "edp:" + CreateID(segments...) | ||
} | ||
|
||
func MkRef(tp string, id string) Ref { | ||
r := Ref{} | ||
func MkRef(tp string, id string) netex.Ref { | ||
r := netex.Ref{} | ||
r.Ref = id | ||
r.Version = "1" | ||
r.XMLName.Local = tp + "Ref" | ||
return r | ||
} | ||
|
||
func MkTypeOfFrameRef(tp string) Ref { | ||
r := Ref{} | ||
func MkTypeOfFrameRef(tp string) netex.Ref { | ||
r := netex.Ref{} | ||
r.Ref = "epip:" + tp | ||
r.Version = "1" | ||
r.XMLName.Local = "TypeOfFrameRef" | ||
return r | ||
} | ||
|
||
func (v *ValidBetween) AYear() { | ||
func ValidAYear() netex.ValidBetween { | ||
v := netex.ValidBetween{} | ||
v.FromDate = time.Now().Truncate(time.Hour * 24) | ||
v.ToDate = time.Now().AddDate(1, 0, 0).Truncate(time.Hour * 24) | ||
return v | ||
} | ||
|
||
func AppendSafe[T any](h *[]T, t ...T) *[]T { | ||
|
@@ -54,3 +58,15 @@ func AppendSafe[T any](h *[]T, t ...T) *[]T { | |
} | ||
return h | ||
} | ||
|
||
func DefaultCompositFrame() netex.CompositeFrame { | ||
c := netex.CompositeFrame{} | ||
c.Version = "1" | ||
c.ValidBetween = ValidAYear() | ||
c.Codespaces.Codespace.Id = "ita" | ||
c.Codespaces.Codespace.Xmlns = "ita" | ||
c.Codespaces.Codespace.XmlnsUrl = "http://www.ita.it" | ||
c.Codespaces.Codespace.Description = "Italian Profile" | ||
c.FrameDefaults.DefaultCodespaceRef.Ref = "ita" | ||
return c | ||
} |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
// SPDX-FileCopyrightText: NOI Techpark <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
package netex | ||
package comp | ||
|
||
import "github.com/noi-techpark/go-netex" | ||
|
||
type OdhEcharging struct { | ||
Scode string | ||
|
@@ -18,16 +20,15 @@ type OdhEcharging struct { | |
} | ||
} | ||
|
||
func compFrame(pd StParkingData) CompositeFrame { | ||
var ret CompositeFrame | ||
ret.Defaults() | ||
func compFrame(pd StParkingData) netex.CompositeFrame { | ||
ret := DefaultCompositFrame() | ||
ret.Id = CreateFrameId("CompositeFrame_EU_PI_STOP_OFFER", "PARKING", "ita") | ||
ret.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_LINE_OFFER") | ||
|
||
site := siteFrame() | ||
ret.Frames.Frames = append(ret.Frames.Frames, &site) | ||
|
||
res := ResourceFrame{} | ||
res := netex.ResourceFrame{} | ||
res.Id = CreateFrameId("ResourceFrame_EU_PI_MOBILITY", "ita") | ||
res.Version = "1" | ||
res.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_COMMON") | ||
|
@@ -40,16 +41,16 @@ func compFrame(pd StParkingData) CompositeFrame { | |
} | ||
|
||
type StParkingData struct { | ||
Parkings []Parking | ||
Operators []Operator | ||
Parkings []netex.Parking | ||
Operators []netex.Operator | ||
} | ||
|
||
type StParking interface { | ||
StParking() (StParkingData, error) | ||
} | ||
|
||
func GetParking(ps []StParking) ([]CompositeFrame, error) { | ||
ret := []CompositeFrame{} | ||
func GetParking(ps []StParking) ([]netex.CompositeFrame, error) { | ||
ret := []netex.CompositeFrame{} | ||
|
||
apd := StParkingData{} | ||
|
||
|
@@ -67,8 +68,8 @@ func GetParking(ps []StParking) ([]CompositeFrame, error) { | |
return ret, nil | ||
} | ||
|
||
func siteFrame() SiteFrame { | ||
var site SiteFrame | ||
func siteFrame() netex.SiteFrame { | ||
var site netex.SiteFrame | ||
site.Id = CreateFrameId("SiteFrame_EU_PI_STOP", "ita") | ||
site.Version = "1" | ||
site.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_STOP") | ||
|
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
// SPDX-FileCopyrightText: NOI Techpark <[email protected]> | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
package netex | ||
package comp | ||
|
||
import ( | ||
"encoding/json" | ||
"log/slog" | ||
|
||
"github.com/noi-techpark/go-netex" | ||
) | ||
|
||
type Company struct { | ||
|
@@ -28,23 +30,23 @@ func (pc *Company) UnmarshalJSON(p []byte) error { | |
} | ||
|
||
type StSharingData struct { | ||
Fleets []Fleet | ||
Vehicles []Vehicle | ||
CarModels []CarModelProfile | ||
CycleModels []CycleModelProfile | ||
Operators []Operator | ||
Modes []VehicleSharing | ||
Services []VehicleSharingService | ||
Constraints []MobilityServiceConstraintZone | ||
Parkings []Parking | ||
Fleets []netex.Fleet | ||
Vehicles []netex.Vehicle | ||
CarModels []netex.CarModelProfile | ||
CycleModels []netex.CycleModelProfile | ||
Operators []netex.Operator | ||
Modes []netex.VehicleSharing | ||
Services []netex.VehicleSharingService | ||
Constraints []netex.MobilityServiceConstraintZone | ||
Parkings []netex.Parking | ||
} | ||
|
||
type StSharing interface { | ||
StSharing() (StSharingData, error) | ||
} | ||
|
||
func GetSharing(bikeProviders []StSharing, carProviders []StSharing) ([]CompositeFrame, error) { | ||
ret := []CompositeFrame{} | ||
func GetSharing(bikeProviders []StSharing, carProviders []StSharing) ([]netex.CompositeFrame, error) { | ||
ret := []netex.CompositeFrame{} | ||
|
||
c, err := compSharing("BikeSharing", bikeProviders) | ||
if err != nil { | ||
|
@@ -60,26 +62,26 @@ func GetSharing(bikeProviders []StSharing, carProviders []StSharing) ([]Composit | |
|
||
return ret, nil | ||
} | ||
func compSharing(serviceName string, ps []StSharing) (CompositeFrame, error) { | ||
mob := MobilityServiceFrame{} | ||
func compSharing(serviceName string, ps []StSharing) (netex.CompositeFrame, error) { | ||
mob := netex.MobilityServiceFrame{} | ||
mob.Id = CreateFrameId("MobilityServiceFrame_EU_PI_MOBILITY", serviceName) | ||
mob.Version = "1" | ||
mob.FrameDefaults.DefaultCurrency = "EUR" | ||
|
||
res := ResourceFrame{} | ||
res := netex.ResourceFrame{} | ||
res.Id = CreateFrameId("ResourceFrame_EU_PI_COMMON", serviceName) | ||
res.Version = "1" | ||
res.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_COMMON") | ||
|
||
site := SiteFrame{} | ||
site := netex.SiteFrame{} | ||
site.Id = CreateFrameId("SiteFrame_EU_PI_STOP", serviceName) | ||
site.Version = "1" | ||
site.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_STOP") | ||
|
||
for _, p := range ps { | ||
d, err := p.StSharing() | ||
if err != nil { | ||
return CompositeFrame{}, err | ||
return netex.CompositeFrame{}, err | ||
} | ||
|
||
mob.Fleets = append(mob.Fleets, d.Fleets...) | ||
|
@@ -95,8 +97,7 @@ func compSharing(serviceName string, ps []StSharing) (CompositeFrame, error) { | |
site.Parkings = append(site.Parkings, d.Parkings...) | ||
} | ||
|
||
comp := CompositeFrame{} | ||
comp.Defaults() | ||
comp := DefaultCompositFrame() | ||
comp.Id = CreateFrameId("CompositeFrame_EU_PI_STOP_OFFER", "SHARING", serviceName) | ||
comp.TypeOfFrameRef = MkTypeOfFrameRef("EU_PI_LINE_OFFER") | ||
comp.Frames.Frames = append(comp.Frames.Frames, mob, res, site) | ||
|
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
Oops, something went wrong.