Example usage for org.apache.commons.csv CSVRecord get

List of usage examples for org.apache.commons.csv CSVRecord get

Introduction

In this page you can find the example usage for org.apache.commons.csv CSVRecord get.

Prototype

public String get(final String name) 

Source Link

Document

Returns a value by name.

Usage

From source file:org.asqatasun.referential.creator.CodeGeneratorMojo.java

/**
 *
 * @param ve/*from  w ww  . ja va 2s  .c  om*/
 * @param records
 * @throws java.io.IOException
 */
public void generate(VelocityEngine ve, Iterable<CSVRecord> records)
        throws IOException, ResourceNotFoundException, ParseErrorException, Exception {
    // Getting the Template
    Template ruleTemplate = ve.getTemplate(templateRule.getPath());
    Template pomTemplate = ve.getTemplate(pom.getPath());
    Template webappBeansTemplate = ve.getTemplate(templateBeansWebapp.getPath());
    Template webappBeansExpressionTemplate = ve.getTemplate(templateBeansExpression.getPath());
    Template auditResultConsoleTemplate = ve.getTemplate(templateAuditResultConsole.getPath());
    Template auditSetUpFormTemplate = ve.getTemplate(templateAuditSetUpForm.getPath());
    Template testCaseTemplate = ve.getTemplate(templateTestCase.getPath());
    Template descriptorTemplate = ve.getTemplate(templateDescriptor.getPath());
    Template installTemplate = ve.getTemplate(templateInstallSh.getPath());
    Template unitTestTemplate = ve.getTemplate(templateUnitTest.getPath());
    Template ruleImplementationTestCaseTemplate = ve.getTemplate(templateRuleImplementationTestCase.getPath());
    // Create a context and add data to the templateRule placeholder
    VelocityContext context = new VelocityContext();
    // Fetch templateRule into a StringWriter
    FileGenerator fg = new FileGenerator(referential, referentialLabel, destinationFolder, refDescriptor,
            isCriterionPresent);
    fg.createI18NFiles(langSet);

    // we parse the records collection only once to create the i18n files.
    // These files will be then used later to create other context files
    // using the i18n keys.
    for (CSVRecord record : records) {
        String testLabelDefault = record.get(TEST_LABEL_COLUMN_NAME + langSet.first());
        String test = record.get(TEST_CODE_COLUMN_NAME);
        for (String lang : langSet) {
            writeToI18NFile(fg, record, lang);
        }
        IS_I18N_REFERENTIAL_CREATED = true;
        if (!isCriterionPresent) {
            test = test.concat("-1");
        }
        context = fg.getContextRuleClassFile(referential, PACKAGE_NAME, test, testLabelDefault, context);
        fg.writeFileCodeGenerate(context, ruleTemplate, getClassNameFromCsvColumn(record));
        fg.writeUnitTestGenerate(context, unitTestTemplate, testLabelDefault,
                getClassNameFromCsvColumn(record));
        String[] testsCasesState = { "Passed", "Failed", "NMI", "NA" };
        for (int i = 0; i < testsCasesState.length; i++) {
            context.put("state", testsCasesState[i]);
            fg.writeTestCaseGenerate(context, testCaseTemplate, getClassNameFromCsvColumn(record),
                    String.valueOf(i + 1));
        }
        addLevelAndScopeToList(record);
    }

    fg.createSqlReference();
    fg.createSqlTheme();
    fg.createSqlCritere();
    fg.createSqlTest(levelList, scopeList);
    fg.createSqlParameters();

    fg.writeAuditSetUpFormBeanGenerate(context, auditSetUpFormTemplate);
    fg.writeAuditResultConsoleBeanGenerate(context, auditResultConsoleTemplate);
    fg.writeWebappBeansGenerate(context, webappBeansTemplate);
    fg.writeWebappBeansExpressionGenerate(context, webappBeansExpressionTemplate);
    fg.writeInstallGenerate(context, installTemplate);
    fg.writeDescriptorGenerate(context, descriptorTemplate);
    fg.writeRuleImplementationTestCaseGenerate(context, ruleImplementationTestCaseTemplate);

    fg.adaptPom(context, pomTemplate);
}

