/
processSchedule.go
61 lines (51 loc) · 1.41 KB
/
processSchedule.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package darwind3
// Process processes an inbound schedule importing or merging it with the
// current schedule in the database
func (p *Schedule) Process(tx *Transaction) error {
// Only look at an existing entry for uR messages. sR messages must replace the existing one
if !tx.pport.SnapshotUpdate {
old := tx.d3.GetSchedule(p.RID)
if old != nil {
// If they are completely the same or the old entry is newer than the new one
// then do nothing
if p.Equals(old) || tx.pport.TS.Before(old.Date) {
// They are identical so bail out
return nil
}
// Use the new entry but merge in the locations from the old one so we keep
// any forecasts
ary := p.Locations
// Run through old locations, any that match the new ones preserve the forecast
for _, b := range old.Locations {
for _, a := range ary {
if a.EqualInSchedule(b) {
a.Forecast = b.Forecast
}
}
}
// Append any old locations not in the new one - we'll never remove a Location
for _, b := range old.Locations {
f := true
for _, a := range ary {
if a.EqualInSchedule(b) {
f = false
}
}
if f {
ary = append(ary, b)
}
}
p.Locations = ary
}
}
tx.d3.UpdateAssociations(p)
p.Date = tx.pport.TS
p.Sort()
tx.d3.PutSchedule(p)
tx.d3.EventManager.PostEvent(&DarwinEvent{
Type: Event_ScheduleUpdated,
RID: p.RID,
Schedule: p,
})
return nil
}