use of org.onebusaway.admin.model.json.VehicleLastKnownRecord in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImpl method getLastKnownRecordData.
private VehicleLastKnownRecord getLastKnownRecordData(String vehicleId) {
List<VehicleLastKnownRecord> lastKnownRecords = new ArrayList<VehicleLastKnownRecord>();
String operationalAPIHost = null;
try {
operationalAPIHost = configurationService.getConfigurationValueAsString("operational-api.host", DEFAULT_OPERATIONAL_API_HOST);
} catch (RemoteConnectFailureException e) {
log.error("Failed retrieving operational API host from TDM. Setting to default value");
operationalAPIHost = DEFAULT_OPERATIONAL_API_HOST;
}
String url = buildURL(operationalAPIHost, "/record/last-known/vehicle/" + vehicleId);
log.info("making request for : " + url);
String lastknownContent = remoteConnectionService.getContent(url);
lastknownContent = lastknownContent.replace(System.getProperty("line.separator"), "");
String json = extractJsonArrayString(lastknownContent);
try {
JSONArray lastKnownContentArray = new JSONArray("[" + json + "]");
for (int i = 0; i < lastKnownContentArray.length(); i++) {
VehicleLastKnownRecord lastKnownRecord = convertToObject(lastKnownContentArray.getString(i), VehicleLastKnownRecord.class);
// lastknownrecord can be null if no data is returned by web service call
if (lastKnownRecord != null) {
lastKnownRecords.add(lastKnownRecord);
}
}
} catch (JSONException e) {
log.error("Error parsing json content : " + e);
e.printStackTrace();
}
if (!lastKnownRecords.isEmpty())
return lastKnownRecords.get(0);
return null;
}
use of org.onebusaway.admin.model.json.VehicleLastKnownRecord in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImpl method getVehicleStatus.
@Override
public List<VehicleStatus> getVehicleStatus(boolean loadNew) {
List<VehicleStatus> vehicleStatusRecords = null;
// Load new data only if asked explicitly
if (loadNew) {
VehicleStatusBuilder builder = new VehicleStatusBuilder();
// get last known record data from operational API
List<VehicleLastKnownRecord> vehicleLastKnownRecords = getLastKnownRecordData();
// get vehicle pipo data
Map<String, VehiclePullout> vehiclePullouts = getPulloutData();
vehicleStatusRecords = new ArrayList<VehicleStatus>();
// Build vehicle status objects by getting the required fields from both collections
for (VehicleLastKnownRecord lastknownRecord : vehicleLastKnownRecords) {
VehiclePullout pullout = vehiclePullouts.get(lastknownRecord.getVehicleId());
VehicleStatus vehicleStatus = builder.buildVehicleStatus(pullout, lastknownRecord);
vehicleStatusRecords.add(vehicleStatus);
}
// Add these records to the cache
cache.add(vehicleStatusRecords);
} else {
// return data from the cache to improve performance
vehicleStatusRecords = cache.fetch();
}
return vehicleStatusRecords;
}
use of org.onebusaway.admin.model.json.VehicleLastKnownRecord in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImpl method getLastKnownRecordData.
private List<VehicleLastKnownRecord> getLastKnownRecordData() {
List<VehicleLastKnownRecord> lastKnownRecords = new ArrayList<VehicleLastKnownRecord>();
String operationalAPIHost = null;
try {
operationalAPIHost = configurationService.getConfigurationValueAsString("operational-api.host", DEFAULT_OPERATIONAL_API_HOST);
} catch (RemoteConnectFailureException e) {
log.error("Failed retrieving operational API host from TDM. Setting to default value");
operationalAPIHost = DEFAULT_OPERATIONAL_API_HOST;
}
String url = buildURL(operationalAPIHost, "/record/last-known/list");
log.debug("making request for : " + url);
String lastknownContent = remoteConnectionService.getContent(url);
lastknownContent = lastknownContent.replace(System.getProperty("line.separator"), "");
String json = extractJsonArrayString(lastknownContent);
try {
JSONArray lastKnownContentArray = new JSONArray("[" + json + "]");
for (int i = 0; i < lastKnownContentArray.length(); i++) {
VehicleLastKnownRecord lastKnownRecord = convertToObject(lastKnownContentArray.getString(i), VehicleLastKnownRecord.class);
// lastknownrecord can be null if no data is returned by web service call
if (lastKnownRecord != null) {
lastKnownRecords.add(lastKnownRecord);
}
}
} catch (JSONException e) {
log.error("Error parsing json content : " + e);
e.printStackTrace();
}
return lastKnownRecords;
}
use of org.onebusaway.admin.model.json.VehicleLastKnownRecord in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImpl method getVehicleDetail.
@Override
public VehicleDetail getVehicleDetail(String vehicleId) {
VehicleDetailBuilder builder = new VehicleDetailBuilder();
VehicleLastKnownRecord lastKnownRecord = getLastKnownRecordData(vehicleId);
if (lastKnownRecord != null) {
VehiclePullout pullout = getPulloutData(vehicleId);
String headSign = getHeadSign(lastKnownRecord.getDestinationSignCode());
String inferredHeadSign = getHeadSign(lastKnownRecord.getInferredDSC());
return builder.buildVehicleDetail(pullout, lastKnownRecord, headSign, inferredHeadSign);
}
return null;
}
Aggregations