Search in sources :

Example 1 with ParsedBundleValidationCheck

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

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

the class BundleCheckParserServiceImpl method parseRecord.

private BundleValidationParseResults parseRecord(CSVRecord record, BundleValidationParseResults parseResults) {
    // Verify that second field contains a valid test.
    if (record.size() < 2 || !validTests.contains(record.get(1).toLowerCase())) {
        BundleValidationParseError parseError = new BundleValidationParseError();
        parseError.setLinenum((int) record.getRecordNumber());
        parseError.setErrorMessage(PARSE_ERROR);
        parseError.setOffendingLine(record.toString());
        parseResults.getParseErrors().add(parseError);
        return parseResults;
    }
    ParsedBundleValidationCheck parsedCheck = new ParsedBundleValidationCheck();
    parsedCheck.setLinenum((int) record.getRecordNumber());
    parsedCheck.setAgencyId(record.get(0));
    parsedCheck.setSpecificTest(record.get(1));
    if (record.get(2) != null) {
        parsedCheck.setRouteName(record.get(2));
    }
    if (record.get(3) != null) {
        parsedCheck.setRouteId(record.get(3));
    }
    if (record.get(4) != null) {
        parsedCheck.setStopName(record.get(4));
    }
    if (record.get(5) != null) {
        parsedCheck.setStopId(record.get(5));
    }
    if (record.get(6) != null) {
        parsedCheck.setDate(record.get(6));
    }
    if (record.get(7) != null) {
        parsedCheck.setDepartureTime(record.get(7));
    }
    parseResults.getParsedBundleChecks().add(parsedCheck);
    return parseResults;
}
Also used : BundleValidationParseError(org.onebusaway.admin.model.BundleValidationParseError) ParsedBundleValidationCheck(org.onebusaway.admin.model.ParsedBundleValidationCheck)

Example 3 with ParsedBundleValidationCheck

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

the class BundleCheckParserServiceImpl method parseBundleChecksFile.

@Override
public BundleValidationParseResults parseBundleChecksFile(Reader csvDataFile) {
    // Create set of valid tests
    List<ParsedBundleValidationCheck> parsedChecks = new ArrayList<ParsedBundleValidationCheck>();
    List<BundleValidationParseError> parseErrors = new ArrayList<BundleValidationParseError>();
    BundleValidationParseResults parseResults = new BundleValidationParseResults();
    parseResults.setParsedBundleChecks(parsedChecks);
    parseResults.setParseErrors(parseErrors);
    try {
        int linenum = 0;
        for (CSVRecord record : CSVFormat.DEFAULT.parse(csvDataFile)) {
            ++linenum;
            parseResults = parseRecord(record, parseResults);
        }
    } catch (FileNotFoundException e) {
        _log.info("Exception parsing csv file ", e);
        e.printStackTrace();
    } catch (IOException e) {
        _log.info("Exception parsing csv file ", e);
        e.printStackTrace();
    }
    return parseResults;
}
Also used : BundleValidationParseError(org.onebusaway.admin.model.BundleValidationParseError) ParsedBundleValidationCheck(org.onebusaway.admin.model.ParsedBundleValidationCheck) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) BundleValidationParseResults(org.onebusaway.admin.model.BundleValidationParseResults) CSVRecord(org.apache.commons.csv.CSVRecord) IOException(java.io.IOException)

Aggregations

ParsedBundleValidationCheck (org.onebusaway.admin.model.ParsedBundleValidationCheck)3 ArrayList (java.util.ArrayList)2 BundleValidationParseError (org.onebusaway.admin.model.BundleValidationParseError)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 CSVRecord (org.apache.commons.csv.CSVRecord)1 BundleValidateQuery (org.onebusaway.admin.model.BundleValidateQuery)1 BundleValidationParseResults (org.onebusaway.admin.model.BundleValidationParseResults)1