@Test public void issueMappingTest() { String[] issues = { OccurrenceIssue.IDENTIFIED_DATE_INVALID.name(), OccurrenceIssue.MODIFIED_DATE_INVALID.name(), OccurrenceIssue.RECORDED_DATE_UNLIKELY.name() }; TemporalRecord temporalRecord = TemporalRecord.newBuilder() .setId("1") .setDay(1) .setYear(2019) .setMonth(1) .setStartDayOfYear(1) .setIssues(IssueRecord.newBuilder().setIssueList(Arrays.asList(issues)).build()) .build(); OccurrenceHdfsRecord hdfsRecord = toOccurrenceHdfsRecord(temporalRecord); Assert.assertArrayEquals(issues, hdfsRecord.getIssue().toArray(new String[issues.length])); }
public static OccurrenceHdfsRecord toOccurrenceHdfsRecord(SpecificRecordBase... records) { OccurrenceHdfsRecord occurrenceHdfsRecord = new OccurrenceHdfsRecord(); occurrenceHdfsRecord.setIssue(new ArrayList<>()); for (SpecificRecordBase record : records) { Optional.ofNullable(converters.get(record.getClass())) .ifPresent(consumer -> consumer.accept(occurrenceHdfsRecord, record)); } Optional<SpecificRecordBase> erOpt = Arrays.stream(records).filter(x -> x instanceof ExtendedRecord).findFirst(); Optional<SpecificRecordBase> brOpt = Arrays.stream(records).filter(x -> x instanceof BasicRecord).findFirst(); if (erOpt.isPresent() && brOpt.isPresent()) { setIdentifier((BasicRecord) brOpt.get(), (ExtendedRecord) erOpt.get(), occurrenceHdfsRecord); } return occurrenceHdfsRecord; }
OccurrenceHdfsRecordConverter { public static OccurrenceHdfsRecord toOccurrenceHdfsRecord(SpecificRecordBase... records) { OccurrenceHdfsRecord occurrenceHdfsRecord = new OccurrenceHdfsRecord(); occurrenceHdfsRecord.setIssue(new ArrayList<>()); for (SpecificRecordBase record : records) { Optional.ofNullable(converters.get(record.getClass())) .ifPresent(consumer -> consumer.accept(occurrenceHdfsRecord, record)); } Optional<SpecificRecordBase> erOpt = Arrays.stream(records).filter(x -> x instanceof ExtendedRecord).findFirst(); Optional<SpecificRecordBase> brOpt = Arrays.stream(records).filter(x -> x instanceof BasicRecord).findFirst(); if (erOpt.isPresent() && brOpt.isPresent()) { setIdentifier((BasicRecord) brOpt.get(), (ExtendedRecord) erOpt.get(), occurrenceHdfsRecord); } return occurrenceHdfsRecord; } }
OccurrenceHdfsRecordConverter { public static OccurrenceHdfsRecord toOccurrenceHdfsRecord(SpecificRecordBase... records) { OccurrenceHdfsRecord occurrenceHdfsRecord = new OccurrenceHdfsRecord(); occurrenceHdfsRecord.setIssue(new ArrayList<>()); for (SpecificRecordBase record : records) { Optional.ofNullable(converters.get(record.getClass())) .ifPresent(consumer -> consumer.accept(occurrenceHdfsRecord, record)); } Optional<SpecificRecordBase> erOpt = Arrays.stream(records).filter(x -> x instanceof ExtendedRecord).findFirst(); Optional<SpecificRecordBase> brOpt = Arrays.stream(records).filter(x -> x instanceof BasicRecord).findFirst(); if (erOpt.isPresent() && brOpt.isPresent()) { setIdentifier((BasicRecord) brOpt.get(), (ExtendedRecord) erOpt.get(), occurrenceHdfsRecord); } return occurrenceHdfsRecord; }  }
OccurrenceHdfsRecordConverter { public static OccurrenceHdfsRecord toOccurrenceHdfsRecord(SpecificRecordBase... records) { OccurrenceHdfsRecord occurrenceHdfsRecord = new OccurrenceHdfsRecord(); occurrenceHdfsRecord.setIssue(new ArrayList<>()); for (SpecificRecordBase record : records) { Optional.ofNullable(converters.get(record.getClass())) .ifPresent(consumer -> consumer.accept(occurrenceHdfsRecord, record)); } Optional<SpecificRecordBase> erOpt = Arrays.stream(records).filter(x -> x instanceof ExtendedRecord).findFirst(); Optional<SpecificRecordBase> brOpt = Arrays.stream(records).filter(x -> x instanceof BasicRecord).findFirst(); if (erOpt.isPresent() && brOpt.isPresent()) { setIdentifier((BasicRecord) brOpt.get(), (ExtendedRecord) erOpt.get(), occurrenceHdfsRecord); } return occurrenceHdfsRecord; }  static OccurrenceHdfsRecord toOccurrenceHdfsRecord(SpecificRecordBase... records); }
OccurrenceHdfsRecordConverter { public static OccurrenceHdfsRecord toOccurrenceHdfsRecord(SpecificRecordBase... records) { OccurrenceHdfsRecord occurrenceHdfsRecord = new OccurrenceHdfsRecord(); occurrenceHdfsRecord.setIssue(new ArrayList<>()); for (SpecificRecordBase record : records) { Optional.ofNullable(converters.get(record.getClass())) .ifPresent(consumer -> consumer.accept(occurrenceHdfsRecord, record)); } Optional<SpecificRecordBase> erOpt = Arrays.stream(records).filter(x -> x instanceof ExtendedRecord).findFirst(); Optional<SpecificRecordBase> brOpt = Arrays.stream(records).filter(x -> x instanceof BasicRecord).findFirst(); if (erOpt.isPresent() && brOpt.isPresent()) { setIdentifier((BasicRecord) brOpt.get(), (ExtendedRecord) erOpt.get(), occurrenceHdfsRecord); } return occurrenceHdfsRecord; }  static OccurrenceHdfsRecord toOccurrenceHdfsRecord(SpecificRecordBase... records);  }