Search in sources :

Example 1 with InvalidParameterException

use of org.asqatasun.referential.creator.exception.InvalidParameterException in project Asqatasun by Asqatasun.

the class CodeGeneratorMojo method execute.

@Override
public void execute() {
    try {
        isContextValid();
    } catch (InvalidParameterException ipe) {
        Logger.getLogger(CodeGeneratorMojo.class.getName()).log(Level.SEVERE, null, ipe);
        return;
    }
    // Initializes engine
    VelocityEngine ve = initializeVelocity();
    Iterable<CSVRecord> records = getCsv();
    if (records == null) {
        return;
    }
    try {
        initializeContext();
        generate(ve, records);
        cleanUpUnusedFiles();
    } catch (IOException ex) {
        Logger.getLogger(CodeGeneratorMojo.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ResourceNotFoundException ex) {
        Logger.getLogger(CodeGeneratorMojo.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ParseErrorException ex) {
        Logger.getLogger(CodeGeneratorMojo.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(CodeGeneratorMojo.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : InvalidParameterException(org.asqatasun.referential.creator.exception.InvalidParameterException) VelocityEngine(org.apache.velocity.app.VelocityEngine) ParseErrorException(org.apache.velocity.exception.ParseErrorException) CSVRecord(org.apache.commons.csv.CSVRecord) IOException(java.io.IOException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException) InvalidParameterException(org.asqatasun.referential.creator.exception.InvalidParameterException) I18NLanguageNotFoundException(org.asqatasun.referential.creator.exception.I18NLanguageNotFoundException) ParseErrorException(org.apache.velocity.exception.ParseErrorException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException)

Example 2 with InvalidParameterException

use of org.asqatasun.referential.creator.exception.InvalidParameterException in project Asqatasun by Asqatasun.

the class CodeGeneratorMojo method writeToI18NFile.

private void writeToI18NFile(FileGenerator fg, CSVRecord record, String lang) throws IOException, InvalidParameterException {
    Integer themeIndex = Integer.valueOf(record.get(THEME_CODE_COLUMN_NAME));
    String theme = record.get(THEME_LABEL_COLUMN_NAME + lang);
    String critere;
    String critereCode;
    String test = record.get(TEST_LABEL_COLUMN_NAME + lang);
    String testCode = record.get(TEST_CODE_COLUMN_NAME);
    if (isCriterionPresent) {
        critere = record.get(CRITERION_LABEL_COLUMN_NAME + lang);
        critereCode = record.get(CRITERION_CODE_COLUMN_NAME);
    } else {
        critere = test;
        critereCode = testCode;
    }
    if (StringUtils.isBlank(theme) || StringUtils.isBlank(critere) || StringUtils.isBlank(critereCode)) {
        throw new InvalidParameterException("Your csv file has an empty column");
    }
    Map themeMap = Collections.singletonMap(themeIndex, theme);
    Map critereMap = Collections.singletonMap(critereCode, critere);
    Map testMap = Collections.singletonMap(testCode, test);
    if (StringUtils.isNotBlank(theme) && StringUtils.isNotBlank(String.valueOf(themeIndex))) {
        fg.writei18NFile(themeMap, lang, langSet.first(), "theme");
    }
    if (StringUtils.isNotBlank(critere) && StringUtils.isNotBlank(critereCode)) {
        fg.writei18NFile(critereMap, lang, langSet.first(), "criterion");
    }
    if (StringUtils.isNotBlank(test) && StringUtils.isNotBlank(testCode)) {
        fg.writei18NFile(testMap, lang, langSet.first(), "rule");
    }
    if (IS_I18N_REFERENTIAL_CREATED == false) {
        fg.writei18NFile(null, lang, langSet.first(), "referential");
    }
}
Also used : InvalidParameterException(org.asqatasun.referential.creator.exception.InvalidParameterException) Map(java.util.Map)

Aggregations

InvalidParameterException (org.asqatasun.referential.creator.exception.InvalidParameterException)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Map (java.util.Map)1 CSVRecord (org.apache.commons.csv.CSVRecord)1 VelocityEngine (org.apache.velocity.app.VelocityEngine)1 ParseErrorException (org.apache.velocity.exception.ParseErrorException)1 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)1 I18NLanguageNotFoundException (org.asqatasun.referential.creator.exception.I18NLanguageNotFoundException)1