From b382fe6fe406fec50c437ac9e4e072e8955786ec Mon Sep 17 00:00:00 2001 From: Brian Ferris Date: Sat, 14 Apr 2012 14:56:13 +0200 Subject: [PATCH] Issue #6: Document and Verify Schedule Deviation Propagation Through Layovers The admin interface currently supports a method to inject vehicle location records using a web-form. I've been using this interface to simulate various vehicle locations in order to test some behavior around layovers. I've made a few changes to improve the usability of this form: 1) The most-recently-submitted record will be used to automatically populate the form after submission. 2) Add a post-submission message to indicate that things were successful. --- .../realtime/VehicleLocationRecordBean.java | 20 ++++++++ .../debug/VehicleLocationRecordAction.java | 46 +++++++++++++++++-- .../admin/debug/vehicle-location-record.jspx | 2 + 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/onebusaway-transit-data/src/main/java/org/onebusaway/transit_data/model/realtime/VehicleLocationRecordBean.java b/onebusaway-transit-data/src/main/java/org/onebusaway/transit_data/model/realtime/VehicleLocationRecordBean.java index dfa61ae45..62cf62a13 100644 --- a/onebusaway-transit-data/src/main/java/org/onebusaway/transit_data/model/realtime/VehicleLocationRecordBean.java +++ b/onebusaway-transit-data/src/main/java/org/onebusaway/transit_data/model/realtime/VehicleLocationRecordBean.java @@ -160,4 +160,24 @@ public String getStatus() { public void setStatus(String status) { this.status = status; } + + /** + * All field values will be copied from the specified bean into our own bean. + * + * @param bean values copied from this bean + */ + public void copyFrom(VehicleLocationRecordBean bean) { + this.blockId = bean.blockId; + this.currentLocation = bean.currentLocation; + this.currentOrientation = bean.currentOrientation; + this.distanceAlongBlock = bean.distanceAlongBlock; + this.phase = bean.phase; + this.scheduleDeviation = bean.scheduleDeviation; + this.serviceDate = bean.serviceDate; + this.status = bean.status; + this.timeOfLocationUpdate = bean.timeOfLocationUpdate; + this.timeOfRecord = bean.timeOfRecord; + this.tripId = bean.vehicleId; + this.vehicleId = bean.vehicleId; + } } diff --git a/onebusaway-webapp/src/main/java/org/onebusaway/webapp/actions/admin/debug/VehicleLocationRecordAction.java b/onebusaway-webapp/src/main/java/org/onebusaway/webapp/actions/admin/debug/VehicleLocationRecordAction.java index 30eaab23a..a227ef70b 100644 --- a/onebusaway-webapp/src/main/java/org/onebusaway/webapp/actions/admin/debug/VehicleLocationRecordAction.java +++ b/onebusaway-webapp/src/main/java/org/onebusaway/webapp/actions/admin/debug/VehicleLocationRecordAction.java @@ -15,8 +15,11 @@ */ package org.onebusaway.webapp.actions.admin.debug; +import java.util.Map; + import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; +import org.apache.struts2.interceptor.SessionAware; import org.apache.struts2.interceptor.validation.SkipValidation; import org.onebusaway.transit_data.model.realtime.VehicleLocationRecordBean; import org.onebusaway.transit_data.services.TransitDataService; @@ -27,10 +30,16 @@ import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator; import com.opensymphony.xwork2.validator.annotations.Validations; -@Results({@Result(type = "redirectAction", name = "submitSuccess", params = { - "actionName", "vehicle-location-record"})}) +@Results({ + @Result(type = "redirectAction", name = "submitSuccess", params = { + "actionName", "vehicle-location-record", "m", "1"}), + @Result(type = "redirectAction", name = "resetSuccess", params = { + "actionName", "vehicle-location-record", "m", "2"})}) public class VehicleLocationRecordAction extends ActionSupport implements - ModelDriven { + ModelDriven, SessionAware { + + private static final String KEY_LAST_RECORD = VehicleLocationRecordAction.class.getName() + + ".lastRecord"; private static final long serialVersionUID = 1L; @@ -38,6 +47,10 @@ public class VehicleLocationRecordAction extends ActionSupport implements private TransitDataService _transitDataService; + private Map _session; + + private int _m = 0; + @Autowired public void setTransitDataService(TransitDataService transitDataService) { _transitDataService = transitDataService; @@ -48,9 +61,30 @@ public VehicleLocationRecordBean getModel() { return _model; } + @Override + public void setSession(Map session) { + _session = session; + } + + public void setM(int m) { + _m = m; + } + @SkipValidation @Override public String execute() { + VehicleLocationRecordBean lastRecord = (VehicleLocationRecordBean) _session.get(KEY_LAST_RECORD); + if (lastRecord != null) { + _model.copyFrom(lastRecord); + } + switch(_m) { + case 1: + addActionMessage("Record submitted!"); + break; + case 2: + addActionMessage("Vehicle reset!"); + break; + } return SUCCESS; } @@ -65,13 +99,16 @@ public String submit() { _model.setVehicleId(clean(_model.getVehicleId())); _transitDataService.submitVehicleLocation(_model); + + _session.put(KEY_LAST_RECORD, _model); + return "submitSuccess"; } @Validations(requiredStrings = {@RequiredStringValidator(fieldName = "vehicleId", key = "requiredField")}) public String reset() { _transitDataService.resetVehicleLocation(_model.getVehicleId()); - return "submitSuccess"; + return "resetSuccess"; } private String clean(String value) { @@ -79,4 +116,5 @@ private String clean(String value) { return null; return value; } + } diff --git a/onebusaway-webapp/src/main/webapp/WEB-INF/content/admin/debug/vehicle-location-record.jspx b/onebusaway-webapp/src/main/webapp/WEB-INF/content/admin/debug/vehicle-location-record.jspx index 9b85f8603..2f979510d 100644 --- a/onebusaway-webapp/src/main/webapp/WEB-INF/content/admin/debug/vehicle-location-record.jspx +++ b/onebusaway-webapp/src/main/webapp/WEB-INF/content/admin/debug/vehicle-location-record.jspx @@ -26,6 +26,8 @@

Vehicle Location Record

+ +

Create a record: