diff --git a/src/vstp/actions.go b/src/vstp/actions.go index 79759f2..15369e4 100644 --- a/src/vstp/actions.go +++ b/src/vstp/actions.go @@ -1,6 +1,8 @@ package vstp import ( + "fmt" + "git.fjla.uk/owlboard/go-types/pkg/database" "git.fjla.uk/owlboard/mq-client/log" ) @@ -23,4 +25,5 @@ func createEntry(entry database.Service) { func deleteEntry(entry database.Service) { log.Msg.Info("Entry DELETE requested for: " + entry.TrainUid + " - " + entry.Headcode) + fmt.Printf("%+v\n", entry) } diff --git a/src/vstp/parser.go b/src/vstp/parser.go index fcb52a8..04bd89e 100644 --- a/src/vstp/parser.go +++ b/src/vstp/parser.go @@ -25,10 +25,8 @@ func unmarshalData(jsonData string) database.Service { if schedule.Data.CIFMsg.ScheduleSegment == nil { log.Msg.Warn("ScheduleSegment is nil") - return database.Service{} } else if len(schedule.Data.CIFMsg.ScheduleSegment) == 0 { log.Msg.Warn("ScheduleSegment is empty") - return database.Service{} } saveToFile(schedule, "unmarshalled") // For Debugging Only return formatData(&schedule.Data.CIFMsg) @@ -38,19 +36,32 @@ func unmarshalData(jsonData string) database.Service { func formatData(dataInput *upstreamApi.Schedule) database.Service { log.Msg.Debug("ScheduleSegment length: " + fmt.Sprint(len(dataInput.ScheduleSegment))) log.Msg.Debug("Printing dataInput to console:") + + var operator, headcode, powerType string + var planSpeed int32 + var stops []database.Stop + + // Check that the ScheduleSegment contains data, 'Delete' messages have no ScheduleSegment + if len(dataInput.ScheduleSegment) > 0 { + operator = dataInput.ScheduleSegment[0].ATOCCode + headcode = dataInput.ScheduleSegment[0].SignallingID + powerType = dataInput.ScheduleSegment[0].CIFPowerType + planSpeed = parseSpeed(dataInput.ScheduleSegment[0].CIFSpeed) + stops = parseStops(dataInput.ScheduleSegment[0].ScheduleLocation) + } service := database.Service{ TransactionType: dataInput.TransactionType, StpIndicator: dataInput.CIFSTPIndicator, Vstp: true, - Operator: dataInput.ScheduleSegment[0].ATOCCode, + Operator: operator, TrainUid: dataInput.CIFTrainUID, - Headcode: dataInput.ScheduleSegment[0].SignallingID, - PowerType: dataInput.ScheduleSegment[0].CIFPowerType, - PlanSpeed: parseSpeed(dataInput.ScheduleSegment[0].CIFSpeed), + Headcode: headcode, + PowerType: powerType, + PlanSpeed: planSpeed, ScheduleStartDate: parseDate(dataInput.ScheduleStartDate, false), ScheduleEndDate: parseDate(dataInput.ScheduleEndDate, true), DaysRun: parseDaysRun(dataInput.ScheduleDaysRun), - Stops: parseStops(dataInput.ScheduleSegment[0].ScheduleLocation), + Stops: stops, } return service }