}
public static void updateTripPattern() {
TripPattern tripPattern;
try {
tripPattern = mapper.readValue(params.get("body"), TripPattern.class);
if(tripPattern.id == null)
badRequest();
TripPattern originalTripPattern = TripPattern.findById(tripPattern.id);
if(originalTripPattern == null)
badRequest();
if(tripPattern.encodedShape != null) {
if(originalTripPattern.shape != null) {
originalTripPattern.shape.updateShapeFromEncoded(tripPattern.encodedShape);
tripPattern.shape = originalTripPattern.shape;
}
else {
TripShape ts = TripShape.createFromEncoded(tripPattern.encodedShape);
tripPattern.shape = ts;
}
}
else {
tripPattern.shape = null;
// need to remove old shapes...
}
TripPattern updatedTripPattern = TripPattern.em().merge(tripPattern);
updatedTripPattern.save();
Set<Long> patternStopIds = new HashSet<Long>();
for(TripPatternStop patternStop : updatedTripPattern.patternStops) {
patternStopIds.add(patternStop.id);
}