use of org.onebusaway.admin.model.BundleValidationCheckResult in project onebusaway-application-modules by camsys.
the class DeletedRouteQueryResultChecker method checkResults.
@Override
public BundleValidationCheckResult checkResults(BundleValidateQuery query) {
BundleValidationCheckResult checkResult = new BundleValidationCheckResult();
String result = query.getQueryResult();
result = result.toLowerCase();
String route = query.getRouteOrStop();
route = route.toLowerCase();
String routeId = query.getRouteId();
if (routeId.length() == 0) {
routeId = query.getRouteOrStop();
}
if (result.contains(CODE_200) && (!result.contains(SHORT_NAME + route) && !result.contains(LONG_NAME + route))) {
checkResult.setTestStatus(PASS);
checkResult.setTestResult(query.getErrorMessage() + FOUND_ROUTE_INFO + routeId);
} else {
checkResult.setTestStatus(FAIL);
checkResult.setTestResult(query.getErrorMessage() + DID_NOT_FIND_ROUTE_INFO + routeId);
}
return checkResult;
}
use of org.onebusaway.admin.model.BundleValidationCheckResult in project onebusaway-application-modules by camsys.
the class RouteQueryResultChecker method checkResults.
@Override
public BundleValidationCheckResult checkResults(BundleValidateQuery query) {
BundleValidationCheckResult checkResult = new BundleValidationCheckResult();
String result = query.getQueryResult();
String route = query.getRouteOrStop();
route = route.toLowerCase();
result = result.toLowerCase();
String routeId = query.getRouteId();
if (routeId.length() == 0) {
routeId = query.getRouteOrStop();
}
if (result.contains(CODE_200) && (result.contains(SHORT_NAME + route) || result.contains(LONG_NAME + route))) {
checkResult.setTestStatus(PASS);
checkResult.setTestResult(query.getErrorMessage() + FOUND_ROUTE_INFO + routeId);
} else {
checkResult.setTestStatus(FAIL);
checkResult.setTestResult(query.getErrorMessage() + DID_NOT_FIND_ROUTE_INFO + routeId);
}
return checkResult;
}
use of org.onebusaway.admin.model.BundleValidationCheckResult in project onebusaway-application-modules by camsys.
the class ScheduleQueryResultChecker method checkResults.
@Override
public BundleValidationCheckResult checkResults(BundleValidateQuery query) {
BundleValidationCheckResult checkResult = new BundleValidationCheckResult();
String result = query.getQueryResult();
if (result.contains(CODE_200) && (result.contains("arrivalEnabled") || result.contains("departureEnabled"))) {
checkResult.setTestStatus(PASS);
checkResult.setTestResult(query.getErrorMessage() + FOUND_SCHEDULE_ENTRIES + query.getStopId());
} else {
checkResult.setTestStatus(FAIL);
checkResult.setTestResult(query.getErrorMessage() + DID_NOT_FIND_SCHEDULE_ENTRIES + query.getStopId());
}
return checkResult;
}
use of org.onebusaway.admin.model.BundleValidationCheckResult in project onebusaway-application-modules by camsys.
the class ScheduleTimeResultChecker method checkResults.
@Override
public BundleValidationCheckResult checkResults(BundleValidateQuery query) {
ObjectMapper mapper = new ObjectMapper();
BundleValidationCheckResult checkResult = new BundleValidationCheckResult();
String result = query.getQueryResult();
mapper.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, true);
Map<String, Object> parsedResult = new HashMap<String, Object>();
boolean parseFailed = false;
try {
parsedResult = mapper.readValue(result, HashMap.class);
} catch (JsonParseException e) {
_log.error("JsonParseException trying to parse query results.");
checkResult.setTestResult("JsonParseException trying to parse query results.");
parseFailed = true;
} catch (JsonMappingException e) {
_log.error("JsonMappingException trying to parse query results.");
checkResult.setTestResult("JsonMappingException trying to parse query results.");
parseFailed = true;
} catch (IOException e) {
_log.error("IOException trying to parse query results.");
checkResult.setTestResult("IOException trying to parse query results.");
parseFailed = true;
}
if (parseFailed) {
checkResult.setTestStatus(FAIL);
return checkResult;
}
Map<String, Object> data = (Map<String, Object>) parsedResult.get("data");
Map<String, Object> entry = (Map<String, Object>) data.get("entry");
int httpCode = (Integer) parsedResult.get("code");
if (httpCode != 200) {
// Call failed or didn't find any schedule entries
checkResult.setTestStatus(FAIL);
checkResult.setTestResult("Http call failed with error " + httpCode);
// checkResult.setTestResult(DID_NOT_FIND_SCHEDULE_ENTRIES + "stop #" + query.getRouteOrStop());
} else {
// Parse the JSON result and create a set of the departure times
Set<Long> departureTimes = new HashSet<Long>();
ArrayList<Map<String, Object>> stopRouteSchedules = (ArrayList<Map<String, Object>>) entry.get("stopRouteSchedules");
for (Map<String, Object> stopRouteSchedule : stopRouteSchedules) {
ArrayList<Map<String, Object>> stopRouteDirectionSchedules = (ArrayList<Map<String, Object>>) stopRouteSchedule.get("stopRouteDirectionSchedules");
for (Map<String, Object> stopRouteDirectionSchedule : stopRouteDirectionSchedules) {
ArrayList<Map<String, Object>> scheduleStopTimes = (ArrayList<Map<String, Object>>) stopRouteDirectionSchedule.get("scheduleStopTimes");
for (Map<String, Object> scheduleStopTime : scheduleStopTimes) {
// Check each departure time
long departureTime = (Long) scheduleStopTime.get("departureTime");
departureTimes.add(departureTime);
}
}
}
// JSON successfully parsed, so continue processing
Long timeInMillis = convertToTimeInMillis(query.getServiceDate(), query.getDepartureTime());
// In case GTFS time has some number of seconds
long timeUpperBound = timeInMillis + (59 * 1000);
// In case GTFS time gets rounded up
long timeLowerBound = timeInMillis - (30 * 1000);
boolean foundTime = false;
for (long departureTime : departureTimes) {
if (departureTime >= timeLowerBound && departureTime <= timeUpperBound) {
foundTime = true;
}
}
if (foundTime) {
checkResult.setTestResult(query.getErrorMessage() + FOUND_SCHEDULE_ENTRIES + query.getStopId() + " at departure time " + query.getDepartureTime());
if (query.getSpecificTest().toLowerCase().equals("stop date at time")) {
checkResult.setTestStatus(PASS);
} else {
checkResult.setTestStatus(FAIL);
}
} else {
// Didn't find a departure at that time
checkResult.setTestResult(query.getErrorMessage() + DID_NOT_FIND_SCHEDULE_ENTRIES + query.getStopId() + " at departure time " + query.getDepartureTime());
if (query.getSpecificTest().toLowerCase().equals("stop date at time")) {
checkResult.setTestStatus(FAIL);
} else {
checkResult.setTestStatus(PASS);
}
}
}
return checkResult;
}
use of org.onebusaway.admin.model.BundleValidationCheckResult in project onebusaway-application-modules by camsys.
the class ValidateBundleAction method checkResults.
public List<BundleValidationCheckResult> checkResults(List<BundleValidateQuery> queryResults) {
List<BundleValidationCheckResult> testResults = new ArrayList<BundleValidationCheckResult>();
int linenum = 1;
for (BundleValidateQuery query : queryResults) {
QueryResultChecker resultChecker = getResultChecker(query.getSpecificTest().toLowerCase());
BundleValidationCheckResult checkResult = resultChecker.checkResults(query);
checkResult.setLinenum(linenum);
checkResult.setCsvLinenum(query.getLinenum());
checkResult.setSpecificTest(query.getSpecificTest());
checkResult.setTestQuery(query.getQuery());
testResults.add(checkResult);
++linenum;
}
return testResults;
}
Aggregations