@@ -38,19 +38,20 @@ public void afterRowWrite() throws IOException {
38
38
39
39
private boolean checkCalendarIds (Set <NewGTFSError > idErrors , FieldContext fieldContext ) throws IOException {
40
40
boolean shouldSkipRecord = false ;
41
+ String key = getTableScopedValue (table , getIdScope (), keyValue );
42
+
41
43
if (isHandlingActiveFeed ()) {
42
44
LocalDate startDate = getCsvDate ("start_date" );
43
- // If a service_id from the active calendar has both the
44
- // start_date and end_date in the future, the service will be
45
- // excluded from the merged file. Records in trips,
46
- // calendar_dates, and calendar_attributes referencing this
47
- // service_id shall also be removed/ignored. Stop_time records
48
- // for the ignored trips shall also be removed.
49
45
if (!startDate .isBefore (feedMergeContext .future .getFeedFirstDate ())) {
46
+ // If a service_id from the active calendar has both the
47
+ // start_date and end_date in the future, the service will be
48
+ // excluded from the merged file. Records in trips,
49
+ // calendar_dates, and calendar_attributes referencing this
50
+ // service_id shall also be removed/ignored. Stop_time records
51
+ // for the ignored trips shall also be removed.
50
52
LOG .warn (
51
- "Skipping calendar entry {} because it operates fully within the time span of future feed." ,
53
+ "Skipping active calendar entry {} because it operates fully within the time span of future feed." ,
52
54
keyValue );
53
- String key = getTableScopedValue (table , getIdScope (), keyValue );
54
55
mergeFeedsResult .skippedIds .add (key );
55
56
shouldSkipRecord = true ;
56
57
} else {
@@ -68,7 +69,7 @@ private boolean checkCalendarIds(Set<NewGTFSError> idErrors, FieldContext fieldC
68
69
boolean activeAndFutureTripIdsAreDisjoint = job .sharedTripIdsWithConsistentSignature .isEmpty ();
69
70
if (activeAndFutureTripIdsAreDisjoint ) {
70
71
futureStartDate = feedMergeContext .futureFirstCalendarStartDate ;
71
- } else if (job .serviceIdsToTerminateEarly .contains (keyValue )) {
72
+ } else if (job .serviceIdsFromActiveFeedToTerminateEarly .contains (keyValue )) {
72
73
futureStartDate = feedMergeContext .future .getFeedFirstDate ();
73
74
}
74
75
// In other cases not covered above, new calendar entry is already flagged for insertion
@@ -85,10 +86,20 @@ private boolean checkCalendarIds(Set<NewGTFSError> idErrors, FieldContext fieldC
85
86
.format (GTFS_DATE_FORMATTER ));
86
87
}
87
88
}
89
+ /* } else {
90
+ // If handling the future feed, the MTC revised feed merge logic is as follows:
91
+ // - Calendar entries from the future feed will be inserted as is in the merged feed.
92
+ // so no additional processing needed here, unless the calendar entry is no longer used.
93
+ if (job.serviceIdsFromFutureFeedToRemove.contains(keyValue)) {
94
+ LOG.warn(
95
+ "Skipping future calendar entry {} because it will become unused in the merged feed.",
96
+ keyValue);
97
+ mergeFeedsResult.skippedIds.add(key);
98
+ shouldSkipRecord = true;
99
+ }
100
+
101
+ */
88
102
}
89
- // If handling the future feed, the MTC revised feed merge logic is as follows:
90
- // - Calendar entries from the future feed will be inserted as is in the merged feed.
91
- // so no additional processing needed here.
92
103
93
104
94
105
// If any service_id in the active feed matches with the future
@@ -98,8 +109,7 @@ private boolean checkCalendarIds(Set<NewGTFSError> idErrors, FieldContext fieldC
98
109
// duplicates? I think we would need to consider the
99
110
// service_id:exception_type:date as the unique key and include any
100
111
// all entries as long as they are unique on this key.
101
-
102
- if (hasDuplicateError (idErrors )) {
112
+ if (isHandlingActiveFeed () && hasDuplicateError (idErrors )) {
103
113
// Modify service_id and ensure that referencing trips
104
114
// have service_id updated.
105
115
updateAndRemapOutput (fieldContext );
@@ -108,7 +118,11 @@ private boolean checkCalendarIds(Set<NewGTFSError> idErrors, FieldContext fieldC
108
118
// Track service ID because we want to avoid removing trips that may reference this
109
119
// service_id when the service_id is used by calendar_dates that operate in the valid
110
120
// date range, i.e., before the future feed's first date.
111
- if (!shouldSkipRecord && fieldContext .nameEquals (SERVICE_ID )) mergeFeedsResult .serviceIds .add (fieldContext .getValueToWrite ());
121
+ //
122
+ // If service is going to be cloned, add to the output service ids.
123
+ if (!shouldSkipRecord && fieldContext .nameEquals (SERVICE_ID )) {
124
+ mergeFeedsResult .serviceIds .add (fieldContext .getValueToWrite ());
125
+ }
112
126
113
127
return !shouldSkipRecord ;
114
128
}
@@ -119,25 +133,27 @@ private boolean checkCalendarIds(Set<NewGTFSError> idErrors, FieldContext fieldC
119
133
* @throws IOException
120
134
*/
121
135
public void addClonedServiceId () throws IOException {
122
- String originalServiceId = getRowValues ()[keyFieldIndex ];
123
- if (job .serviceIdsToCloneRenameAndExtend .contains (originalServiceId )) {
124
- // FIXME: Do we need to worry about calendar_dates?
125
- String [] clonedValues = getRowValues ().clone ();
126
- String newServiceId = clonedValues [keyFieldIndex ] = String .join (":" , getIdScope (), originalServiceId );
127
- // Modify start date only (preserve the end date on the future calendar entry).
128
- int startDateIndex = Table .CALENDAR .getFieldIndex ("start_date" );
129
- clonedValues [startDateIndex ] = feedMergeContext .active .feed .calendars .get (originalServiceId ).start_date
130
- .format (GTFS_DATE_FORMATTER );
131
- referenceTracker .checkReferencesAndUniqueness (
132
- keyValue ,
133
- getLineNumber (),
134
- table .fields [0 ],
135
- newServiceId ,
136
- table ,
137
- keyField ,
138
- table .getOrderFieldName ()
139
- );
140
- writeValuesToTable (clonedValues , true );
136
+ if (isHandlingFutureFeed ()) {
137
+ String originalServiceId = keyValue ;
138
+ if (job .serviceIdsToCloneRenameAndExtend .contains (originalServiceId )) {
139
+ // FIXME: Do we need to worry about calendar_dates?
140
+ String [] clonedValues = getRowValues ().clone ();
141
+ String newServiceId = clonedValues [keyFieldIndex ] = String .join (":" , getIdScope (), originalServiceId );
142
+ // Modify start date only (preserve the end date from the future calendar entry).
143
+ int startDateIndex = Table .CALENDAR .getFieldIndex ("start_date" );
144
+ clonedValues [startDateIndex ] = feedMergeContext .active .feed .calendars .get (originalServiceId ).start_date
145
+ .format (GTFS_DATE_FORMATTER );
146
+ referenceTracker .checkReferencesAndUniqueness (
147
+ keyValue ,
148
+ getLineNumber (),
149
+ table .fields [0 ],
150
+ newServiceId ,
151
+ table ,
152
+ keyField ,
153
+ table .getOrderFieldName ()
154
+ );
155
+ writeValuesToTable (clonedValues , true );
156
+ }
141
157
}
142
158
}
143
159
}
0 commit comments