@Test public void testDoTransform() throws Exception { ETLStatistics etlStatistics = new ETLStatistics(); List<Specimen> list = null; CrsSpecimenTransformer crsSpecimenTransformer = new CrsSpecimenTransformer(etlStatistics); CrsExtractor extractor = new CrsExtractor(specimenFile, etlStatistics); for (XMLRecordInfo extracted : extractor) { CommonReflectionUtil.setField(AbstractTransformer.class, crsSpecimenTransformer, "objectID", "RMNH.MAM.TT.5"); CommonReflectionUtil.setField(AbstractTransformer.class, crsSpecimenTransformer, "input", extracted); Object returned = CommonReflectionUtil.callMethod(null, null, crsSpecimenTransformer, "doTransform"); list = (List<Specimen>) returned; Specimen sp = list.get(0); List<String> previousSourceIds = new ArrayList<>(); previousSourceIds.add("AAA"); previousSourceIds.add("OOO"); Specimen expectedSpecimen = new Specimen(); expectedSpecimen.setSourceID("CRS"); expectedSpecimen.setId("RMNH.MAM.TT.5@CRS"); expectedSpecimen.setUnitGUID("https: expectedSpecimen.setOwner("Naturalis Biodiversity Center"); expectedSpecimen.setTitle("RMNH.ART"); expectedSpecimen.setKindOfUnit("WholeOrganism"); expectedSpecimen.setCollectionType("PreservedSpecimen"); expectedSpecimen.setNumberOfSpecimen(1); expectedSpecimen.setPreviousSourceID(previousSourceIds); assertNotNull("01",sp); assertEquals("02",expectedSpecimen.getSourceID(), sp.getSourceID()); assertEquals("03",expectedSpecimen.getId(), sp.getId()); assertEquals("04",expectedSpecimen.getUnitGUID(), sp.getUnitGUID()); assertEquals("05",expectedSpecimen.getOwner(), sp.getOwner()); assertEquals("06",expectedSpecimen.getTitle(), sp.getTitle()); assertEquals("07",expectedSpecimen.getKindOfUnit(), sp.getKindOfUnit()); assertEquals("08",expectedSpecimen.getCollectionType(), sp.getCollectionType()); assertEquals("09",expectedSpecimen.getNumberOfSpecimen(), sp.getNumberOfSpecimen()); assertEquals("10",expectedSpecimen.getPreviousSourceID(), sp.getPreviousSourceID()); } }
@Override protected List<Specimen> doTransform() { Element record = input.getRecord(); if (hasStatusDeleted()) { stats.recordsSkipped++; info("Skipping record with status \"deleted\""); return null; } String recordBasis = val(record, "abcd:RecordBasis"); if (recordBasis == null) { stats.recordsSkipped++; if (!suppressErrors) { warn("Skipping virtual specimen"); } return null; } List<Element> elems = DOMUtil.getDescendants(record, "ncrsDetermination"); if (elems == null) { stats.recordsRejected++; if (!suppressErrors) { error("Missing element: <ncrsDetermination>"); } return null; } if (testGenera != null && !hasTestGenus(elems)) { stats.recordsSkipped++; return null; } Specimen specimen = new Specimen(); String collectionType = val(record, "abcd:CollectionType"); for (Element e : elems) { SpecimenIdentification si = getIdentification(e, collectionType); if (si != null) { specimen.addIndentification(si); } } if (specimen.getIdentifications() == null) { stats.recordsRejected++; if (!suppressErrors) { error("Invalid or insufficient specimen identification information"); } return null; } stats.recordsAccepted++; stats.objectsProcessed++; sortIdentificationsPreferredFirst(specimen); if (doEnrich()) { enrichIdentification(specimen); } try { String tmp; specimen.setSourceSystem(CRS); specimen.setUnitID(objectID); specimen.setId(getElasticsearchId(CRS, objectID)); specimen.setSourceSystemId(specimen.getUnitID()); ThemeCache tsc = ThemeCache.getInstance(); List<String> themes = tsc.lookup(objectID, SPECIMEN, CRS); specimen.setTheme(themes); specimen.setUnitGUID(ETLUtil.getSpecimenPurl(objectID)); specimen.setCollectorsFieldNumber(val(record, "abcd:CollectorsFieldNumber")); specimen.setSourceInstitutionID(SOURCE_INSTITUTION_ID); specimen.setPreviousSourceID(getPreviousSourceIds()); specimen.setOwner(SOURCE_INSTITUTION_ID); specimen.setSourceID("CRS"); specimen.setLicenseType(LICENCE_TYPE); specimen.setLicense(LICENCE); specimen.setRecordBasis(recordBasis); specimen.setKindOfUnit(val(record, "abcd:KindOfUnit")); specimen.setCollectionType(collectionType); specimen.setTitle(val(record, "abcd:Title")); specimen.setNumberOfSpecimen(ival(record, "abcd:AccessionSpecimenNumbers")); tmp = val(record, "abcd:ObjectPublic"); specimen.setObjectPublic(tmp == null || tmp.trim().equals("1")); tmp = val(record, "abcd:MultiMediaPublic"); specimen.setMultiMediaPublic(tmp == null || tmp.trim().equals("1")); tmp = val(record, "abcd:FromCaptivity"); specimen.setFromCaptivity(tmp != null && tmp.trim().equals("1")); tmp = val(record, "abcd:PreparationType"); if (tmp == null) { tmp = val(record, "abcd:SpecimenMount"); } specimen.setPreparationType(tmp); specimen.setPhaseOrStage(getPhaseOrStage()); specimen.setSex(getSex()); specimen.setGatheringEvent(getGatheringEvent()); specimen.setDateLastEdited(getDateLastEdited()); specimen.setAssociatedMultiMediaUris(getAssociatedMultiMediaUris()); stats.objectsAccepted++; return Collections.singletonList(specimen); } catch (Throwable t) { handleError(t); return null; } }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { @Override protected List<Specimen> doTransform() { Element record = input.getRecord(); if (hasStatusDeleted()) { stats.recordsSkipped++; info("Skipping record with status \"deleted\""); return null; } String recordBasis = val(record, "abcd:RecordBasis"); if (recordBasis == null) { stats.recordsSkipped++; if (!suppressErrors) { warn("Skipping virtual specimen"); } return null; } List<Element> elems = DOMUtil.getDescendants(record, "ncrsDetermination"); if (elems == null) { stats.recordsRejected++; if (!suppressErrors) { error("Missing element: <ncrsDetermination>"); } return null; } if (testGenera != null && !hasTestGenus(elems)) { stats.recordsSkipped++; return null; } Specimen specimen = new Specimen(); String collectionType = val(record, "abcd:CollectionType"); for (Element e : elems) { SpecimenIdentification si = getIdentification(e, collectionType); if (si != null) { specimen.addIndentification(si); } } if (specimen.getIdentifications() == null) { stats.recordsRejected++; if (!suppressErrors) { error("Invalid or insufficient specimen identification information"); } return null; } stats.recordsAccepted++; stats.objectsProcessed++; sortIdentificationsPreferredFirst(specimen); if (doEnrich()) { enrichIdentification(specimen); } try { String tmp; specimen.setSourceSystem(CRS); specimen.setUnitID(objectID); specimen.setId(getElasticsearchId(CRS, objectID)); specimen.setSourceSystemId(specimen.getUnitID()); ThemeCache tsc = ThemeCache.getInstance(); List<String> themes = tsc.lookup(objectID, SPECIMEN, CRS); specimen.setTheme(themes); specimen.setUnitGUID(ETLUtil.getSpecimenPurl(objectID)); specimen.setCollectorsFieldNumber(val(record, "abcd:CollectorsFieldNumber")); specimen.setSourceInstitutionID(SOURCE_INSTITUTION_ID); specimen.setPreviousSourceID(getPreviousSourceIds()); specimen.setOwner(SOURCE_INSTITUTION_ID); specimen.setSourceID("CRS"); specimen.setLicenseType(LICENCE_TYPE); specimen.setLicense(LICENCE); specimen.setRecordBasis(recordBasis); specimen.setKindOfUnit(val(record, "abcd:KindOfUnit")); specimen.setCollectionType(collectionType); specimen.setTitle(val(record, "abcd:Title")); specimen.setNumberOfSpecimen(ival(record, "abcd:AccessionSpecimenNumbers")); tmp = val(record, "abcd:ObjectPublic"); specimen.setObjectPublic(tmp == null || tmp.trim().equals("1")); tmp = val(record, "abcd:MultiMediaPublic"); specimen.setMultiMediaPublic(tmp == null || tmp.trim().equals("1")); tmp = val(record, "abcd:FromCaptivity"); specimen.setFromCaptivity(tmp != null && tmp.trim().equals("1")); tmp = val(record, "abcd:PreparationType"); if (tmp == null) { tmp = val(record, "abcd:SpecimenMount"); } specimen.setPreparationType(tmp); specimen.setPhaseOrStage(getPhaseOrStage()); specimen.setSex(getSex()); specimen.setGatheringEvent(getGatheringEvent()); specimen.setDateLastEdited(getDateLastEdited()); specimen.setAssociatedMultiMediaUris(getAssociatedMultiMediaUris()); stats.objectsAccepted++; return Collections.singletonList(specimen); } catch (Throwable t) { handleError(t); return null; } } }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { @Override protected List<Specimen> doTransform() { Element record = input.getRecord(); if (hasStatusDeleted()) { stats.recordsSkipped++; info("Skipping record with status \"deleted\""); return null; } String recordBasis = val(record, "abcd:RecordBasis"); if (recordBasis == null) { stats.recordsSkipped++; if (!suppressErrors) { warn("Skipping virtual specimen"); } return null; } List<Element> elems = DOMUtil.getDescendants(record, "ncrsDetermination"); if (elems == null) { stats.recordsRejected++; if (!suppressErrors) { error("Missing element: <ncrsDetermination>"); } return null; } if (testGenera != null && !hasTestGenus(elems)) { stats.recordsSkipped++; return null; } Specimen specimen = new Specimen(); String collectionType = val(record, "abcd:CollectionType"); for (Element e : elems) { SpecimenIdentification si = getIdentification(e, collectionType); if (si != null) { specimen.addIndentification(si); } } if (specimen.getIdentifications() == null) { stats.recordsRejected++; if (!suppressErrors) { error("Invalid or insufficient specimen identification information"); } return null; } stats.recordsAccepted++; stats.objectsProcessed++; sortIdentificationsPreferredFirst(specimen); if (doEnrich()) { enrichIdentification(specimen); } try { String tmp; specimen.setSourceSystem(CRS); specimen.setUnitID(objectID); specimen.setId(getElasticsearchId(CRS, objectID)); specimen.setSourceSystemId(specimen.getUnitID()); ThemeCache tsc = ThemeCache.getInstance(); List<String> themes = tsc.lookup(objectID, SPECIMEN, CRS); specimen.setTheme(themes); specimen.setUnitGUID(ETLUtil.getSpecimenPurl(objectID)); specimen.setCollectorsFieldNumber(val(record, "abcd:CollectorsFieldNumber")); specimen.setSourceInstitutionID(SOURCE_INSTITUTION_ID); specimen.setPreviousSourceID(getPreviousSourceIds()); specimen.setOwner(SOURCE_INSTITUTION_ID); specimen.setSourceID("CRS"); specimen.setLicenseType(LICENCE_TYPE); specimen.setLicense(LICENCE); specimen.setRecordBasis(recordBasis); specimen.setKindOfUnit(val(record, "abcd:KindOfUnit")); specimen.setCollectionType(collectionType); specimen.setTitle(val(record, "abcd:Title")); specimen.setNumberOfSpecimen(ival(record, "abcd:AccessionSpecimenNumbers")); tmp = val(record, "abcd:ObjectPublic"); specimen.setObjectPublic(tmp == null || tmp.trim().equals("1")); tmp = val(record, "abcd:MultiMediaPublic"); specimen.setMultiMediaPublic(tmp == null || tmp.trim().equals("1")); tmp = val(record, "abcd:FromCaptivity"); specimen.setFromCaptivity(tmp != null && tmp.trim().equals("1")); tmp = val(record, "abcd:PreparationType"); if (tmp == null) { tmp = val(record, "abcd:SpecimenMount"); } specimen.setPreparationType(tmp); specimen.setPhaseOrStage(getPhaseOrStage()); specimen.setSex(getSex()); specimen.setGatheringEvent(getGatheringEvent()); specimen.setDateLastEdited(getDateLastEdited()); specimen.setAssociatedMultiMediaUris(getAssociatedMultiMediaUris()); stats.objectsAccepted++; return Collections.singletonList(specimen); } catch (Throwable t) { handleError(t); return null; } } CrsSpecimenTransformer(ETLStatistics stats); }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { @Override protected List<Specimen> doTransform() { Element record = input.getRecord(); if (hasStatusDeleted()) { stats.recordsSkipped++; info("Skipping record with status \"deleted\""); return null; } String recordBasis = val(record, "abcd:RecordBasis"); if (recordBasis == null) { stats.recordsSkipped++; if (!suppressErrors) { warn("Skipping virtual specimen"); } return null; } List<Element> elems = DOMUtil.getDescendants(record, "ncrsDetermination"); if (elems == null) { stats.recordsRejected++; if (!suppressErrors) { error("Missing element: <ncrsDetermination>"); } return null; } if (testGenera != null && !hasTestGenus(elems)) { stats.recordsSkipped++; return null; } Specimen specimen = new Specimen(); String collectionType = val(record, "abcd:CollectionType"); for (Element e : elems) { SpecimenIdentification si = getIdentification(e, collectionType); if (si != null) { specimen.addIndentification(si); } } if (specimen.getIdentifications() == null) { stats.recordsRejected++; if (!suppressErrors) { error("Invalid or insufficient specimen identification information"); } return null; } stats.recordsAccepted++; stats.objectsProcessed++; sortIdentificationsPreferredFirst(specimen); if (doEnrich()) { enrichIdentification(specimen); } try { String tmp; specimen.setSourceSystem(CRS); specimen.setUnitID(objectID); specimen.setId(getElasticsearchId(CRS, objectID)); specimen.setSourceSystemId(specimen.getUnitID()); ThemeCache tsc = ThemeCache.getInstance(); List<String> themes = tsc.lookup(objectID, SPECIMEN, CRS); specimen.setTheme(themes); specimen.setUnitGUID(ETLUtil.getSpecimenPurl(objectID)); specimen.setCollectorsFieldNumber(val(record, "abcd:CollectorsFieldNumber")); specimen.setSourceInstitutionID(SOURCE_INSTITUTION_ID); specimen.setPreviousSourceID(getPreviousSourceIds()); specimen.setOwner(SOURCE_INSTITUTION_ID); specimen.setSourceID("CRS"); specimen.setLicenseType(LICENCE_TYPE); specimen.setLicense(LICENCE); specimen.setRecordBasis(recordBasis); specimen.setKindOfUnit(val(record, "abcd:KindOfUnit")); specimen.setCollectionType(collectionType); specimen.setTitle(val(record, "abcd:Title")); specimen.setNumberOfSpecimen(ival(record, "abcd:AccessionSpecimenNumbers")); tmp = val(record, "abcd:ObjectPublic"); specimen.setObjectPublic(tmp == null || tmp.trim().equals("1")); tmp = val(record, "abcd:MultiMediaPublic"); specimen.setMultiMediaPublic(tmp == null || tmp.trim().equals("1")); tmp = val(record, "abcd:FromCaptivity"); specimen.setFromCaptivity(tmp != null && tmp.trim().equals("1")); tmp = val(record, "abcd:PreparationType"); if (tmp == null) { tmp = val(record, "abcd:SpecimenMount"); } specimen.setPreparationType(tmp); specimen.setPhaseOrStage(getPhaseOrStage()); specimen.setSex(getSex()); specimen.setGatheringEvent(getGatheringEvent()); specimen.setDateLastEdited(getDateLastEdited()); specimen.setAssociatedMultiMediaUris(getAssociatedMultiMediaUris()); stats.objectsAccepted++; return Collections.singletonList(specimen); } catch (Throwable t) { handleError(t); return null; } } CrsSpecimenTransformer(ETLStatistics stats);  }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { @Override protected List<Specimen> doTransform() { Element record = input.getRecord(); if (hasStatusDeleted()) { stats.recordsSkipped++; info("Skipping record with status \"deleted\""); return null; } String recordBasis = val(record, "abcd:RecordBasis"); if (recordBasis == null) { stats.recordsSkipped++; if (!suppressErrors) { warn("Skipping virtual specimen"); } return null; } List<Element> elems = DOMUtil.getDescendants(record, "ncrsDetermination"); if (elems == null) { stats.recordsRejected++; if (!suppressErrors) { error("Missing element: <ncrsDetermination>"); } return null; } if (testGenera != null && !hasTestGenus(elems)) { stats.recordsSkipped++; return null; } Specimen specimen = new Specimen(); String collectionType = val(record, "abcd:CollectionType"); for (Element e : elems) { SpecimenIdentification si = getIdentification(e, collectionType); if (si != null) { specimen.addIndentification(si); } } if (specimen.getIdentifications() == null) { stats.recordsRejected++; if (!suppressErrors) { error("Invalid or insufficient specimen identification information"); } return null; } stats.recordsAccepted++; stats.objectsProcessed++; sortIdentificationsPreferredFirst(specimen); if (doEnrich()) { enrichIdentification(specimen); } try { String tmp; specimen.setSourceSystem(CRS); specimen.setUnitID(objectID); specimen.setId(getElasticsearchId(CRS, objectID)); specimen.setSourceSystemId(specimen.getUnitID()); ThemeCache tsc = ThemeCache.getInstance(); List<String> themes = tsc.lookup(objectID, SPECIMEN, CRS); specimen.setTheme(themes); specimen.setUnitGUID(ETLUtil.getSpecimenPurl(objectID)); specimen.setCollectorsFieldNumber(val(record, "abcd:CollectorsFieldNumber")); specimen.setSourceInstitutionID(SOURCE_INSTITUTION_ID); specimen.setPreviousSourceID(getPreviousSourceIds()); specimen.setOwner(SOURCE_INSTITUTION_ID); specimen.setSourceID("CRS"); specimen.setLicenseType(LICENCE_TYPE); specimen.setLicense(LICENCE); specimen.setRecordBasis(recordBasis); specimen.setKindOfUnit(val(record, "abcd:KindOfUnit")); specimen.setCollectionType(collectionType); specimen.setTitle(val(record, "abcd:Title")); specimen.setNumberOfSpecimen(ival(record, "abcd:AccessionSpecimenNumbers")); tmp = val(record, "abcd:ObjectPublic"); specimen.setObjectPublic(tmp == null || tmp.trim().equals("1")); tmp = val(record, "abcd:MultiMediaPublic"); specimen.setMultiMediaPublic(tmp == null || tmp.trim().equals("1")); tmp = val(record, "abcd:FromCaptivity"); specimen.setFromCaptivity(tmp != null && tmp.trim().equals("1")); tmp = val(record, "abcd:PreparationType"); if (tmp == null) { tmp = val(record, "abcd:SpecimenMount"); } specimen.setPreparationType(tmp); specimen.setPhaseOrStage(getPhaseOrStage()); specimen.setSex(getSex()); specimen.setGatheringEvent(getGatheringEvent()); specimen.setDateLastEdited(getDateLastEdited()); specimen.setAssociatedMultiMediaUris(getAssociatedMultiMediaUris()); stats.objectsAccepted++; return Collections.singletonList(specimen); } catch (Throwable t) { handleError(t); return null; } } CrsSpecimenTransformer(ETLStatistics stats);   }