Search in sources :

Example 1 with BundleValidationCheckResult

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;
}
Also used : BundleValidationCheckResult(org.onebusaway.admin.model.BundleValidationCheckResult)

Example 2 with BundleValidationCheckResult

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;
}
Also used : BundleValidationCheckResult(org.onebusaway.admin.model.BundleValidationCheckResult)

Example 3 with BundleValidationCheckResult

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;
}
Also used : BundleValidationCheckResult(org.onebusaway.admin.model.BundleValidationCheckResult)

Example 4 with BundleValidationCheckResult

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;
}
Also used : HashMap(java.util.HashMap) BundleValidationCheckResult(org.onebusaway.admin.model.BundleValidationCheckResult) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) HashSet(java.util.HashSet)

Example 5 with BundleValidationCheckResult

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;
}
Also used : BundleValidationCheckResult(org.onebusaway.admin.model.BundleValidationCheckResult) BundleValidateQuery(org.onebusaway.admin.model.BundleValidateQuery) ArrayList(java.util.ArrayList)

Aggregations

BundleValidationCheckResult (org.onebusaway.admin.model.BundleValidationCheckResult)9 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JsonParseException (org.codehaus.jackson.JsonParseException)2 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 BundleValidateQuery (org.onebusaway.admin.model.BundleValidateQuery)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 BundleValidationParseResults (org.onebusaway.admin.model.BundleValidationParseResults)1