Skip to content

Commit

Permalink
Merge branch 'master' into feat/203
Browse files Browse the repository at this point in the history
  • Loading branch information
cka-y authored Feb 6, 2025
2 parents 07fb6ac + 02c5307 commit 61993dc
Show file tree
Hide file tree
Showing 29 changed files with 186 additions and 283 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ public class PointNearOriginNotice extends ValidationNotice {
private final String filename;

/** The row of the faulty row. */
private final int csvRowNumber;
@Nullable private final Integer csvRowNumber;

/** The index of the feature in the feature collection. */
@Nullable private final Integer featureIndex;

/** The id of the faulty entity. */
@Nullable private final String entityId;

/** The name of the field that uses latitude value. */
private final String latFieldName;
@Nullable private final String latFieldName;

/** The latitude of the faulty row. */
private final double latFieldValue;

/** The name of the field that uses longitude value. */
private final String lonFieldName;
@Nullable private final String lonFieldName;

/** The longitude of the faulty row */
private final double lonFieldValue;
Expand All @@ -67,6 +70,7 @@ public PointNearOriginNotice(
this.latFieldValue = latFieldValue;
this.lonFieldName = lonFieldName;
this.lonFieldValue = lonFieldValue;
this.featureIndex = null;
}

public PointNearOriginNotice(
Expand All @@ -83,5 +87,22 @@ public PointNearOriginNotice(
this.latFieldValue = latFieldValue;
this.lonFieldName = lonFieldName;
this.lonFieldValue = lonFieldValue;
this.featureIndex = null;
}

public PointNearOriginNotice(
String filename,
String entityId,
double latFieldValue,
double lonFieldValue,
int featureIndex) {
this.filename = filename;
this.csvRowNumber = null;
this.entityId = entityId;
this.latFieldName = null;
this.latFieldValue = latFieldValue;
this.lonFieldName = null;
this.lonFieldValue = lonFieldValue;
this.featureIndex = featureIndex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,24 @@ public class PointNearPoleNotice extends ValidationNotice {
private final String filename;

/** The row of the faulty row. */
private final int csvRowNumber;
@Nullable private final Integer csvRowNumber;

/** The index of the feature in the feature collection. */
@Nullable private final Integer featureIndex;

/** The id of the faulty entity. */
@Nullable private final String entityId;

/** The name of the field that uses latitude value. */
private final String latFieldName;
@Nullable private final String latFieldName;

/** The latitude of the faulty row. */
private final double latFieldValue;

/** The name of the field that uses longitude value. */
private final String lonFieldName;
@Nullable private final String lonFieldName;

/** The longitude of the faulty row. */
/** The longitude of the faulty row */
private final double lonFieldValue;

public PointNearPoleNotice(
Expand All @@ -67,6 +70,7 @@ public PointNearPoleNotice(
this.latFieldValue = latFieldValue;
this.lonFieldName = lonFieldName;
this.lonFieldValue = lonFieldValue;
this.featureIndex = null;
}

public PointNearPoleNotice(
Expand All @@ -83,5 +87,22 @@ public PointNearPoleNotice(
this.latFieldValue = latFieldValue;
this.lonFieldName = lonFieldName;
this.lonFieldValue = lonFieldValue;
this.featureIndex = null;
}

public PointNearPoleNotice(
String filename,
String entityId,
double latFieldValue,
double lonFieldValue,
int featureIndex) {
this.filename = filename;
this.csvRowNumber = null;
this.entityId = entityId;
this.latFieldName = null;
this.latFieldValue = latFieldValue;
this.lonFieldName = null;
this.lonFieldValue = lonFieldValue;
this.featureIndex = featureIndex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ private NoticeContainer validateHeaders(
.filter(GtfsColumnDescriptor::headerRequired)
.map(GtfsColumnDescriptor::columnName)
.collect(Collectors.toSet()),
columnDescriptors.stream()
.filter(GtfsColumnDescriptor::headerRecommended)
.map(GtfsColumnDescriptor::columnName)
.collect(Collectors.toSet()),
headerNotices);
return headerNotices;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public abstract class GtfsColumnDescriptor {

public abstract boolean headerRequired();

public abstract boolean headerRecommended();

public abstract FieldLevelEnum fieldLevel();

public abstract Optional<RowParser.NumberBounds> numberBounds();
Expand All @@ -35,8 +33,6 @@ public abstract static class Builder {

public abstract Builder setHeaderRequired(boolean value);

public abstract Builder setHeaderRecommended(boolean value);

public abstract Builder setFieldLevel(FieldLevelEnum value);

public abstract Builder setNumberBounds(Optional<RowParser.NumberBounds> value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.TreeSet;
import org.mobilitydata.gtfsvalidator.notice.DuplicatedColumnNotice;
import org.mobilitydata.gtfsvalidator.notice.EmptyColumnNameNotice;
import org.mobilitydata.gtfsvalidator.notice.MissingRecommendedColumnNotice;
import org.mobilitydata.gtfsvalidator.notice.MissingRequiredColumnNotice;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.notice.UnknownColumnNotice;
Expand All @@ -37,7 +36,6 @@ public void validate(
CsvHeader actualHeader,
Set<String> supportedColumns,
Set<String> requiredColumns,
Set<String> recommendedColumns,
NoticeContainer noticeContainer) {
if (actualHeader.getColumnCount() == 0) {
// This is an empty file.
Expand All @@ -48,9 +46,6 @@ public void validate(
// We remove the columns that are properly present and well formed from that set, and at the
// end only the missing required columns are left in the set.
TreeSet<String> missingColumns = new TreeSet<>(requiredColumns);
// We also want to find the recommended columns that are absent. We use the same scheme for
// these.
TreeSet<String> missingRecommendedColumns = new TreeSet<>(recommendedColumns);
for (int i = 0; i < actualHeader.getColumnCount(); ++i) {
String column = actualHeader.getColumnName(i);
// Column indices are zero-based. We add 1 to make them 1-based.
Expand All @@ -69,20 +64,11 @@ public void validate(

// If the column is present, it should not be in the missing required columns set
missingColumns.remove(column);

// If the column is present, it should not be in the missing recommended columns set
missingRecommendedColumns.remove(column);
}
if (!missingColumns.isEmpty()) {
for (String column : missingColumns) {
noticeContainer.addValidationNotice(new MissingRequiredColumnNotice(filename, column));
}
}

if (!missingRecommendedColumns.isEmpty()) {
for (String column : missingRecommendedColumns) {
noticeContainer.addValidationNotice(new MissingRecommendedColumnNotice(filename, column));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ void validate(
CsvHeader actualHeader,
Set<String> supportedHeaders,
Set<String> requiredHeaders,
Set<String> recommendedHeaders,
NoticeContainer noticeContainer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ public boolean headerRequired() {
return false;
}

@Override
public boolean headerRecommended() {
return false;
}

@Override
public FieldLevelEnum fieldLevel() {
return FieldLevelEnum.REQUIRED;
Expand Down Expand Up @@ -146,7 +141,6 @@ public void asString_recommended_missing() {
GtfsColumnDescriptor.builder()
.setColumnName("column name")
.setHeaderRequired(false)
.setHeaderRecommended(false)
.setFieldLevel(FieldLevelEnum.RECOMMENDED)
.setIsMixedCase(false)
.setIsCached(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public void validate(
CsvHeader actualHeader,
Set<String> supportedHeaders,
Set<String> requiredHeaders,
Set<String> recommendedHeaders,
NoticeContainer noticeContainer) {
noticeContainer.addValidationNotice(headerValidationNotice);
}
Expand Down Expand Up @@ -148,15 +147,13 @@ public void missingRequiredField() {
GtfsColumnDescriptor.builder()
.setColumnName(GtfsTestEntity.ID_FIELD_NAME)
.setHeaderRequired(true)
.setHeaderRecommended(false)
.setFieldLevel(FieldLevelEnum.REQUIRED)
.setIsMixedCase(false)
.setIsCached(false)
.build(),
GtfsColumnDescriptor.builder()
.setColumnName(GtfsTestEntity.CODE_FIELD_NAME)
.setHeaderRequired(false)
.setHeaderRecommended(false)
.setFieldLevel(FieldLevelEnum.REQUIRED)
.setIsMixedCase(false)
.setIsCached(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public ImmutableList<GtfsColumnDescriptor> getColumns() {
GtfsColumnDescriptor.builder()
.setColumnName(GtfsTestEntity.ID_FIELD_NAME)
.setHeaderRequired(true)
.setHeaderRecommended(false)
.setFieldLevel(FieldLevelEnum.REQUIRED)
.setIsMixedCase(false)
.setIsCached(false)
Expand All @@ -49,7 +48,6 @@ public ImmutableList<GtfsColumnDescriptor> getColumns() {
GtfsColumnDescriptor.builder()
.setColumnName(GtfsTestEntity.CODE_FIELD_NAME)
.setHeaderRequired(false)
.setHeaderRecommended(false)
.setFieldLevel(FieldLevelEnum.OPTIONAL)
.setIsMixedCase(false)
.setIsCached(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public ImmutableList<GtfsColumnDescriptor> getColumns() {
GtfsColumnDescriptor.builder()
.setColumnName(GtfsTestEntity.ID_FIELD_NAME)
.setHeaderRequired(true)
.setHeaderRecommended(false)
.setFieldLevel(FieldLevelEnum.REQUIRED)
.setIsMixedCase(false)
.setIsCached(false)
Expand All @@ -50,7 +49,6 @@ public ImmutableList<GtfsColumnDescriptor> getColumns() {
GtfsColumnDescriptor.builder()
.setColumnName(GtfsTestEntity.CODE_FIELD_NAME)
.setHeaderRequired(false)
.setHeaderRecommended(false)
.setFieldLevel(FieldLevelEnum.OPTIONAL)
.setIsMixedCase(false)
.setIsCached(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
import static com.google.common.truth.Truth.assertThat;

import com.google.common.collect.ImmutableSet;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mobilitydata.gtfsvalidator.notice.DuplicatedColumnNotice;
import org.mobilitydata.gtfsvalidator.notice.EmptyColumnNameNotice;
import org.mobilitydata.gtfsvalidator.notice.MissingRecommendedColumnNotice;
import org.mobilitydata.gtfsvalidator.notice.MissingRequiredColumnNotice;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.notice.UnknownColumnNotice;
Expand All @@ -42,7 +40,6 @@ public void expectedColumns() {
new CsvHeader(new String[] {"stop_id", "stop_name"}),
ImmutableSet.of("stop_id", "stop_name", "stop_lat", "stop_lon"),
ImmutableSet.of("stop_id"),
Set.of(),
container);

assertThat(container.getValidationNotices()).isEmpty();
Expand All @@ -58,7 +55,6 @@ public void unknownColumnShouldGenerateNotice() {
new CsvHeader(new String[] {"stop_id", "stop_name", "stop_extra"}),
ImmutableSet.of("stop_id", "stop_name"),
ImmutableSet.of("stop_id"),
Set.of(),
container);

assertThat(container.getValidationNotices())
Expand All @@ -75,29 +71,12 @@ public void missingRequiredColumnShouldGenerateNotice() {
new CsvHeader(new String[] {"stop_name"}),
ImmutableSet.of("stop_id", "stop_name"),
ImmutableSet.of("stop_id"),
Set.of(),
container);

assertThat(container.getValidationNotices())
.containsExactly(new MissingRequiredColumnNotice("stops.txt", "stop_id"));
}

@Test
public void missingRecommendedColumnShouldGenerateNotice() {
NoticeContainer container = new NoticeContainer();
new DefaultTableHeaderValidator()
.validate(
"stops.txt",
new CsvHeader(new String[] {"stop_name"}),
Set.of("stop_id", "stop_name"),
Set.of(),
Set.of("stop_id"),
container);

assertThat(container.getValidationNotices())
.containsExactly(new MissingRecommendedColumnNotice("stops.txt", "stop_id"));
}

@Test
public void duplicatedColumnShouldGenerateNotice() {
NoticeContainer container = new NoticeContainer();
Expand All @@ -107,7 +86,6 @@ public void duplicatedColumnShouldGenerateNotice() {
new CsvHeader(new String[] {"stop_id", "stop_name", "stop_id"}),
ImmutableSet.of("stop_id", "stop_name"),
ImmutableSet.of("stop_id"),
Set.of(),
container);

assertThat(container.getValidationNotices())
Expand All @@ -124,7 +102,6 @@ public void emptyFileShouldNotGenerateNotice() {
CsvHeader.EMPTY,
ImmutableSet.of("stop_id", "stop_name"),
ImmutableSet.of("stop_id"),
Set.of(),
container);

assertThat(container.getValidationNotices()).isEmpty();
Expand All @@ -140,7 +117,6 @@ public void emptyColumnNameShouldGenerateNotice() {
new CsvHeader(new String[] {"stop_id", null, "stop_name", ""}),
ImmutableSet.of("stop_id", "stop_name"),
ImmutableSet.of("stop_id"),
Set.of(),
container);

assertThat(container.getValidationNotices())
Expand Down
Loading

0 comments on commit 61993dc

Please sign in to comment.