Skip to content

Commit

Permalink
fix(MergeLineContext): Move newAgencyId to FeedMergeContext for persi…
Browse files Browse the repository at this point in the history
…sted value.
  • Loading branch information
binh-dam-ibigroup committed Nov 8, 2021
1 parent bde820d commit e80950c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void checkForMissingAgencyId() {
// agency_id is optional if only one agency is present, but that will
// cause issues for the feed merge, so we need to insert an agency_id
// for the single entry.
newAgencyId = UUID.randomUUID().toString();
feedMergeContext.setNewAgencyId(UUID.randomUUID().toString());
if (keyFieldMissing) {
// Only add agency_id field if it is missing in table.
addField(Table.AGENCY.fields[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ public class FeedMergeContext implements Closeable {
public final LocalDate activeFeedFirstDate;
private LocalDate futureFeedFirstDate;
private LocalDate futureFirstCalendarStartDate = LocalDate.MAX;
/** Trip ids shared between the active and future feed. */
/**
* Trip ids shared between the active and future feed.
*/
public final Set<String> sharedTripIds;

/**
* Holds the auto-generated agency id to be updated if none was provided.
*/
private String newAgencyId;

public FeedMergeContext(Set<FeedVersion> feedVersions, Auth0UserProfile owner) throws IOException {
feedsToMerge = MergeFeedUtils.collectAndSortFeeds(feedVersions, owner);
Expand Down Expand Up @@ -126,6 +131,14 @@ public void setFutureFeedFirstDate(LocalDate futureFeedFirstDate) {
this.futureFeedFirstDate = futureFeedFirstDate;
}

public String getNewAgencyId() {
return newAgencyId;
}

public void setNewAgencyId(String newAgencyId) {
this.newAgencyId = newAgencyId;
}

/**
* Holds the status of a trip service id mismatch determination.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class MergeLineContext {
private final CsvListWriter writer;
private CsvReader csvReader;
protected boolean skipRecord;
protected String newAgencyId; // move
protected boolean keyFieldMissing;
private String[] rowValues;
private int lineNumber = 0;
Expand Down Expand Up @@ -126,8 +125,8 @@ public void startNewFeed(int feedIndex) throws IOException {
keyFieldMissing = false;
// Use for a new agency ID for use if the feed does not contain one. Initialize to
// null. If the value becomes non-null, the agency_id is missing and needs to be
// replaced with the generated value stored in this variable.
newAgencyId = null;
// replaced in other affected tables with the generated value stored in this variable.
feedMergeContext.setNewAgencyId(null);
// Generate ID prefix to scope GTFS identifiers to avoid conflicts.
idScope = getCleanName(feedSource.name) + version.version;
csvReader = table.getCsvReader(feed.zipFile, null);
Expand Down Expand Up @@ -358,6 +357,7 @@ protected void checkRoutesAndStopsIds(Set<NewGTFSError> idErrors) throws IOExcep
if (hasDuplicateError(idErrors)) skipRecord = true;
}

String newAgencyId = feedMergeContext.getNewAgencyId();
if (newAgencyId != null && fieldNameEquals(AGENCY_ID)) {
LOG.info(
"Updating route#agency_id to (auto-generated) {} for route={}",
Expand All @@ -375,6 +375,7 @@ private boolean useAltKey() {
}

public boolean updateAgencyIdIfNeeded() {
String newAgencyId = feedMergeContext.getNewAgencyId();
if (newAgencyId != null && fieldNameEquals(AGENCY_ID) && job.mergeType.equals(REGIONAL)) {
if (fieldContext.getValue().equals("") && table.name.equals("agency") && lineNumber > 0) {
// If there is no agency_id value for a second (or greater) agency
Expand Down

0 comments on commit e80950c

Please sign in to comment.