@Test(expected = DataImportHandlerException.class) @SuppressWarnings("unchecked") public void testTransformRow_InvalidInput3_Number() { List l = new ArrayList(); l.add(AbstractDataImportHandlerTest.createMap("column", "num", NumberFormatTransformer.FORMAT_STYLE, NumberFormatTransformer.NUMBER)); Context c = AbstractDataImportHandlerTest.getContext(null, null, null, Context.FULL_DUMP, l, null); Map m = AbstractDataImportHandlerTest.createMap( "num", "123" + DECIMAL_SEP + "456" + DECIMAL_SEP + "789"); new NumberFormatTransformer().transformRow(m, c); }
@SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> row, Context context) { VariableResolver resolver = context.getVariableResolver(); for (Map<String, String> fld : context.getAllEntityFields()) { String style = resolver.replaceTokens(fld.get(FORMAT_STYLE)); if (style != null) { String column = fld.get(DataImporter.COLUMN); String srcCol = fld.get(RegexTransformer.SRC_COL_NAME); Locale locale = null; String localeStr = resolver.replaceTokens(fld.get(LOCALE)); if (srcCol == null) srcCol = column; if (localeStr != null) { Matcher matcher = localeRegex.matcher(localeStr); if (matcher.find() && matcher.groupCount() == 2) { locale = new Locale(matcher.group(1), matcher.group(2)); } else { throw new DataImportHandlerException(DataImportHandlerException.SEVERE, "Invalid Locale specified for field: " + fld); } } else { locale = Locale.getDefault(); } Object val = row.get(srcCol); String styleSmall = style.toLowerCase(); if (val instanceof List) { List<String> inputs = (List) val; List results = new ArrayList(); for (String input : inputs) { try { results.add(process(input, styleSmall, locale)); } catch (ParseException e) { throw new DataImportHandlerException( DataImportHandlerException.SEVERE, "Failed to apply NumberFormat on column: " + column, e); } } row.put(column, results); } else { if (val == null || val.toString().trim().equals("")) continue; try { row.put(column, process(val.toString(), styleSmall, locale)); } catch (ParseException e) { throw new DataImportHandlerException( DataImportHandlerException.SEVERE, "Failed to apply NumberFormat on column: " + column, e); } } } } return row; }
NumberFormatTransformer extends Transformer { @SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> row, Context context) { VariableResolver resolver = context.getVariableResolver(); for (Map<String, String> fld : context.getAllEntityFields()) { String style = resolver.replaceTokens(fld.get(FORMAT_STYLE)); if (style != null) { String column = fld.get(DataImporter.COLUMN); String srcCol = fld.get(RegexTransformer.SRC_COL_NAME); Locale locale = null; String localeStr = resolver.replaceTokens(fld.get(LOCALE)); if (srcCol == null) srcCol = column; if (localeStr != null) { Matcher matcher = localeRegex.matcher(localeStr); if (matcher.find() && matcher.groupCount() == 2) { locale = new Locale(matcher.group(1), matcher.group(2)); } else { throw new DataImportHandlerException(DataImportHandlerException.SEVERE, "Invalid Locale specified for field: " + fld); } } else { locale = Locale.getDefault(); } Object val = row.get(srcCol); String styleSmall = style.toLowerCase(); if (val instanceof List) { List<String> inputs = (List) val; List results = new ArrayList(); for (String input : inputs) { try { results.add(process(input, styleSmall, locale)); } catch (ParseException e) { throw new DataImportHandlerException( DataImportHandlerException.SEVERE, "Failed to apply NumberFormat on column: " + column, e); } } row.put(column, results); } else { if (val == null || val.toString().trim().equals("")) continue; try { row.put(column, process(val.toString(), styleSmall, locale)); } catch (ParseException e) { throw new DataImportHandlerException( DataImportHandlerException.SEVERE, "Failed to apply NumberFormat on column: " + column, e); } } } } return row; } }
NumberFormatTransformer extends Transformer { @SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> row, Context context) { VariableResolver resolver = context.getVariableResolver(); for (Map<String, String> fld : context.getAllEntityFields()) { String style = resolver.replaceTokens(fld.get(FORMAT_STYLE)); if (style != null) { String column = fld.get(DataImporter.COLUMN); String srcCol = fld.get(RegexTransformer.SRC_COL_NAME); Locale locale = null; String localeStr = resolver.replaceTokens(fld.get(LOCALE)); if (srcCol == null) srcCol = column; if (localeStr != null) { Matcher matcher = localeRegex.matcher(localeStr); if (matcher.find() && matcher.groupCount() == 2) { locale = new Locale(matcher.group(1), matcher.group(2)); } else { throw new DataImportHandlerException(DataImportHandlerException.SEVERE, "Invalid Locale specified for field: " + fld); } } else { locale = Locale.getDefault(); } Object val = row.get(srcCol); String styleSmall = style.toLowerCase(); if (val instanceof List) { List<String> inputs = (List) val; List results = new ArrayList(); for (String input : inputs) { try { results.add(process(input, styleSmall, locale)); } catch (ParseException e) { throw new DataImportHandlerException( DataImportHandlerException.SEVERE, "Failed to apply NumberFormat on column: " + column, e); } } row.put(column, results); } else { if (val == null || val.toString().trim().equals("")) continue; try { row.put(column, process(val.toString(), styleSmall, locale)); } catch (ParseException e) { throw new DataImportHandlerException( DataImportHandlerException.SEVERE, "Failed to apply NumberFormat on column: " + column, e); } } } } return row; }  }
NumberFormatTransformer extends Transformer { @SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> row, Context context) { VariableResolver resolver = context.getVariableResolver(); for (Map<String, String> fld : context.getAllEntityFields()) { String style = resolver.replaceTokens(fld.get(FORMAT_STYLE)); if (style != null) { String column = fld.get(DataImporter.COLUMN); String srcCol = fld.get(RegexTransformer.SRC_COL_NAME); Locale locale = null; String localeStr = resolver.replaceTokens(fld.get(LOCALE)); if (srcCol == null) srcCol = column; if (localeStr != null) { Matcher matcher = localeRegex.matcher(localeStr); if (matcher.find() && matcher.groupCount() == 2) { locale = new Locale(matcher.group(1), matcher.group(2)); } else { throw new DataImportHandlerException(DataImportHandlerException.SEVERE, "Invalid Locale specified for field: " + fld); } } else { locale = Locale.getDefault(); } Object val = row.get(srcCol); String styleSmall = style.toLowerCase(); if (val instanceof List) { List<String> inputs = (List) val; List results = new ArrayList(); for (String input : inputs) { try { results.add(process(input, styleSmall, locale)); } catch (ParseException e) { throw new DataImportHandlerException( DataImportHandlerException.SEVERE, "Failed to apply NumberFormat on column: " + column, e); } } row.put(column, results); } else { if (val == null || val.toString().trim().equals("")) continue; try { row.put(column, process(val.toString(), styleSmall, locale)); } catch (ParseException e) { throw new DataImportHandlerException( DataImportHandlerException.SEVERE, "Failed to apply NumberFormat on column: " + column, e); } } } } return row; }  @SuppressWarnings("unchecked") Object transformRow(Map<String, Object> row, Context context); }
NumberFormatTransformer extends Transformer { @SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> row, Context context) { VariableResolver resolver = context.getVariableResolver(); for (Map<String, String> fld : context.getAllEntityFields()) { String style = resolver.replaceTokens(fld.get(FORMAT_STYLE)); if (style != null) { String column = fld.get(DataImporter.COLUMN); String srcCol = fld.get(RegexTransformer.SRC_COL_NAME); Locale locale = null; String localeStr = resolver.replaceTokens(fld.get(LOCALE)); if (srcCol == null) srcCol = column; if (localeStr != null) { Matcher matcher = localeRegex.matcher(localeStr); if (matcher.find() && matcher.groupCount() == 2) { locale = new Locale(matcher.group(1), matcher.group(2)); } else { throw new DataImportHandlerException(DataImportHandlerException.SEVERE, "Invalid Locale specified for field: " + fld); } } else { locale = Locale.getDefault(); } Object val = row.get(srcCol); String styleSmall = style.toLowerCase(); if (val instanceof List) { List<String> inputs = (List) val; List results = new ArrayList(); for (String input : inputs) { try { results.add(process(input, styleSmall, locale)); } catch (ParseException e) { throw new DataImportHandlerException( DataImportHandlerException.SEVERE, "Failed to apply NumberFormat on column: " + column, e); } } row.put(column, results); } else { if (val == null || val.toString().trim().equals("")) continue; try { row.put(column, process(val.toString(), styleSmall, locale)); } catch (ParseException e) { throw new DataImportHandlerException( DataImportHandlerException.SEVERE, "Failed to apply NumberFormat on column: " + column, e); } } } } return row; }  @SuppressWarnings("unchecked") Object transformRow(Map<String, Object> row, Context context); static final String FORMAT_STYLE; static final String LOCALE; static final String NUMBER; static final String PERCENT; static final String INTEGER; static final String CURRENCY; }