Skip to content

Commit

Permalink
Issue #6: Document and Verify Schedule Deviation Propagation Through
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bdferris committed Apr 14, 2012
1 parent 6eff39e commit b382fe6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,17 +30,27 @@
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<VehicleLocationRecordBean> {
ModelDriven<VehicleLocationRecordBean>, SessionAware {

private static final String KEY_LAST_RECORD = VehicleLocationRecordAction.class.getName()
+ ".lastRecord";

private static final long serialVersionUID = 1L;

private VehicleLocationRecordBean _model = new VehicleLocationRecordBean();

private TransitDataService _transitDataService;

private Map<String, Object> _session;

private int _m = 0;

@Autowired
public void setTransitDataService(TransitDataService transitDataService) {
_transitDataService = transitDataService;
Expand All @@ -48,9 +61,30 @@ public VehicleLocationRecordBean getModel() {
return _model;
}

@Override
public void setSession(Map<String, Object> 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;
}

Expand All @@ -65,18 +99,22 @@ 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) {
if (value != null && value.trim().isEmpty())
return null;
return value;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

<h1>Vehicle Location Record</h1>

<s:actionmessage />

<h2>Create a record:</h2>

<s:form method="post" action="vehicle-location-record!submit">
Expand Down

0 comments on commit b382fe6

Please sign in to comment.