Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated hsqldb, slf4j. Fixed javac compiler bug, added more robust agency support. #45

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion onebusaway-gtfs-hibernate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.0.0-rc9</version>
<version>2.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,20 @@ public void saveOrUpdateEntity(Object entity) {
public <T> void clearAllEntitiesForType(Class<T> type) {
_ops.clearAllEntitiesForType(type);
}

@Override
public ServiceCalendar getFirstCalendarForServiceId(AgencyAndId serviceId) {

List<ServiceCalendar> calendars = _ops.findByNamedQueryAndNamedParam(
"calendarsForServiceId", "serviceId", serviceId);

switch (calendars.size()) {
case 0:
return null;
case 1:
return calendars.get(0);
default:
return calendars.get(0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
import org.onebusaway.gtfs_transformer.updates.SubsectionTripTransformStrategy.SubsectionOperation;
import org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy;
import org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TransformFactory {

Expand Down Expand Up @@ -126,6 +128,8 @@ public class TransformFactory {
private final EntitySchemaCache _schemaCache = new EntitySchemaCache();

private final PropertyMethodResolverImpl _propertyMethodResolver;

private static Logger _log = LoggerFactory.getLogger(TransformFactory.class);

public TransformFactory(GtfsTransformer transformer) {
_transformer = transformer;
Expand Down Expand Up @@ -460,8 +464,11 @@ private void setObjectPropertiesFromJsonUsingCsvFields(Object object,
try {
mapping.translateFromCSVToObject(context, values, wrapped);
} catch (MissingRequiredFieldException ex) {
throw new TransformSpecificationMissingArgumentException(line,
ex.getFieldName());
String verboseMessage = "line=" + line + ", context=" + context + ", json="
+ json + ", object=" + object;
_log.error("missing required field; details:" + verboseMessage);
throw new TransformSpecificationMissingArgumentException(verboseMessage,
ex.getFieldName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) {
- stopTime.getArrivalTime();
maxDeviation = Math.max(maxDeviation, deviation);
if (deviation > 60)
_log.info("out_of_order_stop_times: prev=" + prev + " next="
_log.debug("out_of_order_stop_times: prev=" + prev + " next="
+ stopTime + " deviation=" + deviation);
stopTime.setArrivalTime(prev.getDepartureTime());
if (stopTime.getDepartureTime() < stopTime.getArrivalTime())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@
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;

public class LocalVsExpressUpdateStrategy implements GtfsTransformStrategy {

private static Logger _log = LoggerFactory.getLogger(LocalVsExpressUpdateStrategy.class);

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {

_log.info("running");
for (Route route : dao.getAllRoutes()) {

List<Trip> trips = dao.getTripsForRoute(route);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,63 +27,66 @@
import org.slf4j.LoggerFactory;

public class ShapeTransformStrategy implements GtfsTransformStrategy {
// there is something wrong with the configuration of the strategy
// these changes clearly should not be necessary
// (unless onebusaway-csv changes forced this?)
// TODO FIXME
private String shapeId;

private Logger _log = LoggerFactory.getLogger(ShapeTransformStrategy.class);
private String shape;

private String _shapeId;
private boolean matchStart = true;

private String _shape;
private boolean matchEnd = true;

private boolean _matchStart = true;

private boolean _matchEnd = true;

public void setShapeId(String shapeId) {
_shapeId = shapeId;
public void setShapeId(String ashapeId) {
shapeId = ashapeId;
}

public void setShape(String shape) {
_shape = shape;
public void setShape(String ashape) {
shape = ashape;
}

public void setMatchStart(boolean matchStart) {
_matchStart = matchStart;
public void setMatchStart(boolean amatchStart) {
matchStart = amatchStart;
}

public void setMatchEnd(boolean matchEnd) {
_matchEnd = matchEnd;
public void setMatchEnd(boolean amatchEnd) {
matchEnd = amatchEnd;
}

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {

String agencyId = context.getDefaultAgencyId();
AgencyAndId shapeId = new AgencyAndId(agencyId, _shapeId);
AgencyAndId ashapeId = new AgencyAndId(agencyId, shapeId);

List<ShapePoint> shapePoints = dao.getShapePointsForShapeId(shapeId);
List<ShapePoint> shapePoints = dao.getShapePointsForShapeId(ashapeId);

if (shapePoints.isEmpty()) {
_log.warn("no points found for shape: " + shapeId);
// this cannot be a logger as it is BeanWrapped
System.err.println("no points found for shape: " + ashapeId);
return;
}

// Duplicate the list into something we can modify
shapePoints = new ArrayList<ShapePoint>(shapePoints);

List<ShapePoint> segment = decode(_shape);
List<ShapePoint> segment = decode(shape);
ShapePoint from = segment.get(0);
ShapePoint to = segment.get(segment.size() - 1);

int fromIndex = 0;
int toIndex = shapePoints.size() - 1;

if (_matchStart)
if (matchStart)
fromIndex = closest(shapePoints, from, 0);
if (_matchEnd)
if (matchEnd)
toIndex = closest(shapePoints, to, fromIndex);

if (toIndex < fromIndex) {
_log.error("segment match is out of order: fromIndex=" + fromIndex
// this cannot be a logger as it is BeanWrapped
System.err.println("segment match is out of order: fromIndex=" + fromIndex
+ " toIndex=" + toIndex);
return;
}
Expand All @@ -98,7 +101,7 @@ public void run(TransformContext context, GtfsMutableRelationalDao dao) {
for (ShapePoint point : shapePoints) {
point.setDistTraveled(ShapePoint.MISSING_VALUE);
point.setSequence(index++);
point.setShapeId(shapeId);
point.setShapeId(ashapeId);
}

for (ShapePoint point : segment)
Expand Down Expand Up @@ -180,4 +183,4 @@ private int[] decodeNumberWithIndex(String value, int index) {

return new int[] {num, index};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ public ServiceCalendar getCalendarForServiceId(AgencyAndId serviceId) {
throw new MultipleCalendarsForServiceIdException(serviceId);
}

@Override
public ServiceCalendar getFirstCalendarForServiceId(AgencyAndId serviceId) {
ensureCalendarsByServiceIdRelation();
List<ServiceCalendar> calendars = list(_calendarsByServiceId.get(serviceId));
switch (calendars.size()) {
case 0:
return null;
case 1:
return calendars.get(0);
default:
return calendars.get(0);
}
}


@Override
public List<FareRule> getFareRulesForFareAttribute(FareAttribute fareAttribute) {
if (_fareRulesByFareAttribute == null) {
Expand Down Expand Up @@ -326,18 +341,23 @@ private static <K, V> Map<K, List<V>> mapToValueList(Iterable<V> values,
new ArrayList<V>().getClass());
}

/*
* TODO: FIXME: Javac 1.6 can't infer the type correctly with previous definition
* of CIMPL (compiler bug). So this method is named incorrectly until we de-support
* javac 1.6 should that ever happen
*/
@SuppressWarnings("unchecked")
private static <K, V, C extends Collection<V>, CIMPL extends C> Map<K, C> mapToValueCollection(
private static <K, V, CIMPL extends List<V>> Map<K, List<V>> mapToValueCollection(
Iterable<V> values, String property, Class<K> keyType,
Class<CIMPL> collectionType) {

Map<K, C> byKey = new HashMap<K, C>();
Map<K, List<V>> byKey = new HashMap<K, List<V>>();
SimplePropertyQuery query = new SimplePropertyQuery(property);

for (V value : values) {

K key = (K) query.invoke(value);
C valuesForKey = byKey.get(key);
List<V> valuesForKey = byKey.get(key);
if (valuesForKey == null) {

try {
Expand Down Expand Up @@ -377,4 +397,4 @@ public Object invoke(Object value) {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public CalendarServiceData createData() {
public Set<ServiceDate> getServiceDatesForServiceId(AgencyAndId serviceId,
TimeZone serviceIdTimeZone) {
Set<ServiceDate> activeDates = new HashSet<ServiceDate>();
ServiceCalendar c = _dao.getCalendarForServiceId(serviceId);
ServiceCalendar c = _dao.getFirstCalendarForServiceId(serviceId);

if (c != null) {
addDatesFromCalendar(c, serviceIdTimeZone, activeDates);
Expand Down Expand Up @@ -252,4 +252,4 @@ private static Date getServiceDateAsNoon(ServiceDate serviceDate,
c.add(Calendar.HOUR_OF_DAY, 12);
return c.getTime();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.onebusaway.gtfs.serialization.GtfsEntitySchemaFactory;
import org.onebusaway.gtfs.serialization.GtfsReader;
import org.onebusaway.gtfs.serialization.GtfsReaderContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A {@link FieldMappingFactory} implementation that produces a
Expand Down Expand Up @@ -64,6 +66,7 @@
*/
public class DefaultAgencyIdFieldMappingFactory implements FieldMappingFactory {

private static Logger _log = LoggerFactory.getLogger(DefaultAgencyIdFieldMappingFactory.class);
private String _agencyIdPath = null;

public DefaultAgencyIdFieldMappingFactory() {
Expand Down Expand Up @@ -108,19 +111,24 @@ public void translateFromCSVToObject(CsvEntityContext context,
return;

String agencyId = resolveAgencyId(context, object);

if (agencyId == null) {
_log.error("missing agencyId for object " + object);
return;
}
//_log.error("looking for fieldName=" + _csvFieldName);
String id = (String) csvValues.get(_csvFieldName);
AgencyAndId agencyAndId = new AgencyAndId(agencyId, id);
object.setPropertyValue(_objFieldName, agencyAndId);
}

private String resolveAgencyId(CsvEntityContext context, BeanWrapper object) {

//_log.error("resolveAgencyId(" + context + ", " + object + ")");
if (_agencyIdPath == null) {
GtfsReaderContext ctx = (GtfsReaderContext) context.get(GtfsReader.KEY_CONTEXT);
return ctx.getDefaultAgencyId();
}

//_log.error("agencyIdPath=" + _agencyIdPath);
for (String property : _agencyIdPath.split("\\.")) {
Object value = object.getPropertyValue(property);
object = BeanWrapperFactory.wrap(value);
Expand All @@ -129,4 +137,4 @@ private String resolveAgencyId(CsvEntityContext context, BeanWrapper object) {
return object.getWrappedInstance(Object.class).toString();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public interface GtfsRelationalDao extends GtfsDao {
public List<AgencyAndId> getAllServiceIds();

public ServiceCalendar getCalendarForServiceId(AgencyAndId serviceId);

public ServiceCalendar getFirstCalendarForServiceId(AgencyAndId serviceId);

/****
* {@link ServiceCalendarDate} Methods
Expand All @@ -128,4 +130,4 @@ public List<ServiceCalendarDate> getCalendarDatesForServiceId(

public List<FareRule> getFareRulesForFareAttribute(FareAttribute fareAttribute);

}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.6</version>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down