@Test public void testMapperDate_noDatePattern() { LOG.info("testMapperDate_noDatePattern()"); Map<String, Object> mapConfigs = new HashMap<>(); mapConfigs.put("some_param", "some_value"); MapperDate mapperDate = new MapperDate(); assertFalse("Was able to initialize!", mapperDate.init(null, "someField", null, mapConfigs)); }
@Override public boolean init(String inputDesc, String fieldName, String mapClassCode, Object mapConfigs) { init(inputDesc, fieldName, mapClassCode); if (!(mapConfigs instanceof Map)) { LOG.fatal("Can't initialize object. mapConfigs class is not of type Map. " + mapConfigs.getClass().getName() + ", map=" + this); return false; } @SuppressWarnings("unchecked") Map<String, Object> mapObjects = (Map<String, Object>) mapConfigs; String targetDateFormat = (String) mapObjects.get("target_date_pattern"); String srcDateFormat = (String) mapObjects.get("src_date_pattern"); if (StringUtils.isEmpty(targetDateFormat)) { LOG.fatal("Date format for map is empty. " + this); } else { LOG.info("Date mapper format is " + targetDateFormat); if (targetDateFormat.equalsIgnoreCase("epoch")) { isEpoch = true; return true; } else { try { targetDateFormatter = new SimpleDateFormat(targetDateFormat); if (!StringUtils.isEmpty(srcDateFormat)) { srcDateFormatter = new SimpleDateFormat(srcDateFormat); } return true; } catch (Throwable ex) { LOG.fatal("Error creating date format. format=" + targetDateFormat + ". " + this.toString()); } } } return false; }
MapperDate extends Mapper { @Override public boolean init(String inputDesc, String fieldName, String mapClassCode, Object mapConfigs) { init(inputDesc, fieldName, mapClassCode); if (!(mapConfigs instanceof Map)) { LOG.fatal("Can't initialize object. mapConfigs class is not of type Map. " + mapConfigs.getClass().getName() + ", map=" + this); return false; } @SuppressWarnings("unchecked") Map<String, Object> mapObjects = (Map<String, Object>) mapConfigs; String targetDateFormat = (String) mapObjects.get("target_date_pattern"); String srcDateFormat = (String) mapObjects.get("src_date_pattern"); if (StringUtils.isEmpty(targetDateFormat)) { LOG.fatal("Date format for map is empty. " + this); } else { LOG.info("Date mapper format is " + targetDateFormat); if (targetDateFormat.equalsIgnoreCase("epoch")) { isEpoch = true; return true; } else { try { targetDateFormatter = new SimpleDateFormat(targetDateFormat); if (!StringUtils.isEmpty(srcDateFormat)) { srcDateFormatter = new SimpleDateFormat(srcDateFormat); } return true; } catch (Throwable ex) { LOG.fatal("Error creating date format. format=" + targetDateFormat + ". " + this.toString()); } } } return false; } }
MapperDate extends Mapper { @Override public boolean init(String inputDesc, String fieldName, String mapClassCode, Object mapConfigs) { init(inputDesc, fieldName, mapClassCode); if (!(mapConfigs instanceof Map)) { LOG.fatal("Can't initialize object. mapConfigs class is not of type Map. " + mapConfigs.getClass().getName() + ", map=" + this); return false; } @SuppressWarnings("unchecked") Map<String, Object> mapObjects = (Map<String, Object>) mapConfigs; String targetDateFormat = (String) mapObjects.get("target_date_pattern"); String srcDateFormat = (String) mapObjects.get("src_date_pattern"); if (StringUtils.isEmpty(targetDateFormat)) { LOG.fatal("Date format for map is empty. " + this); } else { LOG.info("Date mapper format is " + targetDateFormat); if (targetDateFormat.equalsIgnoreCase("epoch")) { isEpoch = true; return true; } else { try { targetDateFormatter = new SimpleDateFormat(targetDateFormat); if (!StringUtils.isEmpty(srcDateFormat)) { srcDateFormatter = new SimpleDateFormat(srcDateFormat); } return true; } catch (Throwable ex) { LOG.fatal("Error creating date format. format=" + targetDateFormat + ". " + this.toString()); } } } return false; }  }
MapperDate extends Mapper { @Override public boolean init(String inputDesc, String fieldName, String mapClassCode, Object mapConfigs) { init(inputDesc, fieldName, mapClassCode); if (!(mapConfigs instanceof Map)) { LOG.fatal("Can't initialize object. mapConfigs class is not of type Map. " + mapConfigs.getClass().getName() + ", map=" + this); return false; } @SuppressWarnings("unchecked") Map<String, Object> mapObjects = (Map<String, Object>) mapConfigs; String targetDateFormat = (String) mapObjects.get("target_date_pattern"); String srcDateFormat = (String) mapObjects.get("src_date_pattern"); if (StringUtils.isEmpty(targetDateFormat)) { LOG.fatal("Date format for map is empty. " + this); } else { LOG.info("Date mapper format is " + targetDateFormat); if (targetDateFormat.equalsIgnoreCase("epoch")) { isEpoch = true; return true; } else { try { targetDateFormatter = new SimpleDateFormat(targetDateFormat); if (!StringUtils.isEmpty(srcDateFormat)) { srcDateFormatter = new SimpleDateFormat(srcDateFormat); } return true; } catch (Throwable ex) { LOG.fatal("Error creating date format. format=" + targetDateFormat + ". " + this.toString()); } } } return false; }  @Override boolean init(String inputDesc, String fieldName, String mapClassCode, Object mapConfigs); @Override Object apply(Map<String, Object> jsonObj, Object value); }
MapperDate extends Mapper { @Override public boolean init(String inputDesc, String fieldName, String mapClassCode, Object mapConfigs) { init(inputDesc, fieldName, mapClassCode); if (!(mapConfigs instanceof Map)) { LOG.fatal("Can't initialize object. mapConfigs class is not of type Map. " + mapConfigs.getClass().getName() + ", map=" + this); return false; } @SuppressWarnings("unchecked") Map<String, Object> mapObjects = (Map<String, Object>) mapConfigs; String targetDateFormat = (String) mapObjects.get("target_date_pattern"); String srcDateFormat = (String) mapObjects.get("src_date_pattern"); if (StringUtils.isEmpty(targetDateFormat)) { LOG.fatal("Date format for map is empty. " + this); } else { LOG.info("Date mapper format is " + targetDateFormat); if (targetDateFormat.equalsIgnoreCase("epoch")) { isEpoch = true; return true; } else { try { targetDateFormatter = new SimpleDateFormat(targetDateFormat); if (!StringUtils.isEmpty(srcDateFormat)) { srcDateFormatter = new SimpleDateFormat(srcDateFormat); } return true; } catch (Throwable ex) { LOG.fatal("Error creating date format. format=" + targetDateFormat + ". " + this.toString()); } } } return false; }  @Override boolean init(String inputDesc, String fieldName, String mapClassCode, Object mapConfigs); @Override Object apply(Map<String, Object> jsonObj, Object value);  }