@Test @SuppressWarnings("unchecked") public void testTransformRow_SingleRow() throws Exception { List fields = new ArrayList(); fields.add(AbstractDataImportHandlerTest.createMap(DataImporter.COLUMN, "lastModified")); fields.add(AbstractDataImportHandlerTest.createMap(DataImporter.COLUMN, "dateAdded", RegexTransformer.SRC_COL_NAME, "lastModified", DateFormatTransformer.DATE_TIME_FMT, "MM/dd/yyyy")); SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); Date now = format.parse(format.format(new Date())); Map row = AbstractDataImportHandlerTest.createMap("lastModified", format .format(now)); VariableResolverImpl resolver = new VariableResolverImpl(); resolver.addNamespace("e", row); Context context = AbstractDataImportHandlerTest.getContext(null, resolver, null, Context.FULL_DUMP, fields, null); new DateFormatTransformer().transformRow(row, context); Assert.assertEquals(now, row.get("dateAdded")); }
@SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> aRow, Context context) { for (Map<String, String> map : context.getAllEntityFields()) { String fmt = map.get(DATE_TIME_FMT); if (fmt == null) continue; String column = map.get(DataImporter.COLUMN); String srcCol = map.get(RegexTransformer.SRC_COL_NAME); if (srcCol == null) srcCol = column; try { Object o = aRow.get(srcCol); if (o instanceof List) { List inputs = (List) o; List<Date> results = new ArrayList<Date>(); for (Object input : inputs) { results.add(process(input, fmt)); } aRow.put(column, results); } else { if (o != null) { aRow.put(column, process(o, fmt)); } } } catch (ParseException e) { LOG.warn("Could not parse a Date field ", e); } } return aRow; }
DateFormatTransformer extends Transformer { @SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> aRow, Context context) { for (Map<String, String> map : context.getAllEntityFields()) { String fmt = map.get(DATE_TIME_FMT); if (fmt == null) continue; String column = map.get(DataImporter.COLUMN); String srcCol = map.get(RegexTransformer.SRC_COL_NAME); if (srcCol == null) srcCol = column; try { Object o = aRow.get(srcCol); if (o instanceof List) { List inputs = (List) o; List<Date> results = new ArrayList<Date>(); for (Object input : inputs) { results.add(process(input, fmt)); } aRow.put(column, results); } else { if (o != null) { aRow.put(column, process(o, fmt)); } } } catch (ParseException e) { LOG.warn("Could not parse a Date field ", e); } } return aRow; } }
DateFormatTransformer extends Transformer { @SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> aRow, Context context) { for (Map<String, String> map : context.getAllEntityFields()) { String fmt = map.get(DATE_TIME_FMT); if (fmt == null) continue; String column = map.get(DataImporter.COLUMN); String srcCol = map.get(RegexTransformer.SRC_COL_NAME); if (srcCol == null) srcCol = column; try { Object o = aRow.get(srcCol); if (o instanceof List) { List inputs = (List) o; List<Date> results = new ArrayList<Date>(); for (Object input : inputs) { results.add(process(input, fmt)); } aRow.put(column, results); } else { if (o != null) { aRow.put(column, process(o, fmt)); } } } catch (ParseException e) { LOG.warn("Could not parse a Date field ", e); } } return aRow; }  }
DateFormatTransformer extends Transformer { @SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> aRow, Context context) { for (Map<String, String> map : context.getAllEntityFields()) { String fmt = map.get(DATE_TIME_FMT); if (fmt == null) continue; String column = map.get(DataImporter.COLUMN); String srcCol = map.get(RegexTransformer.SRC_COL_NAME); if (srcCol == null) srcCol = column; try { Object o = aRow.get(srcCol); if (o instanceof List) { List inputs = (List) o; List<Date> results = new ArrayList<Date>(); for (Object input : inputs) { results.add(process(input, fmt)); } aRow.put(column, results); } else { if (o != null) { aRow.put(column, process(o, fmt)); } } } catch (ParseException e) { LOG.warn("Could not parse a Date field ", e); } } return aRow; }  @SuppressWarnings("unchecked") Object transformRow(Map<String, Object> aRow, Context context); }
DateFormatTransformer extends Transformer { @SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> aRow, Context context) { for (Map<String, String> map : context.getAllEntityFields()) { String fmt = map.get(DATE_TIME_FMT); if (fmt == null) continue; String column = map.get(DataImporter.COLUMN); String srcCol = map.get(RegexTransformer.SRC_COL_NAME); if (srcCol == null) srcCol = column; try { Object o = aRow.get(srcCol); if (o instanceof List) { List inputs = (List) o; List<Date> results = new ArrayList<Date>(); for (Object input : inputs) { results.add(process(input, fmt)); } aRow.put(column, results); } else { if (o != null) { aRow.put(column, process(o, fmt)); } } } catch (ParseException e) { LOG.warn("Could not parse a Date field ", e); } } return aRow; }  @SuppressWarnings("unchecked") Object transformRow(Map<String, Object> aRow, Context context); static final String DATE_TIME_FMT; }