@Test public void temporalMapperTest() { String rawEventDate = "2019-01-01"; Long eventDate = LocalDate.of(2019, 1, 1).atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli(); TemporalRecord temporalRecord = TemporalRecord.newBuilder() .setId("1") .setDay(1) .setYear(2019) .setMonth(1) .setStartDayOfYear(1) .setEventDate(EventDate.newBuilder().setLte(rawEventDate).build()) .setDateIdentified(rawEventDate) .setModified(rawEventDate) .build(); OccurrenceHdfsRecord hdfsRecord = toOccurrenceHdfsRecord(temporalRecord); Assert.assertEquals(Integer.valueOf(1), hdfsRecord.getDay()); Assert.assertEquals(Integer.valueOf(1), hdfsRecord.getMonth()); Assert.assertEquals(Integer.valueOf(2019), hdfsRecord.getYear()); Assert.assertEquals("1", hdfsRecord.getStartdayofyear()); Assert.assertEquals(eventDate, hdfsRecord.getEventdate()); Assert.assertEquals(eventDate, hdfsRecord.getDateidentified()); Assert.assertEquals(eventDate, hdfsRecord.getModified()); }
private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> temporalMapper() { return (hr, sr) -> { TemporalRecord tr = (TemporalRecord) sr; Optional.ofNullable(tr.getDateIdentified()) .map(STRING_TO_DATE) .ifPresent(date -> hr.setDateidentified(date.getTime())); Optional.ofNullable(tr.getModified()) .map(STRING_TO_DATE) .ifPresent(date -> hr.setModified(date.getTime())); hr.setDay(tr.getDay()); hr.setMonth(tr.getMonth()); hr.setYear(tr.getYear()); if (Objects.nonNull(tr.getStartDayOfYear())) { hr.setStartdayofyear(tr.getStartDayOfYear().toString()); } else { hr.setStartdayofyear(null); } if (Objects.nonNull(tr.getEndDayOfYear())) { hr.setEnddayofyear(tr.getEndDayOfYear().toString()); } else { hr.setEnddayofyear(null); } if (tr.getEventDate() != null && tr.getEventDate().getGte() != null) { Optional.ofNullable(tr.getEventDate().getGte()) .map(STRING_TO_DATE) .ifPresent(eventDate -> hr.setEventdate(eventDate.getTime())); } else { TemporalUtils.getTemporal(tr.getYear(), tr.getMonth(), tr.getDay()) .map(TEMPORAL_TO_DATE) .ifPresent(eventDate -> hr.setEventdate(eventDate.getTime())); } setCreatedIfGreater(hr, tr.getCreated()); addIssues(tr.getIssues(), hr); }; }
OccurrenceHdfsRecordConverter { private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> temporalMapper() { return (hr, sr) -> { TemporalRecord tr = (TemporalRecord) sr; Optional.ofNullable(tr.getDateIdentified()) .map(STRING_TO_DATE) .ifPresent(date -> hr.setDateidentified(date.getTime())); Optional.ofNullable(tr.getModified()) .map(STRING_TO_DATE) .ifPresent(date -> hr.setModified(date.getTime())); hr.setDay(tr.getDay()); hr.setMonth(tr.getMonth()); hr.setYear(tr.getYear()); if (Objects.nonNull(tr.getStartDayOfYear())) { hr.setStartdayofyear(tr.getStartDayOfYear().toString()); } else { hr.setStartdayofyear(null); } if (Objects.nonNull(tr.getEndDayOfYear())) { hr.setEnddayofyear(tr.getEndDayOfYear().toString()); } else { hr.setEnddayofyear(null); } if (tr.getEventDate() != null && tr.getEventDate().getGte() != null) { Optional.ofNullable(tr.getEventDate().getGte()) .map(STRING_TO_DATE) .ifPresent(eventDate -> hr.setEventdate(eventDate.getTime())); } else { TemporalUtils.getTemporal(tr.getYear(), tr.getMonth(), tr.getDay()) .map(TEMPORAL_TO_DATE) .ifPresent(eventDate -> hr.setEventdate(eventDate.getTime())); } setCreatedIfGreater(hr, tr.getCreated()); addIssues(tr.getIssues(), hr); }; } }
OccurrenceHdfsRecordConverter { private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> temporalMapper() { return (hr, sr) -> { TemporalRecord tr = (TemporalRecord) sr; Optional.ofNullable(tr.getDateIdentified()) .map(STRING_TO_DATE) .ifPresent(date -> hr.setDateidentified(date.getTime())); Optional.ofNullable(tr.getModified()) .map(STRING_TO_DATE) .ifPresent(date -> hr.setModified(date.getTime())); hr.setDay(tr.getDay()); hr.setMonth(tr.getMonth()); hr.setYear(tr.getYear()); if (Objects.nonNull(tr.getStartDayOfYear())) { hr.setStartdayofyear(tr.getStartDayOfYear().toString()); } else { hr.setStartdayofyear(null); } if (Objects.nonNull(tr.getEndDayOfYear())) { hr.setEnddayofyear(tr.getEndDayOfYear().toString()); } else { hr.setEnddayofyear(null); } if (tr.getEventDate() != null && tr.getEventDate().getGte() != null) { Optional.ofNullable(tr.getEventDate().getGte()) .map(STRING_TO_DATE) .ifPresent(eventDate -> hr.setEventdate(eventDate.getTime())); } else { TemporalUtils.getTemporal(tr.getYear(), tr.getMonth(), tr.getDay()) .map(TEMPORAL_TO_DATE) .ifPresent(eventDate -> hr.setEventdate(eventDate.getTime())); } setCreatedIfGreater(hr, tr.getCreated()); addIssues(tr.getIssues(), hr); }; }  }
OccurrenceHdfsRecordConverter { private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> temporalMapper() { return (hr, sr) -> { TemporalRecord tr = (TemporalRecord) sr; Optional.ofNullable(tr.getDateIdentified()) .map(STRING_TO_DATE) .ifPresent(date -> hr.setDateidentified(date.getTime())); Optional.ofNullable(tr.getModified()) .map(STRING_TO_DATE) .ifPresent(date -> hr.setModified(date.getTime())); hr.setDay(tr.getDay()); hr.setMonth(tr.getMonth()); hr.setYear(tr.getYear()); if (Objects.nonNull(tr.getStartDayOfYear())) { hr.setStartdayofyear(tr.getStartDayOfYear().toString()); } else { hr.setStartdayofyear(null); } if (Objects.nonNull(tr.getEndDayOfYear())) { hr.setEnddayofyear(tr.getEndDayOfYear().toString()); } else { hr.setEnddayofyear(null); } if (tr.getEventDate() != null && tr.getEventDate().getGte() != null) { Optional.ofNullable(tr.getEventDate().getGte()) .map(STRING_TO_DATE) .ifPresent(eventDate -> hr.setEventdate(eventDate.getTime())); } else { TemporalUtils.getTemporal(tr.getYear(), tr.getMonth(), tr.getDay()) .map(TEMPORAL_TO_DATE) .ifPresent(eventDate -> hr.setEventdate(eventDate.getTime())); } setCreatedIfGreater(hr, tr.getCreated()); addIssues(tr.getIssues(), hr); }; }  static OccurrenceHdfsRecord toOccurrenceHdfsRecord(SpecificRecordBase... records); }
OccurrenceHdfsRecordConverter { private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> temporalMapper() { return (hr, sr) -> { TemporalRecord tr = (TemporalRecord) sr; Optional.ofNullable(tr.getDateIdentified()) .map(STRING_TO_DATE) .ifPresent(date -> hr.setDateidentified(date.getTime())); Optional.ofNullable(tr.getModified()) .map(STRING_TO_DATE) .ifPresent(date -> hr.setModified(date.getTime())); hr.setDay(tr.getDay()); hr.setMonth(tr.getMonth()); hr.setYear(tr.getYear()); if (Objects.nonNull(tr.getStartDayOfYear())) { hr.setStartdayofyear(tr.getStartDayOfYear().toString()); } else { hr.setStartdayofyear(null); } if (Objects.nonNull(tr.getEndDayOfYear())) { hr.setEnddayofyear(tr.getEndDayOfYear().toString()); } else { hr.setEnddayofyear(null); } if (tr.getEventDate() != null && tr.getEventDate().getGte() != null) { Optional.ofNullable(tr.getEventDate().getGte()) .map(STRING_TO_DATE) .ifPresent(eventDate -> hr.setEventdate(eventDate.getTime())); } else { TemporalUtils.getTemporal(tr.getYear(), tr.getMonth(), tr.getDay()) .map(TEMPORAL_TO_DATE) .ifPresent(eventDate -> hr.setEventdate(eventDate.getTime())); } setCreatedIfGreater(hr, tr.getCreated()); addIssues(tr.getIssues(), hr); }; }  static OccurrenceHdfsRecord toOccurrenceHdfsRecord(SpecificRecordBase... records);  }