Search in sources :

Example 1 with BundleValidateQuery

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

the class BuildBundleQueriesServiceImpl method buildQueries.

@Override
public List<BundleValidateQuery> buildQueries(List<ParsedBundleValidationCheck> parsedChecks, String checkEnvironment) {
    if (queryBuilders == null) {
        initQueryBuilders();
    }
    List<BundleValidateQuery> queries = new ArrayList<BundleValidateQuery>();
    String envURI = "";
    if (checkEnvironment.equals(PRODUCTION_ENV)) {
        envURI = getConfigValue("apiProd");
    } else {
        envURI = getConfigValue("apiStaging");
    }
    String apiKey = getConfigValue("apiKey");
    String apiQuery = getConfigValue("apiQuery");
    String siriQuery = getConfigValue("siriQuery");
    for (ParsedBundleValidationCheck check : parsedChecks) {
        BundleValidateQuery validationQuery = new BundleValidateQuery();
        String specificTest = check.getSpecificTest().toLowerCase();
        String query = queryBuilders.get(specificTest) == null ? "" : queryBuilders.get(specificTest).buildQuery(envURI, apiKey, apiQuery, siriQuery, check);
        validationQuery.setLinenum(check.getLinenum());
        validationQuery.setSpecificTest(check.getSpecificTest());
        validationQuery.setRouteOrStop(check.getRouteName());
        validationQuery.setRouteId(check.getRouteId());
        validationQuery.setStopId(check.getStopId());
        validationQuery.setServiceDate(check.getDate());
        validationQuery.setDepartureTime(check.getDepartureTime());
        validationQuery.setQuery(query);
        if (query.isEmpty()) {
            continue;
        } else {
            queries.add(validationQuery);
        }
    }
    return queries;
}
Also used : BundleValidateQuery(org.onebusaway.admin.model.BundleValidateQuery) ArrayList(java.util.ArrayList) ParsedBundleValidationCheck(org.onebusaway.admin.model.ParsedBundleValidationCheck)

Example 2 with BundleValidateQuery

use of org.onebusaway.admin.model.BundleValidateQuery 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)

Example 3 with BundleValidateQuery

use of org.onebusaway.admin.model.BundleValidateQuery 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)

Aggregations

BundleValidateQuery (org.onebusaway.admin.model.BundleValidateQuery)3 ArrayList (java.util.ArrayList)2 BundleValidationCheckResult (org.onebusaway.admin.model.BundleValidationCheckResult)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)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 BundleValidationParseResults (org.onebusaway.admin.model.BundleValidationParseResults)1 ParsedBundleValidationCheck (org.onebusaway.admin.model.ParsedBundleValidationCheck)1