Skip to content

Commit

Permalink
Merge pull request #15 from mbta/es-merge-latest-upstream
Browse files Browse the repository at this point in the history
Merge latest upstream changes
  • Loading branch information
EmmaSimon committed Jun 22, 2023
2 parents 5f381cd + a1dfbac commit 0a8f672
Show file tree
Hide file tree
Showing 23 changed files with 440 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 8
java-version: 11

- name: Cache Maven dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Test project with Maven
run: mvn --no-transfer-progress test verify
run: mvn --no-transfer-progress test install
2 changes: 1 addition & 1 deletion onebusaway-gtfs-hibernate-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-gtfs-modules</artifactId>
<version>1.3.119-MBTA-SNAPSHOT</version>
<version>1.4.4-MBTA-SNAPSHOT</version>
</parent>
<artifactId>onebusaway-gtfs-hibernate-cli</artifactId>
<name>onebusaway-gtfs-hibernate-cli</name>
Expand Down
2 changes: 1 addition & 1 deletion onebusaway-gtfs-hibernate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-gtfs-modules</artifactId>
<version>1.3.119-MBTA-SNAPSHOT</version>
<version>1.4.4-MBTA-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ public List<Route> getAllRoutes() {
return _ops.find("FROM Route route");
}

@Override
public List<RouteStop> getAllRouteStops() {
return _ops.find("FROM RouteStop routeStop");
}

@Override
public List<RouteShape> getAllRouteShapes() {
return _ops.find("FROM RouteShape routeShape");
}

