@Test public void extendedRecordMapperTest() { Map<String, String> coreTerms = new HashMap<>(); coreTerms.put(DwcTerm.verbatimDepth.simpleName(), "1.0"); coreTerms.put(DwcTerm.collectionCode.simpleName(), "C1"); coreTerms.put(DwcTerm.institutionCode.simpleName(), "I1"); coreTerms.put(DwcTerm.catalogNumber.simpleName(), "CN1"); coreTerms.put(DwcTerm.class_.simpleName(), "classs"); coreTerms.put(DcTerm.format.simpleName(), "format"); coreTerms.put(DwcTerm.order.simpleName(), "order"); coreTerms.put(DwcTerm.group.simpleName(), "group"); coreTerms.put(DcTerm.date.simpleName(), "26/06/2019"); coreTerms.put( DwcTerm.basisOfRecord.simpleName(), BasisOfRecord.HUMAN_OBSERVATION.name().toLowerCase()); coreTerms.put(DwcTerm.lifeStage.simpleName(), "adultss"); coreTerms.put(DwcTerm.sampleSizeUnit.simpleName(), "unit"); coreTerms.put(DwcTerm.sampleSizeValue.simpleName(), "value"); coreTerms.put(DwcTerm.organismQuantity.simpleName(), "quantity"); coreTerms.put(DwcTerm.organismQuantityType.simpleName(), "type"); coreTerms.put(DwcTerm.recordedBy.simpleName(), "recordedBy"); coreTerms.put(DwcTerm.identifiedBy.simpleName(), "identifiedBy"); coreTerms.put(GbifTerm.identifiedByID.simpleName(), "13123|21312"); coreTerms.put(GbifTerm.recordedByID.simpleName(), "53453|5785"); coreTerms.put(DwcTerm.occurrenceStatus.simpleName(), OccurrenceStatus.ABSENT.name()); coreTerms.put(DwcTerm.individualCount.simpleName(), "0"); ExtendedRecord extendedRecord = ExtendedRecord.newBuilder().setId("1").setCoreTerms(coreTerms).build(); MetadataRecord metadataRecord = MetadataRecord.newBuilder() .setId("1") .setLicense(License.CC_BY_4_0.name()) .setHostingOrganizationKey("hostOrgKey") .build(); List<AgentIdentifier> agentIds = Collections.singletonList( AgentIdentifier.newBuilder() .setType(AgentIdentifierType.OTHER.name()) .setValue("13123") .build()); BasicRecord basicRecord = BasicRecord.newBuilder() .setId("1") .setCreated(1L) .setLicense(License.CC0_1_0.name()) .setIdentifiedByIds(agentIds) .setRecordedByIds(agentIds) .setIndividualCount(0) .setBasisOfRecord(BasisOfRecord.HUMAN_OBSERVATION.name()) .setOccurrenceStatus(OccurrenceStatus.ABSENT.name()) .build(); List<RankedName> classification = new ArrayList<>(); classification.add(RankedName.newBuilder().setName("CLASS").setRank(Rank.CLASS).build()); classification.add(RankedName.newBuilder().setName("ORDER").setRank(Rank.ORDER).build()); TaxonRecord taxonRecord = TaxonRecord.newBuilder() .setCreated( 2L) .setClassification(classification) .build(); TemporalRecord temporalRecord = TemporalRecord.newBuilder() .setId("1") .setDateIdentified("2019-11-12T13:24:56.963591") .setModified("2019-04-15T17:17") .build(); OccurrenceHdfsRecord hdfsRecord = toOccurrenceHdfsRecord( basicRecord, metadataRecord, taxonRecord, temporalRecord, extendedRecord); Assert.assertEquals("1.0", hdfsRecord.getVerbatimdepth()); Assert.assertEquals("C1", hdfsRecord.getCollectioncode()); Assert.assertEquals("C1", hdfsRecord.getVCollectioncode()); Assert.assertEquals("I1", hdfsRecord.getInstitutioncode()); Assert.assertEquals("I1", hdfsRecord.getVInstitutioncode()); Assert.assertEquals("CN1", hdfsRecord.getCatalognumber()); Assert.assertEquals("CN1", hdfsRecord.getVCatalognumber()); Assert.assertEquals("1", hdfsRecord.getIdentifier()); Assert.assertEquals("1", hdfsRecord.getVIdentifier()); Assert.assertEquals("quantity", hdfsRecord.getVOrganismquantity()); Assert.assertEquals("type", hdfsRecord.getVOrganismquantitytype()); Assert.assertEquals("unit", hdfsRecord.getVSamplesizeunit()); Assert.assertEquals("value", hdfsRecord.getVSamplesizevalue()); Assert.assertEquals("recordedBy", hdfsRecord.getVRecordedby()); Assert.assertEquals("identifiedBy", hdfsRecord.getIdentifiedby()); Assert.assertEquals("13123|21312", hdfsRecord.getVIdentifiedbyid()); Assert.assertEquals("53453|5785", hdfsRecord.getVRecordedbyid()); Assert.assertEquals(OccurrenceStatus.ABSENT.name(), hdfsRecord.getVOccurrencestatus()); Assert.assertEquals("0", hdfsRecord.getVIndividualcount()); Assert.assertEquals("CLASS", hdfsRecord.getClass$()); Assert.assertEquals("classs", hdfsRecord.getVClass()); Assert.assertEquals("format", hdfsRecord.getFormat()); Assert.assertEquals("format", hdfsRecord.getVFormat()); Assert.assertEquals("ORDER", hdfsRecord.getOrder()); Assert.assertEquals("order", hdfsRecord.getVOrder()); Assert.assertEquals("group", hdfsRecord.getGroup()); Assert.assertEquals("group", hdfsRecord.getVGroup()); Assert.assertEquals("26/06/2019", hdfsRecord.getDate()); Assert.assertEquals("26/06/2019", hdfsRecord.getVDate()); Assert.assertNotNull(hdfsRecord.getDateidentified()); Assert.assertNotNull(hdfsRecord.getModified()); Assert.assertEquals(BasisOfRecord.HUMAN_OBSERVATION.name(), hdfsRecord.getBasisofrecord()); Assert.assertEquals( BasisOfRecord.HUMAN_OBSERVATION.name().toLowerCase(), hdfsRecord.getVBasisofrecord()); Assert.assertNull(hdfsRecord.getLifestage()); Assert.assertEquals("adultss", hdfsRecord.getVLifestage()); Assert.assertEquals(taxonRecord.getCreated(), hdfsRecord.getLastparsed()); Assert.assertEquals(taxonRecord.getCreated(), hdfsRecord.getLastinterpreted()); Assert.assertEquals(License.CC0_1_0.name(), hdfsRecord.getLicense()); Assert.assertEquals(Collections.singletonList("13123"), hdfsRecord.getRecordedbyid()); Assert.assertEquals(Collections.singletonList("13123"), hdfsRecord.getIdentifiedbyid()); Assert.assertEquals(OccurrenceStatus.ABSENT.name(), hdfsRecord.getOccurrencestatus()); Assert.assertEquals(Integer.valueOf(0), hdfsRecord.getIndividualcount()); Assert.assertEquals( metadataRecord.getHostingOrganizationKey(), hdfsRecord.getHostingorganizationkey()); }
private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> extendedRecordMapper() { return (hr, sr) -> { ExtendedRecord er = (ExtendedRecord) sr; er.getCoreTerms() .forEach( (k, v) -> Optional.ofNullable(TERM_FACTORY.findTerm(k)) .ifPresent( term -> { if (TermUtils.verbatimTerms().contains(term)) { Optional.ofNullable(verbatimSchemaField(term)) .ifPresent( field -> { String verbatimField = "V" + field.name().substring(2, 3).toUpperCase() + field.name().substring(3); setHdfsRecordField(hr, field, verbatimField, v); }); } if (!TermUtils.isInterpretedSourceTerm(term)) { Optional.ofNullable(interpretedSchemaField(term)) .ifPresent( field -> { if (Objects.isNull(hr.get(field.name()))) { String interpretedFieldname = field.name(); if (DcTerm.abstract_ == term) { interpretedFieldname = "abstract$"; } else if (DwcTerm.class_ == term) { interpretedFieldname = "class$"; } else if (DwcTerm.group == term) { interpretedFieldname = "group"; } else if (DwcTerm.order == term) { interpretedFieldname = "order"; } else if (DcTerm.date == term) { interpretedFieldname = "date"; } else if (DcTerm.format == term) { interpretedFieldname = "format"; } setHdfsRecordField(hr, field, interpretedFieldname, v); } }); } })); }; }
OccurrenceHdfsRecordConverter { private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> extendedRecordMapper() { return (hr, sr) -> { ExtendedRecord er = (ExtendedRecord) sr; er.getCoreTerms() .forEach( (k, v) -> Optional.ofNullable(TERM_FACTORY.findTerm(k)) .ifPresent( term -> { if (TermUtils.verbatimTerms().contains(term)) { Optional.ofNullable(verbatimSchemaField(term)) .ifPresent( field -> { String verbatimField = "V" + field.name().substring(2, 3).toUpperCase() + field.name().substring(3); setHdfsRecordField(hr, field, verbatimField, v); }); } if (!TermUtils.isInterpretedSourceTerm(term)) { Optional.ofNullable(interpretedSchemaField(term)) .ifPresent( field -> { if (Objects.isNull(hr.get(field.name()))) { String interpretedFieldname = field.name(); if (DcTerm.abstract_ == term) { interpretedFieldname = "abstract$"; } else if (DwcTerm.class_ == term) { interpretedFieldname = "class$"; } else if (DwcTerm.group == term) { interpretedFieldname = "group"; } else if (DwcTerm.order == term) { interpretedFieldname = "order"; } else if (DcTerm.date == term) { interpretedFieldname = "date"; } else if (DcTerm.format == term) { interpretedFieldname = "format"; } setHdfsRecordField(hr, field, interpretedFieldname, v); } }); } })); }; } }
OccurrenceHdfsRecordConverter { private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> extendedRecordMapper() { return (hr, sr) -> { ExtendedRecord er = (ExtendedRecord) sr; er.getCoreTerms() .forEach( (k, v) -> Optional.ofNullable(TERM_FACTORY.findTerm(k)) .ifPresent( term -> { if (TermUtils.verbatimTerms().contains(term)) { Optional.ofNullable(verbatimSchemaField(term)) .ifPresent( field -> { String verbatimField = "V" + field.name().substring(2, 3).toUpperCase() + field.name().substring(3); setHdfsRecordField(hr, field, verbatimField, v); }); } if (!TermUtils.isInterpretedSourceTerm(term)) { Optional.ofNullable(interpretedSchemaField(term)) .ifPresent( field -> { if (Objects.isNull(hr.get(field.name()))) { String interpretedFieldname = field.name(); if (DcTerm.abstract_ == term) { interpretedFieldname = "abstract$"; } else if (DwcTerm.class_ == term) { interpretedFieldname = "class$"; } else if (DwcTerm.group == term) { interpretedFieldname = "group"; } else if (DwcTerm.order == term) { interpretedFieldname = "order"; } else if (DcTerm.date == term) { interpretedFieldname = "date"; } else if (DcTerm.format == term) { interpretedFieldname = "format"; } setHdfsRecordField(hr, field, interpretedFieldname, v); } }); } })); }; }  }
OccurrenceHdfsRecordConverter { private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> extendedRecordMapper() { return (hr, sr) -> { ExtendedRecord er = (ExtendedRecord) sr; er.getCoreTerms() .forEach( (k, v) -> Optional.ofNullable(TERM_FACTORY.findTerm(k)) .ifPresent( term -> { if (TermUtils.verbatimTerms().contains(term)) { Optional.ofNullable(verbatimSchemaField(term)) .ifPresent( field -> { String verbatimField = "V" + field.name().substring(2, 3).toUpperCase() + field.name().substring(3); setHdfsRecordField(hr, field, verbatimField, v); }); } if (!TermUtils.isInterpretedSourceTerm(term)) { Optional.ofNullable(interpretedSchemaField(term)) .ifPresent( field -> { if (Objects.isNull(hr.get(field.name()))) { String interpretedFieldname = field.name(); if (DcTerm.abstract_ == term) { interpretedFieldname = "abstract$"; } else if (DwcTerm.class_ == term) { interpretedFieldname = "class$"; } else if (DwcTerm.group == term) { interpretedFieldname = "group"; } else if (DwcTerm.order == term) { interpretedFieldname = "order"; } else if (DcTerm.date == term) { interpretedFieldname = "date"; } else if (DcTerm.format == term) { interpretedFieldname = "format"; } setHdfsRecordField(hr, field, interpretedFieldname, v); } }); } })); }; }  static OccurrenceHdfsRecord toOccurrenceHdfsRecord(SpecificRecordBase... records); }
OccurrenceHdfsRecordConverter { private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> extendedRecordMapper() { return (hr, sr) -> { ExtendedRecord er = (ExtendedRecord) sr; er.getCoreTerms() .forEach( (k, v) -> Optional.ofNullable(TERM_FACTORY.findTerm(k)) .ifPresent( term -> { if (TermUtils.verbatimTerms().contains(term)) { Optional.ofNullable(verbatimSchemaField(term)) .ifPresent( field -> { String verbatimField = "V" + field.name().substring(2, 3).toUpperCase() + field.name().substring(3); setHdfsRecordField(hr, field, verbatimField, v); }); } if (!TermUtils.isInterpretedSourceTerm(term)) { Optional.ofNullable(interpretedSchemaField(term)) .ifPresent( field -> { if (Objects.isNull(hr.get(field.name()))) { String interpretedFieldname = field.name(); if (DcTerm.abstract_ == term) { interpretedFieldname = "abstract$"; } else if (DwcTerm.class_ == term) { interpretedFieldname = "class$"; } else if (DwcTerm.group == term) { interpretedFieldname = "group"; } else if (DwcTerm.order == term) { interpretedFieldname = "order"; } else if (DcTerm.date == term) { interpretedFieldname = "date"; } else if (DcTerm.format == term) { interpretedFieldname = "format"; } setHdfsRecordField(hr, field, interpretedFieldname, v); } }); } })); }; }  static OccurrenceHdfsRecord toOccurrenceHdfsRecord(SpecificRecordBase... records);  }