From source file:org.asqatasun.referential.creator.CodeGeneratorMojo.java

private void addLevelAndScopeToList(CSVRecord record) {
    try {/*ww w.  j  a  v  a2s .  com*/
        String level = record.get(LEVEL_CODE_COLUMN_NAME);
        if (StringUtils.isBlank(level)) {
            levelList.add("1");
        } else {
            levelList.add(level);
        }
    } catch (IllegalArgumentException iae) {
        levelList.add("1");
    }
    try {
        String scope = record.get(SCOPE_CODE_COLUMN_NAME);
        if (StringUtils.isBlank(scope)) {
            scopeList.add("1");
        } else {
            scopeList.add(scope);
        }
    } catch (IllegalArgumentException iae) {
        scopeList.add("1");
    }
}

From source file:org.asqatasun.referential.creator.CodeGeneratorMojo.java

private String getClassNameFromCsvColumn(CSVRecord record) {
    try {/*from   www. j ava  2s . com*/
        String className = record.get(CLASSNAME_CODE_COLUMN_NAME);
        if (StringUtils.isBlank(className)) {
            return null;
        } else {
            return className.replace(" ", "").replace("-", "");
        }
    } catch (IllegalArgumentException iae) {
        return null;
    }
}

From source file:org.asqatasun.referentiel.creator.CodeGeneratorMojo.java

/**
 *
 * @param ve//  w w w. j  ava2s .  c o  m
 * @param records
 * @throws java.io.IOException
 */
public void generate(VelocityEngine ve, Iterable<CSVRecord> records)
        throws IOException, ResourceNotFoundException, ParseErrorException, Exception {
    // Getting the Template
    Template ruleTemplate = ve.getTemplate(templateRule.getPath());
    Template pomTemplate = ve.getTemplate(pom.getPath());
    Template webappBeansTemplate = ve.getTemplate(templateBeansWebapp.getPath());
    Template webappBeansExpressionTemplate = ve.getTemplate(templateBeansExpression.getPath());
    Template auditResultConsoleTemplate = ve.getTemplate(templateAuditResultConsole.getPath());
    Template auditSetUpFormTemplate = ve.getTemplate(templateAuditSetUpForm.getPath());
    Template testCaseTemplate = ve.getTemplate(templateTestCase.getPath());
    Template descriptorTemplate = ve.getTemplate(templateDescriptor.getPath());
    Template installTemplate = ve.getTemplate(templateInstallSh.getPath());
    Template unitTestTemplate = ve.getTemplate(templateUnitTest.getPath());
    Template ruleImplementationTestCaseTemplate = ve.getTemplate(templateRuleImplementationTestCase.getPath());
    // Create a context and add data to the templateRule placeholder
    VelocityContext context = new VelocityContext();
    // Fetch templateRule into a StringWriter
    FileGenerator fg = new FileGenerator(referentiel, referentielLabel, destinationFolder, refDescriptor,
            isCriterionPresent);
    fg.createI18NFiles(langSet);

    // we parse the records collection only once to create the i18n files.
    // These files will be then used later to create other context files
    // using the i18n keys.
    for (CSVRecord record : records) {
        String testLabelDefault = record.get(TEST_LABEL_COLUMN_NAME + langSet.first());
        String test = record.get(TEST_CODE_COLUMN_NAME);
        for (String lang : langSet) {
            writeToI18NFile(fg, record, lang);
        }
        IS_I18N_REFERENTIAL_CREATED = true;
        if (!isCriterionPresent) {
            test = test.concat("-1");
        }
        context = fg.getContextRuleClassFile(referentiel, PACKAGE_NAME, test, testLabelDefault, context);
        fg.writeFileCodeGenerate(context, ruleTemplate, getClassNameFromCsvColumn(record));
        fg.writeUnitTestGenerate(context, unitTestTemplate, testLabelDefault,
                getClassNameFromCsvColumn(record));
        String[] testsCasesState = { "Passed", "Failed", "NMI", "NA" };
        for (int i = 0; i < testsCasesState.length; i++) {
            context.put("state", testsCasesState[i]);
            fg.writeTestCaseGenerate(context, testCaseTemplate, getClassNameFromCsvColumn(record),
                    String.valueOf(i + 1));
        }
        addLevelAndScopeToList(record);
    }

    fg.createSqlReference();
    fg.createSqlTheme();
    fg.createSqlCritere();
    fg.createSqlTest(levelList, scopeList);
    fg.createSqlParameters();

    fg.writeAuditSetUpFormBeanGenerate(context, auditSetUpFormTemplate);
    fg.writeAuditResultConsoleBeanGenerate(context, auditResultConsoleTemplate);
    fg.writeWebappBeansGenerate(context, webappBeansTemplate);
    fg.writeWebappBeansExpressionGenerate(context, webappBeansExpressionTemplate);
    fg.writeInstallGenerate(context, installTemplate);
    fg.writeDescriptorGenerate(context, descriptorTemplate);
    fg.writeRuleImplementationTestCaseGenerate(context, ruleImplementationTestCaseTemplate);

    fg.adaptPom(context, pomTemplate);
}