@Override
public List<Stop> getAllStops() {
return _ops.find("FROM Stop");
Expand Down
2 changes: 1 addition & 1 deletion onebusaway-gtfs-merge-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>onebusaway-gtfs-modules</artifactId>
<groupId>org.onebusaway</groupId>
<version>1.3.119-MBTA-SNAPSHOT</version>
<version>1.4.4-MBTA-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>onebusaway-gtfs-merge-cli</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion onebusaway-gtfs-merge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>onebusaway-gtfs-modules</artifactId>
<groupId>org.onebusaway</groupId>
<version>1.3.119-MBTA-SNAPSHOT</version>
<version>1.4.4-MBTA-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>onebusaway-gtfs-merge</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion onebusaway-gtfs-transformer-cli-aws/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-gtfs-modules</artifactId>
<version>1.3.119-MBTA-SNAPSHOT</version>
<version>1.4.4-MBTA-SNAPSHOT</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion onebusaway-gtfs-transformer-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-gtfs-modules</artifactId>
<version>1.3.119-MBTA-SNAPSHOT</version>
<version>1.4.4-MBTA-SNAPSHOT</version>
</parent>

<properties>
Expand Down
8 changes: 4 additions & 4 deletions onebusaway-gtfs-transformer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
<parent>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-gtfs-modules</artifactId>
<version>1.3.119-MBTA-SNAPSHOT</version>
<version>1.4.4-MBTA-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-gtfs</artifactId>
<version>1.3.119-MBTA-SNAPSHOT</version>
<version>1.4.4-MBTA-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.onebusaway</groupId>
Expand Down Expand Up @@ -83,8 +83,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Copyright (C) 2023 Cambridge Systematics, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onebusaway.gtfs_transformer.impl;

import org.onebusaway.csv_entities.schema.annotations.CsvField;
import org.onebusaway.gtfs.services.GtfsMutableRelationalDao;
import org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy;
import org.onebusaway.gtfs_transformer.services.TransformContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

/**
* Insert a GTFS extension into a GTFS file via a transformation.
* See the unit test for example usage.
*/

public class AddExtensionFile implements GtfsTransformStrategy {
private static Logger _log = LoggerFactory.getLogger(AddExtensionFile.class);


@CsvField(optional = false)
private String extensionFilename;
@CsvField(optional = false)
private String extensionName;
@Override
public String getName() {
return this.getClass().getName();
}

public void setExtensionFilename(String extensionFilename) {
this.extensionFilename = extensionFilename;
}
public void setExtensionName(String extensionName) {
this.extensionName = extensionName;
}

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
// lookup the file
if (extensionFilename == null)
throw new IllegalStateException("missing required param extensionFilename");
if (extensionName == null)
throw new IllegalStateException("missing required param extensionName");
_log.info("AddExtensionFile entered with {} to {}", extensionName, extensionFilename);
File extension = new File(extensionFilename);
if (!extension.exists()) {
throw new IllegalStateException("attempt to add non-existant extension file:" + extension.getName());
}
String content = null;
try {
content = Files.readString(extension.toPath());
} catch (IOException e) {
throw new IllegalStateException(e);
}
if (content == null)
throw new IllegalStateException("no content for specified file " + extensionFilename);

_log.info("AddExtensionFile copying {} to {}", extensionName, extensionFilename);
dao.addMetadata(extensionName, content);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.util.stream.Collectors;

public class FeedInfoFromAgencyStrategy implements GtfsTransformStrategy {

Expand Down Expand Up @@ -77,9 +78,13 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) {
}

private FeedInfo getFeedInfoFromAgency(GtfsMutableRelationalDao dao, Agency agency) {
FeedInfo info = dao.getFeedInfoForId(agencyId);
if (info == null) {
info = new FeedInfo();
// cannot just use dao.getFeedInfoFromAgencyForId if it needs to be compatable with "update" SimpleModificationStrategy
FeedInfo info = dao.getAllFeedInfos().stream().
filter(feed->feed.getId().equals(agencyId))
.collect(Collectors.toMap(feed->feed.getId(), feed -> feed))
.get(agency.getId());
if (info==null) {
info = new FeedInfo();
}
info.setId(agencyId);
info.setPublisherName(agency.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) {
for (AgencyAndId id : stopsToRemove) {
Stop stop = dao.getStopForId(id);
//removeEntityLibrary.removeStop(dao, stop);
dao.removeEntity(stop);
if (stop != null) {
dao.removeEntity(stop);
} else {
_log.info("expecting stop {} but it was not found", id);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Copyright (C) 2023 Cambridge Systematics, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onebusaway.gtfs_transformer.impl;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onebusaway.gtfs.impl.FileSupport;
import org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl;
import org.onebusaway.gtfs.serialization.GtfsWriter;
import org.onebusaway.gtfs.services.GtfsRelationalDao;
import org.onebusaway.gtfs_transformer.AbstractTestSupport;
import org.onebusaway.gtfs_transformer.services.TransformContext;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.junit.Assert.*;

/**
* test we can insert an extension into a GTFS file via a transformation.
*/
public class AddExtensionFileTest extends AbstractTestSupport {

private static final String TXT_STRING = "route_id,stop_id,direction_id,name\n";
private FileSupport _support = new FileSupport();
private GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
private AddExtensionFile test = new AddExtensionFile();
private TransformContext context = new TransformContext();
private GtfsWriter writer = new GtfsWriter();

@Before
public void setup() {
_gtfs.putAgencies(1);
_gtfs.putStops(1);
_gtfs.putRoutes(1);
_gtfs.putTrips(1, "r0", "sid0");
_gtfs.putStopTimes("t0", "s0");

}
@After
public void teardown() {
_support.cleanup();
}

@Test
public void run() throws IOException {
File extensionFile = File.createTempFile("subwayRouteStop-", ".csv");
if (extensionFile.exists())
extensionFile.deleteOnExit();

String extensionFilename = extensionFile.getAbsolutePath();;
BufferedWriter bwriter = new BufferedWriter(new FileWriter(extensionFilename));
bwriter.write(TXT_STRING);
bwriter.close();

String extensionName = "route_stop.txt";
test.setExtensionFilename(extensionFilename);
test.setExtensionName(extensionName);

test.run(context, dao);

File tmpFileDirectory = File.createTempFile("AddExtensionFileTest-", "-tmp");
if (tmpFileDirectory.exists())
_support.deleteFileRecursively(tmpFileDirectory);
tmpFileDirectory.mkdirs();
_support.markForDeletion(tmpFileDirectory);
writer.setOutputLocation(tmpFileDirectory);
writer.run(dao);
writer.close();

String modLocation = tmpFileDirectory.getAbsolutePath() + File.separator + extensionName;
File expectedFile = new File(modLocation);
// verify file is there
assertTrue("expected extension to be present!", expectedFile.exists());
assertTrue("expected extension to be a file!", expectedFile.isFile());
String actualText = Files.readString(Path.of(modLocation));
assertEquals(TXT_STRING, actualText);

}
}
2 changes: 1 addition & 1 deletion onebusaway-gtfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.onebusaway</groupId>
<artifactId>onebusaway-gtfs-modules</artifactId>
<version>1.3.119-MBTA-SNAPSHOT</version>
<version>1.4.4-MBTA-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
Loading

0 comments on commit 0a8f672

Please sign in to comment.