Example usage for org.apache.commons.csv CSVStrategy EXCEL_STRATEGY

List of usage examples for org.apache.commons.csv CSVStrategy EXCEL_STRATEGY

Introduction

In this page you can find the example usage for org.apache.commons.csv CSVStrategy EXCEL_STRATEGY.

Prototype

CSVStrategy EXCEL_STRATEGY

To view the source code for org.apache.commons.csv CSVStrategy EXCEL_STRATEGY.

Click Source Link

Usage

From source file:xc.mst.services.normalization.NormalizationService.java

protected void setupOrganizationCodeProperties() throws ServiceValidationException {
    int num001Properties = 0;
    boolean valid = true;
    try {//w  ww  . ja  v a 2s .c  o  m
        num001Properties = Integer.parseInt(enabledSteps.getProperty("001Config.NumberOfRows"));
    } catch (NumberFormatException nfe) {
        valid = false;
    }
    if (num001Properties < 1)
        valid = false;
    if (!valid) {
        throw new ServiceValidationException(
                "Service configuration file Organization Code error: 001Config.NumberOfRows must be an integer value greater than zero.");
    }
    orgCodeProperties001 = new HashMap<String, HashMap<String, String>>(num001Properties);
    // # 001Config.<row>=<Source_repository_URL>,<Supply_001_for_Bib>,<Check_for_Holdings_001>
    HashMap<String, String> uniqueURLs = new HashMap<String, String>(num001Properties);
    for (int i = 1; i <= num001Properties; i++) {
        String row = enabledSteps.getProperty("001Config." + i);
        CSVParser csv = new CSVParser(new StringReader(row), CSVStrategy.EXCEL_STRATEGY);
        try {
            String values[] = csv.getLine();
            if (values.length != 3) {
                throw new ServiceValidationException(
                        "Service configuration file Organization Code error: Couldn't parse 001Config row: expecting 3 values separated by commas.");
            }

            if (uniqueURLs.containsKey(values[0])) {
                throw new ServiceValidationException(
                        "Service configuration file Organization Code error: <Source_repository_URLs> must all be unique.");
            }
            uniqueURLs.put(values[0], values[0]);

            HashMap<String, String> hm = new HashMap<String, String>(2);

            String[] yn = { "Y", "N" };
            ValidateSOCConfig(true, "Supply_001_for_Bib", values[1], yn);
            hm.put("Supply_001_for_Bib", values[1]);

            ValidateSOCConfig(true, "Check_for_Holdings_001", values[2], yn);
            hm.put("Check_for_Holdings_001", values[2]);

            orgCodeProperties001.put(values[0], hm);
        } catch (IOException e) {
            throw new ServiceValidationException(
                    "Service configuration file Organization Code error: Couldn't parse 001Config row: "
                            + e.getMessage());
        }
    }

    int num003Properties = 0;
    try {
        num003Properties = Integer.parseInt(enabledSteps.getProperty("003Config.NumberOfRows"));
    } catch (NumberFormatException nfe) {
        valid = false;
    }
    if (num003Properties < 1)
        valid = false;
    if (!valid) {
        throw new ServiceValidationException(
                "Service configuration file Organization Code error: 003Config.NumberOfRows must be an integer value greater than zero.");
    }
    orgCodeProperties003 = new HashMap<String, HashMap<String, String>>(num003Properties);
    // # 003Config.<row>=<Source repository_URL>,<MARC_Org_Code>,<Check_Bib_003>,<Overwrite_Bib_003>,<Check_Holdings_003>,<Overwrite_Holdings_003>
    uniqueURLs = new HashMap<String, String>(num003Properties);
    for (int i = 1; i <= num003Properties; i++) {
        String row = enabledSteps.getProperty("003Config." + i);
        CSVParser csv = new CSVParser(new StringReader(row), CSVStrategy.EXCEL_STRATEGY);
        try {
            String values[] = csv.getLine();
            if (values.length != 6) {
                throw new ServiceValidationException(
                        "Service configuration file Organization Code error: Couldn't parse 003Config row: expecting 6 values separated by commas.");
            }

            if (uniqueURLs.containsKey(values[0])) {
                throw new ServiceValidationException(
                        "Service configuration file Organization Code error: <Source_repository_URLs> must all be unique.");
            }
            uniqueURLs.put(values[0], values[0]);

            HashMap<String, String> hm = new HashMap<String, String>(5);

            if (values[1].length() < 1)
                ValidateSOCConfig(false, "MARC_Org_Code", null, null);
            hm.put("MARC_Org_Code", values[1]);

            String[] ynm0 = { "Y", "N", "M", "0" };
            ValidateSOCConfig(false, "Check_Bib_003", values[2], ynm0);
            hm.put("Check_Bib_003", values[2]);

            String[] yn = { "Y", "N" };
            ValidateSOCConfig(false, "Overwrite_Bib_003", values[3], yn);
            hm.put("Overwrite_Bib_003", values[3]);

            ValidateSOCConfig(false, "Check_Holdings_003", values[4], ynm0);
            hm.put("Check_Holdings_003", values[4]);

            ValidateSOCConfig(false, "Overwrite_Holdings_003", values[5], yn);
            hm.put("Overwrite_Holdings_003", values[5]);

            orgCodeProperties003.put(values[0], hm);
        } catch (IOException e) {
            throw new ServiceValidationException(
                    "Service configuration file Organization Code error: Couldn't parse 003Config row: "
                            + e.getMessage());
        }
    }

}