@Test public void testLikelyIdentified() { Map<String, String> map = new HashMap<>(); map.put(DwcTerm.year.qualifiedName(), "1879"); map.put(DwcTerm.month.qualifiedName(), "11 "); map.put(DwcTerm.day.qualifiedName(), "1"); map.put(DwcTerm.eventDate.qualifiedName(), "1.11.1879"); map.put(DcTerm.modified.qualifiedName(), "2014-01-11"); ExtendedRecord er = ExtendedRecord.newBuilder().setId("1").setCoreTerms(map).build(); TemporalRecord tr = TemporalRecord.newBuilder().setId("1").build(); TemporalInterpreter interpreter = TemporalInterpreter.builder().create(); er.getCoreTerms().put(DwcTerm.dateIdentified.qualifiedName(), "1987-01-31"); interpreter.interpretDateIdentified(er, tr); assertEquals(0, tr.getIssues().getIssueList().size()); er.getCoreTerms().put(DwcTerm.dateIdentified.qualifiedName(), "1787-03-27"); interpreter.interpretDateIdentified(er, tr); assertEquals(0, tr.getIssues().getIssueList().size()); er.getCoreTerms().put(DwcTerm.dateIdentified.qualifiedName(), "2014-01-11"); interpreter.interpretDateIdentified(er, tr); assertEquals(0, tr.getIssues().getIssueList().size()); er.getCoreTerms().put(DwcTerm.dateIdentified.qualifiedName(), "1997"); interpreter.interpretDateIdentified(er, tr); assertEquals(0, tr.getIssues().getIssueList().size()); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); er.getCoreTerms() .put(DwcTerm.dateIdentified.qualifiedName(), (cal.get(Calendar.YEAR) + 1) + "-01-11"); interpreter.interpretDateIdentified(er, tr); assertEquals(1, tr.getIssues().getIssueList().size()); assertEquals( OccurrenceIssue.IDENTIFIED_DATE_UNLIKELY.name(), tr.getIssues().getIssueList().iterator().next()); er.getCoreTerms().put(DwcTerm.dateIdentified.qualifiedName(), "1599-01-11"); interpreter.interpretDateIdentified(er, tr); assertEquals(1, tr.getIssues().getIssueList().size()); assertEquals( OccurrenceIssue.IDENTIFIED_DATE_UNLIKELY.name(), tr.getIssues().getIssueList().iterator().next()); }
public void interpretDateIdentified(ExtendedRecord er, TemporalRecord tr) { if (hasValue(er, DwcTerm.dateIdentified)) { String value = extractValue(er, DwcTerm.dateIdentified); String normalizedValue = Optional.ofNullable(preprocessDateFn).map(x -> x.apply(value)).orElse(value); LocalDate upperBound = LocalDate.now().plusDays(1); Range<LocalDate> validRecordedDateRange = Range.closed(MIN_LOCAL_DATE, upperBound); OccurrenceParseResult<TemporalAccessor> parsed = temporalParser.parseLocalDate( normalizedValue, validRecordedDateRange, OccurrenceIssue.IDENTIFIED_DATE_UNLIKELY); if (parsed.isSuccessful()) { Optional.ofNullable(parsed.getPayload()) .map(TemporalAccessor::toString) .ifPresent(tr::setDateIdentified); } addIssueSet(tr, parsed.getIssues()); } }
TemporalInterpreter implements Serializable { public void interpretDateIdentified(ExtendedRecord er, TemporalRecord tr) { if (hasValue(er, DwcTerm.dateIdentified)) { String value = extractValue(er, DwcTerm.dateIdentified); String normalizedValue = Optional.ofNullable(preprocessDateFn).map(x -> x.apply(value)).orElse(value); LocalDate upperBound = LocalDate.now().plusDays(1); Range<LocalDate> validRecordedDateRange = Range.closed(MIN_LOCAL_DATE, upperBound); OccurrenceParseResult<TemporalAccessor> parsed = temporalParser.parseLocalDate( normalizedValue, validRecordedDateRange, OccurrenceIssue.IDENTIFIED_DATE_UNLIKELY); if (parsed.isSuccessful()) { Optional.ofNullable(parsed.getPayload()) .map(TemporalAccessor::toString) .ifPresent(tr::setDateIdentified); } addIssueSet(tr, parsed.getIssues()); } } }
TemporalInterpreter implements Serializable { public void interpretDateIdentified(ExtendedRecord er, TemporalRecord tr) { if (hasValue(er, DwcTerm.dateIdentified)) { String value = extractValue(er, DwcTerm.dateIdentified); String normalizedValue = Optional.ofNullable(preprocessDateFn).map(x -> x.apply(value)).orElse(value); LocalDate upperBound = LocalDate.now().plusDays(1); Range<LocalDate> validRecordedDateRange = Range.closed(MIN_LOCAL_DATE, upperBound); OccurrenceParseResult<TemporalAccessor> parsed = temporalParser.parseLocalDate( normalizedValue, validRecordedDateRange, OccurrenceIssue.IDENTIFIED_DATE_UNLIKELY); if (parsed.isSuccessful()) { Optional.ofNullable(parsed.getPayload()) .map(TemporalAccessor::toString) .ifPresent(tr::setDateIdentified); } addIssueSet(tr, parsed.getIssues()); } } @Builder(buildMethodName = "create") private  TemporalInterpreter(
      List<DateComponentOrdering> orderings,
      SerializableFunction<String, String> preprocessDateFn); }
