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;
}
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;
}
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;
}
Aggregations