Skip to content

Commit

Permalink
refactor: address pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
miles-grant-ibigroup committed Mar 27, 2024
1 parent ac60485 commit 8082fac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ public void validateParameters(MonitorableJob.Status status) {
public void transform(FeedTransformZipTarget zipTarget, MonitorableJob.Status status) {
String tableName = table + ".txt";
Path targetZipPath = Paths.get(zipTarget.gtfsFile.getAbsolutePath());

try (
FileSystem targetZipFs = FileSystems.newFileSystem(targetZipPath, (ClassLoader) null);
InputStream inputStream = new ByteArrayInputStream(csvData.getBytes(StandardCharsets.UTF_8));
FileSystem targetZipFs = FileSystems.newFileSystem(targetZipPath, (ClassLoader) null);
InputStream newLineStream = new ByteArrayInputStream("\n".getBytes(StandardCharsets.UTF_8));
InputStream inputStream = new ByteArrayInputStream(csvData.getBytes(StandardCharsets.UTF_8));
) {
TransformType type = TransformType.TABLE_MODIFIED;

Expand All @@ -51,6 +53,9 @@ public void transform(FeedTransformZipTarget zipTarget, MonitorableJob.Status st

// Append CSV data into the target file in the temporary copy of file
try (OutputStream os = new FileOutputStream(tempFile, true)) {
// Append a newline in case our data doesn't include one
// Having an extra newline is not a problem!
os.write(newLineStream.readAllBytes());
os.write(inputStream.readAllBytes());
} catch (Exception e) {
status.fail("Failed to write to target file", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.conveyal.datatools.UnitTest;
import com.conveyal.datatools.manager.auth.Auth0Connection;
import com.conveyal.datatools.manager.auth.Auth0UserProfile;
import com.conveyal.datatools.manager.models.FeedRetrievalMethod;
import com.conveyal.datatools.manager.models.FeedSource;
import com.conveyal.datatools.manager.models.FeedVersion;
import com.conveyal.datatools.manager.models.Project;
Expand All @@ -27,17 +26,11 @@
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.supercsv.io.CsvMapReader;
import org.supercsv.prefs.CsvPreference;

import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
Expand All @@ -47,7 +40,6 @@
import static com.conveyal.datatools.TestUtils.createFeedVersion;
import static com.conveyal.datatools.TestUtils.zipFolderFiles;
import static com.conveyal.datatools.manager.models.FeedRetrievalMethod.MANUALLY_UPLOADED;
import static com.conveyal.datatools.manager.models.FeedRetrievalMethod.VERSION_CLONE;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -210,9 +202,9 @@ void canAppendToStops() throws SQLException, IOException {
);
LOG.info("Checking assertions.");
assertEquals(
6, // Magic number should match row count of stops.txt with one extra
5 + 3, // Magic number should match row count of stops.txt with three extra
targetVersion.feedLoadResult.stops.rowCount,
"stops.txt row count should equal input csv data # of rows + 1 extra row"
"stops.txt row count should equal input csv data # of rows + 3 extra rows"
);
// Check for presence of new stop id in database (one record).
assertThatSqlCountQueryYieldsExpectedCount(
Expand Down Expand Up @@ -315,7 +307,9 @@ private static String generateStopsWithCustomFields() {
}

private static String generateStopRow() {
return "\nnew,new,appended stop,,37.06668,-122.07781,,,0,123,,";
return "new3,new3,appended stop,,37,-122,,,0,123,," +
"\nnew2,new2,appended stop,,37,-122,,,0,123,," +
"\nnew,new,appended stop,,37.06668,-122.07781,,,0,123,,";
}

private static String generateCustomCsvData() {
Expand Down

0 comments on commit 8082fac

Please sign in to comment.