TemporalInterpreter implements Serializable { public void interpretDateIdentified(ExtendedRecord er, TemporalRecord tr) { if (hasValue(er, DwcTerm.dateIdentified)) { String value = extractValue(er, DwcTerm.dateIdentified); String normalizedValue = Optional.ofNullable(preprocessDateFn).map(x -> x.apply(value)).orElse(value); LocalDate upperBound = LocalDate.now().plusDays(1); Range<LocalDate> validRecordedDateRange = Range.closed(MIN_LOCAL_DATE, upperBound); OccurrenceParseResult<TemporalAccessor> parsed = temporalParser.parseLocalDate( normalizedValue, validRecordedDateRange, OccurrenceIssue.IDENTIFIED_DATE_UNLIKELY); if (parsed.isSuccessful()) { Optional.ofNullable(parsed.getPayload()) .map(TemporalAccessor::toString) .ifPresent(tr::setDateIdentified); } addIssueSet(tr, parsed.getIssues()); } } @Builder(buildMethodName = "create") private  TemporalInterpreter(
      List<DateComponentOrdering> orderings,
      SerializableFunction<String, String> preprocessDateFn); void interpretTemporal(ExtendedRecord er, TemporalRecord tr); void interpretModified(ExtendedRecord er, TemporalRecord tr); void interpretDateIdentified(ExtendedRecord er, TemporalRecord tr); }
TemporalInterpreter implements Serializable { public void interpretDateIdentified(ExtendedRecord er, TemporalRecord tr) { if (hasValue(er, DwcTerm.dateIdentified)) { String value = extractValue(er, DwcTerm.dateIdentified); String normalizedValue = Optional.ofNullable(preprocessDateFn).map(x -> x.apply(value)).orElse(value); LocalDate upperBound = LocalDate.now().plusDays(1); Range<LocalDate> validRecordedDateRange = Range.closed(MIN_LOCAL_DATE, upperBound); OccurrenceParseResult<TemporalAccessor> parsed = temporalParser.parseLocalDate( normalizedValue, validRecordedDateRange, OccurrenceIssue.IDENTIFIED_DATE_UNLIKELY); if (parsed.isSuccessful()) { Optional.ofNullable(parsed.getPayload()) .map(TemporalAccessor::toString) .ifPresent(tr::setDateIdentified); } addIssueSet(tr, parsed.getIssues()); } } @Builder(buildMethodName = "create") private  TemporalInterpreter(
      List<DateComponentOrdering> orderings,
      SerializableFunction<String, String> preprocessDateFn); void interpretTemporal(ExtendedRecord er, TemporalRecord tr); void interpretModified(ExtendedRecord er, TemporalRecord tr); void interpretDateIdentified(ExtendedRecord er, TemporalRecord tr);  }