Search in sources :

Example 6 with BundleValidationCheckResult

use of org.onebusaway.admin.model.BundleValidationCheckResult in project onebusaway-application-modules by camsys.

the class RealtimeQueryResultChecker method checkResults.

@Override
public BundleValidationCheckResult checkResults(BundleValidateQuery query) {
    BundleValidationCheckResult checkResult = new BundleValidationCheckResult();
    String result = query.getQueryResult();
    if (result.contains("ExpectedArrival") || result.contains("ExpectedDeparture")) {
        checkResult.setTestStatus(PASS);
        checkResult.setTestResult(query.getErrorMessage() + FOUND_REALTIME_INFO + query.getStopId());
    } else {
        checkResult.setTestStatus(FAIL);
        checkResult.setTestResult(query.getErrorMessage() + DID_NOT_FIND_REALTIME_INFO + query.getStopId());
    }
    return checkResult;
}
Also used : BundleValidationCheckResult(org.onebusaway.admin.model.BundleValidationCheckResult)

Example 7 with BundleValidationCheckResult

use of org.onebusaway.admin.model.BundleValidationCheckResult in project onebusaway-application-modules by camsys.

the class StopForRouteResultChecker 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;
    }
    // JSON successfully parsed, so continue processing
    int httpCode = (Integer) parsedResult.get("code");
    Map<String, Object> data = (Map<String, Object>) parsedResult.get("data");
    Map<String, Object> entry = (Map<String, Object>) data.get("entry");
    ArrayList<Object> routeIds = (ArrayList<Object>) entry.get("routeIds");
    if (httpCode != 200 || routeIds == null || routeIds.size() == 0) {
        // Call failed or didn't find any route entries
        checkResult.setTestStatus(FAIL);
        checkResult.setTestResult(query.getErrorMessage() + "Did not find any routes for stop #" + query.getStopId());
    } else {
        // Succeeded at finding stop info, but does it include this route?
        if (routeIds.contains(query.getRouteId())) {
            checkResult.setTestResult(query.getErrorMessage() + "Found stop #" + query.getStopId() + " on Route #" + query.getRouteId());
            if (query.getSpecificTest().toLowerCase().equals("stop for route")) {
                checkResult.setTestStatus(PASS);
            } else {
                checkResult.setTestStatus(FAIL);
            }
        } else {
            // Didn't find that route for that stop
            checkResult.setTestResult(query.getErrorMessage() + "Did not find stop #" + query.getStopId() + " on Route #" + query.getRouteId());
            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) Map(java.util.Map) HashMap(java.util.HashMap) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 8 with BundleValidationCheckResult

use of org.onebusaway.admin.model.BundleValidationCheckResult in project onebusaway-application-modules by camsys.

the class ValidateBundleAction method runValidateBundle.

/**
 * Uploads the bundle validate checks and uses them to test the validity of the bundle
 */
public String runValidateBundle() {
    File inputFile;
    Path csvTarget = null;
    Reader csvInputFile = null;
    if (wikiUrl.length() > 0) {
        URL wikiInputUrl;
        try {
            wikiInputUrl = new URL(wikiUrl);
            csvInputFile = new BufferedReader(new InputStreamReader(wikiInputUrl.openStream()));
        } catch (MalformedURLException e) {
            return "bundleValidationResults";
        } catch (IOException e) {
            e.printStackTrace();
            return "bundleValidationResults";
        }
    } else if (csvFile.length() > 0) {
        csvTarget = uploadCsvFile(csvFile);
        inputFile = csvTarget.toFile();
        try {
            csvInputFile = new FileReader(inputFile);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return "bundleValidationResults";
        }
    } else {
        return "bundleValidationResults";
    }
    BundleValidationParseResults parseResults = _bundleCheckParserService.parseBundleChecksFile(csvInputFile);
    List<BundleValidateQuery> queryResults = _buildBundleQueriesService.buildQueries(parseResults.getParsedBundleChecks(), checkEnvironment);
    for (BundleValidateQuery query : queryResults) {
        String queryResult = getQueryResult(query);
        query.setQueryResult(queryResult);
    }
    List<BundleValidationCheckResult> checkResults = checkResults(queryResults);
    if (csvTarget != null) {
        try {
            Files.delete(csvTarget);
        } catch (IOException e) {
            _log.error("Exception while trying to delete temp .csv file");
            e.printStackTrace();
        }
    }
    bundleValidationResults = checkResults;
    return "bundleValidationResults";
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) InputStreamReader(java.io.InputStreamReader) BundleValidationCheckResult(org.onebusaway.admin.model.BundleValidationCheckResult) BundleValidateQuery(org.onebusaway.admin.model.BundleValidateQuery) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) BundleValidationParseResults(org.onebusaway.admin.model.BundleValidationParseResults) IOException(java.io.IOException) URL(java.net.URL) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File)

Example 9 with BundleValidationCheckResult

use of org.onebusaway.admin.model.BundleValidationCheckResult in project onebusaway-application-modules by camsys.

the class WeekendScheduleQueryResultChecker 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(FOUND_SCHEDULE_ENTRIES);
    } else {
        checkResult.setTestStatus(FAIL);
        checkResult.setTestResult(DID_NOT_FIND_SCHEDULE_ENTRIES);
    }
    return checkResult;
}
Also used : BundleValidationCheckResult(org.onebusaway.admin.model.BundleValidationCheckResult)

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