Search in sources :

Example 1 with BundleValidationParseError

use of org.onebusaway.admin.model.BundleValidationParseError 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 2 with BundleValidationParseError

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

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