Search in sources :

Example 1 with BundleValidationParseResults

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

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

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