From source file:org.asqatasun.rules.doc.utils.exportaw22torgaa3ruledesign.ExtractCsvAndCopy.java

public void copy(Iterable<CSVRecord> records) {
    for (CSVRecord record : records) {
        String targetReference = record.get(TARGET_REFERENTIAL);
        String originalReference = record.get(ORIGINAL_REFERENTIAL);
        String canCopy = record.get(CAN_COPY);
        if (canCopy.equals("1")) {
            String testCode = targetReference.split("-")[1].replace(".", "-");
            String oldTestCode = originalReference.split("-")[1].replace(".", "-");
            try {
                FileUtils.copyFile(getFile(PATH_TO_OLD_HTML_FILE + "Rule-" + oldTestCode + ".html"),
                        getFile(PATH_TO_CREATE_HTML_FILE + "Rule-" + testCode + ".html"));
            } catch (FileNotFoundException ex) {
                System.out.println("Rule missing : " + oldTestCode);
            } catch (IOException ex) {
            }//from   w ww . j  a va 2s  .c om
        }
    }
}

From source file:org.cast.cwm.service.UserSpreadsheetReader.java

protected boolean notEmpty(CSVRecord record, String fieldname) {
    Integer position = headerMap.get(fieldname);
    if (position == null)
        return false;
    String value = record.get(position);
    return (value != null && !value.isEmpty());
}

From source file:org.cast.cwm.service.UserSpreadsheetReader.java

protected String get(CSVRecord record, String fieldname) {
    Integer fieldIndex = headerMap.get(fieldname);
    if (fieldIndex != null)
        return record.get(headerMap.get(fieldname));
    else/*  w  w  w  .j a  v  a2 s.c o m*/
        return null;
}

From source file:org.chanthing.csvtool.xform.LicenseExpirationXform.java

/**
 *  Return a string of form mm/dd/yyyy with the license expiration date from the passed in record
 * and the license number.// w ww. ja v a2s  .c om
 * <p>
 * Needs to be fixed to output the actual last day of the month in question.
 */
public String xform(CSVRecord src) {
    String month = src.get("expmm");
    String year = "20" + src.get("expyy");
    String day = getLastDayInMonth(month, year);
    return month + "/" + day + "/" + year;
}

From source file:org.chanthing.csvtool.xform.NotesFieldXform.java

/**
 *  Return a string consisting of a bulleted list with the make of the car, the state,
 * and the license number./*from   w ww  .  j  av a2  s . com*/
 * <p>
 *  Since we know that the field will contain embedded newlines, we return the value
 * surrounded by double quotes.
 */
public String xform(CSVRecord src) {
    String notesStr = "\"\u2022 " + src.get("make") + "\n" + "\u2022 "
            + State.valueOfAbbreviation(src.get("state")) + "\n" + "\u2022 " + src.get("tag") + "\"";

    return notesStr;
}

From source file:org.chanthing.csvtool.xform.PlanEstimateXform.java

/**
 *  Return a string with the jjj//from  w w w .  ja  v  a 2s . com
 * and the license number.
 * <p>
 * Needs to be fixed to output the actual last day of the month in question.
 */
public String xform(CSVRecord src) {
    String fine = src.get("violFine");
    String decFine = fine.substring(1);

    return decFine.substring(0, decFine.length() - 3);
}