From 58564c3c2efebe5a91cf99c1c07c86e860aa5a9d Mon Sep 17 00:00:00 2001 From: Matthew Blissett Date: Mon, 19 Mar 2018 16:47:38 +0100 Subject: [PATCH] Remove DarwinCoreRecord and DarwinCoreTaxon. These have not been kept up to date with changes in the standard. Resolves https://github.com/gbif/dwca-io/issues/44. --- pom.xml | 2 +- src/main/java/org/gbif/dwca/io/Archive.java | 89 -- .../gbif/dwca/record/DarwinCoreRecord.java | 1217 ----------------- .../org/gbif/dwca/record/DarwinCoreTaxon.java | 767 ----------- .../java/org/gbif/dwca/io/ArchiveTest.java | 39 +- .../dwca/io/ScanArchiveForScientificName.java | 29 +- .../dwca/record/DarwinCoreRecordTest.java | 68 - .../gbif/dwca/record/DarwinCoreTaxonTest.java | 194 --- src/test/resources/simplest-archive/meta.xml | 11 + src/test/resources/simplest-archive/taxa.txt | 3 + 10 files changed, 32 insertions(+), 2387 deletions(-) delete mode 100644 src/main/java/org/gbif/dwca/record/DarwinCoreRecord.java delete mode 100644 src/main/java/org/gbif/dwca/record/DarwinCoreTaxon.java delete mode 100644 src/test/java/org/gbif/dwca/record/DarwinCoreRecordTest.java delete mode 100644 src/test/java/org/gbif/dwca/record/DarwinCoreTaxonTest.java create mode 100644 src/test/resources/simplest-archive/meta.xml create mode 100644 src/test/resources/simplest-archive/taxa.txt diff --git a/pom.xml b/pom.xml index 5f68f9494..b210099ca 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ dwca-io - 1.33-SNAPSHOT + 2.0-SNAPSHOT jar Darwin Core Archive IO Library diff --git a/src/main/java/org/gbif/dwca/io/Archive.java b/src/main/java/org/gbif/dwca/io/Archive.java index d8d9ae499..8ecaff80e 100644 --- a/src/main/java/org/gbif/dwca/io/Archive.java +++ b/src/main/java/org/gbif/dwca/io/Archive.java @@ -3,19 +3,14 @@ import org.gbif.api.model.registry.Dataset; import org.gbif.dwc.DwcFiles; import org.gbif.dwc.DwcLayout; -import org.gbif.dwc.terms.DcTerm; -import org.gbif.dwc.terms.DwcTerm; import org.gbif.dwc.terms.Term; -import org.gbif.dwca.record.DarwinCoreRecord; import org.gbif.dwca.record.Record; -import org.gbif.dwca.record.RecordImpl; import org.gbif.dwca.record.RecordIterator; import org.gbif.dwca.record.StarRecord; import org.gbif.dwca.record.StarRecordImpl; import org.gbif.registry.metadata.parse.DatasetParser; import org.gbif.utils.file.ClosableIterator; import org.gbif.utils.file.FileUtils; -import org.gbif.utils.file.csv.CSVReader; import java.io.File; import java.io.FilenameFilter; @@ -48,81 +43,6 @@ public class Archive implements Iterable { public static final String CONSTITUENT_DIR = "dataset"; public static final String META_FN = "meta.xml"; - /** - * An iterator of fixed DarwinCoreRecords over the core file only. This iterator doesn't need any sorted data files - * as it doesn't deal with extensions. - */ - @Deprecated - static class ArchiveDwcIterator implements ClosableIterator { - - private CSVReader coreReader; - private ArchiveFile core; - private int lineCount = 0; - private final RecordImpl record; - private boolean hasNext = true; - private final Set mappedTerms = new HashSet(); - - ArchiveDwcIterator(Archive archive) { - record = new RecordImpl(archive.getCore(), true, true); - core = archive.getCore(); - // remember used DwC and DC terms - for (DwcTerm term : DwcTerm.values()) { - if (core.hasTerm(term)) { - mappedTerms.add(term); - } - } - for (DcTerm term : DcTerm.values()) { - if (core.hasTerm(term)) { - mappedTerms.add(term); - } - } - try { - coreReader = archive.getCore().getCSVReader(); - // read first core row - record.setRow(coreReader.next()); - if (!record.hasRow()) { - hasNext = false; - } - } catch (Exception e) { - hasNext = false; - LOG.warn("Exception caught", e); - } - } - - public void close() { - coreReader.close(); - } - - public boolean hasNext() { - return hasNext; - } - - public DarwinCoreRecord next() { - DarwinCoreRecord dwc = new DarwinCoreRecord(); - lineCount++; - try { - for (Term term : mappedTerms) { - dwc.setProperty(term, record.value(term)); - } - dwc.setId(record.id()); - // read next line to see if it exists at all - record.setRow(coreReader.next()); - if (!record.hasRow()) { - hasNext = false; - } - - } catch (Exception e) { - LOG.warn("Bad row somewhere around core line: {}", lineCount, e); - } - return dwc; - } - - public void remove() { - throw new UnsupportedOperationException("Cannot remove a row from archive files"); - } - - } - /** * This class is kept for legacy reason, See {@link DwcFiles} for new usage. * @@ -377,15 +297,6 @@ public ClosableIterator iteratorRaw() { return new ArchiveIterator(this, false, false); } - /** - * @return an iterator over simple darwin core records based on the core data file(s). The DarwinCoreRecord instance - * is reused to give better performance, so create a clone before referencing it. - */ - @Deprecated - public ClosableIterator iteratorDwc() { - return new ArchiveDwcIterator(this); - } - public void setCore(ArchiveFile core) { core.setArchive(this); this.core = core; diff --git a/src/main/java/org/gbif/dwca/record/DarwinCoreRecord.java b/src/main/java/org/gbif/dwca/record/DarwinCoreRecord.java deleted file mode 100644 index 34eb8959e..000000000 --- a/src/main/java/org/gbif/dwca/record/DarwinCoreRecord.java +++ /dev/null @@ -1,1217 +0,0 @@ -package org.gbif.dwca.record; - -import com.google.common.base.Objects; - -/** - * A bean representing a simple Darwin Core record with a property for each dwc term apart from terms of group - * MeasurementOrFact or ResourceRelationship. - */ -public class DarwinCoreRecord extends DarwinCoreTaxon { - - private String id; - private String associatedMedia; - private String associatedOccurrences; - private String associatedOrganisms; - private String associatedReferences; - private String associatedSequences; - private String associatedTaxa; - private String bed; - private String behavior; - private String catalogNumber; - private String continent; - private String coordinatePrecision; - private String coordinateUncertaintyInMeters; - private String country; - private String countryCode; - private String county; - private String dateIdentified; - private String day; - private String decimalLatitude; - private String decimalLongitude; - private String disposition; - private String earliestAgeOrLowestStage; - private String earliestEonOrLowestEonothem; - private String earliestEpochOrLowestSeries; - private String earliestEraOrLowestErathem; - private String earliestPeriodOrLowestSystem; - private String endDayOfYear; - private String establishmentMeans; - private String eventDate; - private String eventID; - private String eventRemarks; - private String eventTime; - private String fieldNotes; - private String fieldNumber; - private String footprintSpatialFit; - private String footprintSRS; - private String footprintWKT; - private String formation; - private String geodeticDatum; - private String geologicalContextID; - private String georeferencedBy; - private String georeferencedDate; - private String georeferenceProtocol; - private String georeferenceRemarks; - private String georeferenceSources; - private String georeferenceVerificationStatus; - private String group; - private String habitat; - private String higherGeography; - private String higherGeographyID; - private String highestBiostratigraphicZone; - private String identificationID; - private String identificationQualifier; - private String identificationReferences; - private String identificationRemarks; - private String identificationVerificationStatus; - private String identifiedBy; - private String individualCount; - private String island; - private String islandGroup; - private String latestAgeOrHighestStage; - private String latestEonOrHighestEonothem; - private String latestEpochOrHighestSeries; - private String latestEraOrHighestErathem; - private String latestPeriodOrHighestSystem; - private String lifeStage; - private String lithostratigraphicTerms; - private String locality; - private String locationAccordingTo; - private String locationID; - private String locationRemarks; - private String lowestBiostratigraphicZone; - private String materialSampleID; - private String maximumDepthInMeters; - private String maximumDistanceAboveSurfaceInMeters; - private String maximumElevationInMeters; - private String member; - private String minimumDepthInMeters; - private String minimumDistanceAboveSurfaceInMeters; - private String minimumElevationInMeters; - private String month; - private String municipality; - private String occurrenceID; - private String occurrenceRemarks; - private String occurrenceStatus; - private String organismID; - private String organismName; - private String organismQuantity; - private String organismQuantityType; - private String organismRemarks; - private String organismScope; - private String otherCatalogNumbers; - private String parentEventID; - private String pointRadiusSpatialFit; - private String preparations; - private String previousIdentifications; - private String recordedBy; - private String recordNumber; - private String reproductiveCondition; - private String samplingEffort; - private String sampleSizeUnit; - private String sampleSizeValue; - private String samplingProtocol; - private String sex; - private String startDayOfYear; - private String stateProvince; - private String typeStatus; - private String verbatimCoordinates; - private String verbatimCoordinateSystem; - private String verbatimDepth; - private String verbatimElevation; - private String verbatimEventDate; - private String verbatimLatitude; - private String verbatimLocality; - private String verbatimLongitude; - private String verbatimSRS; - private String waterBody; - private String year; - - /** - * @return the identifier for this record - */ - public String id() { - return id; - } - - /** - * @return the identifier for this record - */ - public String getId() { - return id; - } - - /** - * sets the identifier for this record - */ - public void setId(String id) { - this.id = id; - } - - public String getAssociatedMedia() { - return associatedMedia; - } - - public String getAssociatedOccurrences() { - return associatedOccurrences; - } - - public String getAssociatedOrganisms() { - return associatedOrganisms; - } - - public String getAssociatedReferences() { - return associatedReferences; - } - - public String getAssociatedSequences() { - return associatedSequences; - } - - public String getAssociatedTaxa() { - return associatedTaxa; - } - - public String getBed() { - return bed; - } - - public String getBehavior() { - return behavior; - } - - public String getCatalogNumber() { - return catalogNumber; - } - - public String getContinent() { - return continent; - } - - public String getCoordinatePrecision() { - return coordinatePrecision; - } - - public String getCoordinateUncertaintyInMeters() { - return coordinateUncertaintyInMeters; - } - - public String getCountry() { - return country; - } - - public String getCountryCode() { - return countryCode; - } - - public String getCounty() { - return county; - } - - public String getDateIdentified() { - return dateIdentified; - } - - public String getDay() { - return day; - } - - public String getDecimalLatitude() { - return decimalLatitude; - } - - public String getDecimalLongitude() { - return decimalLongitude; - } - - public String getDisposition() { - return disposition; - } - - public String getEarliestAgeOrLowestStage() { - return earliestAgeOrLowestStage; - } - - public String getEarliestEonOrLowestEonothem() { - return earliestEonOrLowestEonothem; - } - - public String getEarliestEpochOrLowestSeries() { - return earliestEpochOrLowestSeries; - } - - public String getEarliestEraOrLowestErathem() { - return earliestEraOrLowestErathem; - } - - public String getEarliestPeriodOrLowestSystem() { - return earliestPeriodOrLowestSystem; - } - - public String getEndDayOfYear() { - return endDayOfYear; - } - - public String getEstablishmentMeans() { - return establishmentMeans; - } - - public String getEventDate() { - return eventDate; - } - - public String getEventID() { - return eventID; - } - - public String getEventRemarks() { - return eventRemarks; - } - - public String getEventTime() { - return eventTime; - } - - public String getFieldNotes() { - return fieldNotes; - } - - public String getFieldNumber() { - return fieldNumber; - } - - public String getFootprintSpatialFit() { - return footprintSpatialFit; - } - - public String getFootprintSRS() { - return footprintSRS; - } - - public String getFootprintWKT() { - return footprintWKT; - } - - public String getFormation() { - return formation; - } - - public String getGeodeticDatum() { - return geodeticDatum; - } - - public String getGeologicalContextID() { - return geologicalContextID; - } - - public String getGeoreferencedBy() { - return georeferencedBy; - } - - public String getGeoreferencedDate() { - return georeferencedDate; - } - - public String getGeoreferenceProtocol() { - return georeferenceProtocol; - } - - public String getGeoreferenceRemarks() { - return georeferenceRemarks; - } - - public String getGeoreferenceSources() { - return georeferenceSources; - } - - public String getGeoreferenceVerificationStatus() { - return georeferenceVerificationStatus; - } - - public String getGroup() { - return group; - } - - public String getHabitat() { - return habitat; - } - - public String getHigherGeography() { - return higherGeography; - } - - public String getHigherGeographyID() { - return higherGeographyID; - } - - public String getHighestBiostratigraphicZone() { - return highestBiostratigraphicZone; - } - - public String getIdentificationID() { - return identificationID; - } - - public String getIdentificationQualifier() { - return identificationQualifier; - } - - public String getIdentificationReferences() { - return identificationReferences; - } - - public String getIdentificationRemarks() { - return identificationRemarks; - } - - public String getIdentificationVerificationStatus() { - return identificationVerificationStatus; - } - - public String getIdentifiedBy() { - return identifiedBy; - } - - public String getIndividualCount() { - return individualCount; - } - - public String getIsland() { - return island; - } - - public String getIslandGroup() { - return islandGroup; - } - - public String getLatestAgeOrHighestStage() { - return latestAgeOrHighestStage; - } - - public String getLatestEonOrHighestEonothem() { - return latestEonOrHighestEonothem; - } - - public String getLatestEpochOrHighestSeries() { - return latestEpochOrHighestSeries; - } - - public String getLatestEraOrHighestErathem() { - return latestEraOrHighestErathem; - } - - public String getLatestPeriodOrHighestSystem() { - return latestPeriodOrHighestSystem; - } - - public String getLifeStage() { - return lifeStage; - } - - public String getLithostratigraphicTerms() { - return lithostratigraphicTerms; - } - - public String getLocality() { - return locality; - } - - public String getLocationAccordingTo() { - return locationAccordingTo; - } - - public String getLocationID() { - return locationID; - } - - public String getLocationRemarks() { - return locationRemarks; - } - - public String getLowestBiostratigraphicZone() { - return lowestBiostratigraphicZone; - } - - public String getMaterialSampleID() { - return materialSampleID; - } - - public String getMaximumDepthInMeters() { - return maximumDepthInMeters; - } - - public String getMaximumDistanceAboveSurfaceInMeters() { - return maximumDistanceAboveSurfaceInMeters; - } - - public String getMaximumElevationInMeters() { - return maximumElevationInMeters; - } - - public String getMember() { - return member; - } - - public String getMinimumDepthInMeters() { - return minimumDepthInMeters; - } - - public String getMinimumDistanceAboveSurfaceInMeters() { - return minimumDistanceAboveSurfaceInMeters; - } - - public String getMinimumElevationInMeters() { - return minimumElevationInMeters; - } - - public String getMonth() { - return month; - } - - public String getMunicipality() { - return municipality; - } - - public String getOccurrenceID() { - return occurrenceID; - } - - public String getOccurrenceRemarks() { - return occurrenceRemarks; - } - - public String getOccurrenceStatus() { - return occurrenceStatus; - } - - public String getOrganismID() { - return organismID; - } - - public String getOrganismName() { - return organismName; - } - - public String getOrganismQuantity() { - return organismQuantity; - } - - public String getOrganismQuantityType() { - return organismQuantityType; - } - - public String getOrganismRemarks() { - return organismRemarks; - } - - public String getOrganismScope() { - return organismScope; - } - - public String getOtherCatalogNumbers() { - return otherCatalogNumbers; - } - - public String getParentEventID() { - return parentEventID; - } - - public String getPointRadiusSpatialFit() { - return pointRadiusSpatialFit; - } - - public String getPreparations() { - return preparations; - } - - public String getPreviousIdentifications() { - return previousIdentifications; - } - - public String getRecordedBy() { - return recordedBy; - } - - public String getRecordNumber() { - return recordNumber; - } - - public String getReproductiveCondition() { - return reproductiveCondition; - } - - public String getSamplingEffort() { - return samplingEffort; - } - - public String getSamplingProtocol() { - return samplingProtocol; - } - - public String getSampleSizeUnit() { - return sampleSizeUnit; - } - - public String getSampleSizeValue() { - return sampleSizeValue; - } - - public String getSex() { - return sex; - } - - public String getStartDayOfYear() { - return startDayOfYear; - } - - public String getStateProvince() { - return stateProvince; - } - - public String getTypeStatus() { - return typeStatus; - } - - public String getVerbatimCoordinates() { - return verbatimCoordinates; - } - - public String getVerbatimCoordinateSystem() { - return verbatimCoordinateSystem; - } - - public String getVerbatimDepth() { - return verbatimDepth; - } - - public String getVerbatimElevation() { - return verbatimElevation; - } - - public String getVerbatimEventDate() { - return verbatimEventDate; - } - - public String getVerbatimLatitude() { - return verbatimLatitude; - } - - public String getVerbatimLocality() { - return verbatimLocality; - } - - public String getVerbatimLongitude() { - return verbatimLongitude; - } - - public String getVerbatimSRS() { - return verbatimSRS; - } - - public String getWaterBody() { - return waterBody; - } - - public String getYear() { - return year; - } - - public void setAssociatedMedia(String associatedMedia) { - this.associatedMedia = norm(associatedMedia); - } - - public void setAssociatedOccurrences(String associatedOccurrences) { - this.associatedOccurrences = norm(associatedOccurrences); - } - - public void setAssociatedOrganisms(String associatedOrganisms) { - this.associatedOrganisms = norm(associatedOrganisms); - } - - public void setAssociatedReferences(String associatedReferences) { - this.associatedReferences = norm(associatedReferences); - } - - public void setAssociatedSequences(String associatedSequences) { - this.associatedSequences = norm(associatedSequences); - } - - public void setAssociatedTaxa(String associatedTaxa) { - this.associatedTaxa = norm(associatedTaxa); - } - - public void setBed(String bed) { - this.bed = bed; - } - - public void setBehavior(String behavior) { - this.behavior = norm(behavior); - } - - public void setCatalogNumber(String catalogNumber) { - this.catalogNumber = norm(catalogNumber); - } - - public void setContinent(String continent) { - this.continent = norm(continent); - } - - public void setCoordinatePrecision(String coordinatePrecision) { - this.coordinatePrecision = norm(coordinatePrecision); - } - - public void setCoordinateUncertaintyInMeters(String coordinateUncertaintyInMeters) { - this.coordinateUncertaintyInMeters = norm(coordinateUncertaintyInMeters); - } - - public void setCountry(String country) { - this.country = norm(country); - } - - public void setCountryCode(String countryCode) { - this.countryCode = norm(countryCode); - } - - public void setCounty(String county) { - this.county = norm(county); - } - - public void setDateIdentified(String dateIdentified) { - this.dateIdentified = norm(dateIdentified); - } - - public void setDay(String day) { - this.day = norm(day); - } - - public void setDecimalLatitude(String decimalLatitude) { - this.decimalLatitude = norm(decimalLatitude); - } - - public void setDecimalLongitude(String decimalLongitude) { - this.decimalLongitude = norm(decimalLongitude); - } - - public void setDisposition(String disposition) { - this.disposition = norm(disposition); - } - - public void setEarliestAgeOrLowestStage(String earliestAgeOrLowestStage) { - this.earliestAgeOrLowestStage = earliestAgeOrLowestStage; - } - - public void setEarliestEonOrLowestEonothem(String earliestEonOrLowestEonothem) { - this.earliestEonOrLowestEonothem = earliestEonOrLowestEonothem; - } - - public void setEarliestEpochOrLowestSeries(String earliestEpochOrLowestSeries) { - this.earliestEpochOrLowestSeries = earliestEpochOrLowestSeries; - } - - public void setEarliestEraOrLowestErathem(String earliestEraOrLowestErathem) { - this.earliestEraOrLowestErathem = earliestEraOrLowestErathem; - } - - public void setEarliestPeriodOrLowestSystem(String earliestPeriodOrLowestSystem) { - this.earliestPeriodOrLowestSystem = earliestPeriodOrLowestSystem; - } - - public void setEndDayOfYear(String endDayOfYear) { - this.endDayOfYear = norm(endDayOfYear); - } - - public void setEstablishmentMeans(String establishmentMeans) { - this.establishmentMeans = norm(establishmentMeans); - } - - public void setEventDate(String eventDate) { - this.eventDate = norm(eventDate); - } - - public void setEventID(String eventID) { - this.eventID = norm(eventID); - } - - public void setEventRemarks(String eventRemarks) { - this.eventRemarks = norm(eventRemarks); - } - - public void setEventTime(String eventTime) { - this.eventTime = norm(eventTime); - } - - public void setFieldNotes(String fieldNotes) { - this.fieldNotes = norm(fieldNotes); - } - - public void setFieldNumber(String fieldNumber) { - this.fieldNumber = norm(fieldNumber); - } - - public void setFootprintSpatialFit(String footprintSpatialFit) { - this.footprintSpatialFit = norm(footprintSpatialFit); - } - - public void setFootprintSRS(String footprintSRS) { - this.footprintSRS = footprintSRS; - } - - public void setFootprintWKT(String footprintWKT) { - this.footprintWKT = norm(footprintWKT); - } - - public void setFormation(String formation) { - this.formation = formation; - } - - public void setGeodeticDatum(String geodeticDatum) { - this.geodeticDatum = norm(geodeticDatum); - } - - public void setGeologicalContextID(String geologicalContextID) { - this.geologicalContextID = geologicalContextID; - } - - public void setGeoreferencedBy(String georeferencedBy) { - this.georeferencedBy = norm(georeferencedBy); - } - - public void setGeoreferencedDate(String georeferencedDate) { - this.georeferencedDate = georeferencedDate; - } - - public void setGeoreferenceProtocol(String georeferenceProtocol) { - this.georeferenceProtocol = norm(georeferenceProtocol); - } - - public void setGeoreferenceRemarks(String georeferenceRemarks) { - this.georeferenceRemarks = norm(georeferenceRemarks); - } - - public void setGeoreferenceSources(String georeferenceSources) { - this.georeferenceSources = norm(georeferenceSources); - } - - public void setGeoreferenceVerificationStatus(String georeferenceVerificationStatus) { - this.georeferenceVerificationStatus = norm(georeferenceVerificationStatus); - } - - public void setGroup(String group) { - this.group = group; - } - - public void setHabitat(String habitat) { - this.habitat = norm(habitat); - } - - public void setHigherGeography(String higherGeography) { - this.higherGeography = norm(higherGeography); - } - - public void setHigherGeographyID(String higherGeographyID) { - this.higherGeographyID = norm(higherGeographyID); - } - - public void setHighestBiostratigraphicZone(String highestBiostratigraphicZone) { - this.highestBiostratigraphicZone = highestBiostratigraphicZone; - } - - public void setIdentificationID(String identificationID) { - this.identificationID = norm(identificationID); - } - - public void setIdentificationQualifier(String identificationQualifier) { - this.identificationQualifier = norm(identificationQualifier); - } - - public void setIdentificationReferences(String identificationReferences) { - this.identificationReferences = norm(identificationReferences); - } - - public void setIdentificationRemarks(String identificationRemarks) { - this.identificationRemarks = norm(identificationRemarks); - } - - public void setIdentificationVerificationStatus(String identificationVerificationStatus) { - this.identificationVerificationStatus = identificationVerificationStatus; - } - - public void setIdentifiedBy(String identifiedBy) { - this.identifiedBy = norm(identifiedBy); - } - - public void setIndividualCount(String individualCount) { - this.individualCount = norm(individualCount); - } - - public void setIsland(String island) { - this.island = norm(island); - } - - public void setIslandGroup(String islandGroup) { - this.islandGroup = norm(islandGroup); - } - - public void setLatestAgeOrHighestStage(String latestAgeOrHighestStage) { - this.latestAgeOrHighestStage = latestAgeOrHighestStage; - } - - public void setLatestEonOrHighestEonothem(String latestEonOrHighestEonothem) { - this.latestEonOrHighestEonothem = latestEonOrHighestEonothem; - } - - public void setLatestEpochOrHighestSeries(String latestEpochOrHighestSeries) { - this.latestEpochOrHighestSeries = latestEpochOrHighestSeries; - } - - public void setLatestEraOrHighestErathem(String latestEraOrHighestErathem) { - this.latestEraOrHighestErathem = latestEraOrHighestErathem; - } - - public void setLatestPeriodOrHighestSystem(String latestPeriodOrHighestSystem) { - this.latestPeriodOrHighestSystem = latestPeriodOrHighestSystem; - } - - public void setLifeStage(String lifeStage) { - this.lifeStage = norm(lifeStage); - } - - public void setLithostratigraphicTerms(String lithostratigraphicTerms) { - this.lithostratigraphicTerms = lithostratigraphicTerms; - } - - public void setLocality(String locality) { - this.locality = norm(locality); - } - - public void setLocationAccordingTo(String locationAccordingTo) { - this.locationAccordingTo = locationAccordingTo; - } - - public void setLocationID(String locationID) { - this.locationID = norm(locationID); - } - - public void setLocationRemarks(String locationRemarks) { - this.locationRemarks = norm(locationRemarks); - } - - public void setLowestBiostratigraphicZone(String lowestBiostratigraphicZone) { - this.lowestBiostratigraphicZone = lowestBiostratigraphicZone; - } - - public void setMaterialSampleID(String materialSampleID) { - this.materialSampleID = materialSampleID; - } - - public void setMaximumDepthInMeters(String maximumDepthInMeters) { - this.maximumDepthInMeters = norm(maximumDepthInMeters); - } - - public void setMaximumDistanceAboveSurfaceInMeters(String maximumDistanceAboveSurfaceInMeters) { - this.maximumDistanceAboveSurfaceInMeters = norm(maximumDistanceAboveSurfaceInMeters); - } - - public void setMaximumElevationInMeters(String maximumElevationInMeters) { - this.maximumElevationInMeters = norm(maximumElevationInMeters); - } - - public void setMember(String member) { - this.member = member; - } - - public void setMinimumDepthInMeters(String minimumDepthInMeters) { - this.minimumDepthInMeters = norm(minimumDepthInMeters); - } - - public void setMinimumDistanceAboveSurfaceInMeters(String minimumDistanceAboveSurfaceInMeters) { - this.minimumDistanceAboveSurfaceInMeters = norm(minimumDistanceAboveSurfaceInMeters); - } - - public void setMinimumElevationInMeters(String minimumElevationInMeters) { - this.minimumElevationInMeters = norm(minimumElevationInMeters); - } - - public void setMonth(String month) { - this.month = norm(month); - } - - public void setMunicipality(String municipality) { - this.municipality = municipality; - } - - public void setOccurrenceID(String occurrenceID) { - this.occurrenceID = norm(occurrenceID); - } - - public void setOccurrenceRemarks(String occurrenceRemarks) { - this.occurrenceRemarks = norm(occurrenceRemarks); - } - - public void setOccurrenceStatus(String occurrenceStatus) { - this.occurrenceStatus = occurrenceStatus; - } - - public void setOrganismID(String organismID) { - this.organismID = norm(organismID); - } - - public void setOrganismName(String organismName) { - this.organismName = norm(organismName); - } - - public void setOrganismQuantity(String organismQuantity) { - this.organismQuantity = organismQuantity; - } - - public void setOrganismQuantityType(String organismQuantityType) { - this.organismQuantityType = organismQuantityType; - } - - public void setOrganismRemarks(String organismRemarks) { - this.organismRemarks = norm(organismRemarks); - } - - public void setOrganismScope(String organismScope) { - this.organismScope = norm(organismScope); - } - - public void setOtherCatalogNumbers(String otherCatalogNumbers) { - this.otherCatalogNumbers = norm(otherCatalogNumbers); - } - - public void setParentEventID(String parentEventID) { - this.parentEventID = parentEventID; - } - - public void setPointRadiusSpatialFit(String pointRadiusSpatialFit) { - this.pointRadiusSpatialFit = norm(pointRadiusSpatialFit); - } - - public void setPreparations(String preparations) { - this.preparations = norm(preparations); - } - - public void setPreviousIdentifications(String previousIdentifications) { - this.previousIdentifications = norm(previousIdentifications); - } - - public void setRecordedBy(String recordedBy) { - this.recordedBy = norm(recordedBy); - } - - public void setRecordNumber(String recordNumber) { - this.recordNumber = norm(recordNumber); - } - - public void setReproductiveCondition(String reproductiveCondition) { - this.reproductiveCondition = norm(reproductiveCondition); - } - - public void setSamplingEffort(String samplingEffort) { - this.samplingEffort = samplingEffort; - } - - public void setSamplingProtocol(String samplingProtocol) { - this.samplingProtocol = norm(samplingProtocol); - } - - public void setSampleSizeUnit(String sampleSizeUnit) { - this.sampleSizeUnit = sampleSizeUnit; - } - - public void setSampleSizeValue(String sampleSizeValue) { - this.sampleSizeValue = sampleSizeValue; - } - - public void setSex(String sex) { - this.sex = norm(sex); - } - - public void setStartDayOfYear(String startDayOfYear) { - this.startDayOfYear = norm(startDayOfYear); - } - - public void setStateProvince(String stateProvince) { - this.stateProvince = norm(stateProvince); - } - - public void setTypeStatus(String typeStatus) { - this.typeStatus = norm(typeStatus); - } - - public void setVerbatimCoordinates(String verbatimCoordinates) { - this.verbatimCoordinates = norm(verbatimCoordinates); - } - - public void setVerbatimCoordinateSystem(String verbatimCoordinateSystem) { - this.verbatimCoordinateSystem = norm(verbatimCoordinateSystem); - } - - public void setVerbatimDepth(String verbatimDepth) { - this.verbatimDepth = norm(verbatimDepth); - } - - public void setVerbatimElevation(String verbatimElevation) { - this.verbatimElevation = norm(verbatimElevation); - } - - public void setVerbatimEventDate(String verbatimEventDate) { - this.verbatimEventDate = norm(verbatimEventDate); - } - - public void setVerbatimLatitude(String verbatimLatitude) { - this.verbatimLatitude = norm(verbatimLatitude); - } - - public void setVerbatimLocality(String verbatimLocality) { - this.verbatimLocality = norm(verbatimLocality); - } - - public void setVerbatimLongitude(String verbatimLongitude) { - this.verbatimLongitude = norm(verbatimLongitude); - } - - public void setVerbatimSRS(String verbatimSRS) { - this.verbatimSRS = verbatimSRS; - } - - public void setWaterBody(String waterBody) { - this.waterBody = norm(waterBody); - } - - public void setYear(String year) { - this.year = norm(year); - } - - @Override - public int hashCode() { - return Objects.hashCode(id, associatedMedia, associatedOccurrences, associatedOrganisms, associatedReferences, - associatedSequences, associatedTaxa, bed, behavior, catalogNumber, continent, coordinatePrecision, - coordinateUncertaintyInMeters, country, countryCode, county, dateIdentified, day, decimalLatitude, - decimalLongitude, disposition, earliestAgeOrLowestStage, earliestEonOrLowestEonothem, earliestEpochOrLowestSeries, - earliestEraOrLowestErathem, earliestPeriodOrLowestSystem, endDayOfYear, establishmentMeans, eventDate, eventID, - eventRemarks, eventTime, fieldNotes, fieldNumber, footprintSpatialFit, footprintSRS, footprintWKT, formation, - geodeticDatum, geologicalContextID, georeferencedBy, georeferencedDate, georeferenceProtocol, georeferenceRemarks, - georeferenceSources, georeferenceVerificationStatus, group, habitat, higherGeography, higherGeographyID, - highestBiostratigraphicZone, identificationID, identificationQualifier, identificationReferences, - identificationRemarks, identificationVerificationStatus, identifiedBy, individualCount, island, islandGroup, - latestAgeOrHighestStage, latestEonOrHighestEonothem, latestEpochOrHighestSeries, latestEraOrHighestErathem, - latestPeriodOrHighestSystem, lifeStage, lithostratigraphicTerms, locality, locationAccordingTo, locationID, - locationRemarks, lowestBiostratigraphicZone, materialSampleID, maximumDepthInMeters, - maximumDistanceAboveSurfaceInMeters, maximumElevationInMeters, member, minimumDepthInMeters, - minimumDistanceAboveSurfaceInMeters, minimumElevationInMeters, month, municipality, occurrenceID, - occurrenceRemarks, occurrenceStatus, organismID, organismName, organismQuantity, organismQuantityType, - organismRemarks, organismScope, otherCatalogNumbers, parentEventID, pointRadiusSpatialFit, preparations, - previousIdentifications, recordedBy, recordNumber, reproductiveCondition, samplingEffort, sampleSizeUnit, - sampleSizeValue, samplingProtocol, sex, startDayOfYear, stateProvince, typeStatus, verbatimCoordinates, - verbatimCoordinateSystem, verbatimDepth, verbatimElevation, verbatimEventDate, verbatimLatitude, verbatimLocality, - verbatimLongitude, verbatimSRS, waterBody, year); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - final DarwinCoreRecord other = (DarwinCoreRecord) obj; - return Objects.equal(this.id, other.id) && Objects.equal(this.associatedMedia, other.associatedMedia) && Objects - .equal(this.associatedOccurrences, other.associatedOccurrences) && Objects - .equal(this.associatedOrganisms, other.associatedOrganisms) && Objects - .equal(this.associatedReferences, other.associatedReferences) && Objects - .equal(this.associatedSequences, other.associatedSequences) && Objects - .equal(this.associatedTaxa, other.associatedTaxa) && Objects.equal(this.bed, other.bed) && Objects - .equal(this.behavior, other.behavior) && Objects.equal(this.catalogNumber, other.catalogNumber) && Objects - .equal(this.continent, other.continent) && Objects - .equal(this.coordinatePrecision, other.coordinatePrecision) && Objects - .equal(this.coordinateUncertaintyInMeters, other.coordinateUncertaintyInMeters) && Objects - .equal(this.country, other.country) && Objects.equal(this.countryCode, other.countryCode) && Objects - .equal(this.county, other.county) && Objects.equal(this.dateIdentified, other.dateIdentified) && Objects - .equal(this.day, other.day) && Objects.equal(this.decimalLatitude, other.decimalLatitude) && Objects - .equal(this.decimalLongitude, other.decimalLongitude) && Objects.equal(this.disposition, other.disposition) - && Objects.equal(this.earliestAgeOrLowestStage, other.earliestAgeOrLowestStage) && Objects - .equal(this.earliestEonOrLowestEonothem, other.earliestEonOrLowestEonothem) && Objects - .equal(this.earliestEpochOrLowestSeries, other.earliestEpochOrLowestSeries) && Objects - .equal(this.earliestEraOrLowestErathem, other.earliestEraOrLowestErathem) && Objects - .equal(this.earliestPeriodOrLowestSystem, other.earliestPeriodOrLowestSystem) && Objects - .equal(this.endDayOfYear, other.endDayOfYear) && Objects - .equal(this.establishmentMeans, other.establishmentMeans) && Objects.equal(this.eventDate, other.eventDate) - && Objects.equal(this.eventID, other.eventID) && Objects.equal(this.eventRemarks, other.eventRemarks) - && Objects.equal(this.eventTime, other.eventTime) && Objects.equal(this.fieldNotes, other.fieldNotes) - && Objects.equal(this.fieldNumber, other.fieldNumber) && Objects - .equal(this.footprintSpatialFit, other.footprintSpatialFit) && Objects - .equal(this.footprintSRS, other.footprintSRS) && Objects.equal(this.footprintWKT, other.footprintWKT) - && Objects.equal(this.formation, other.formation) && Objects.equal(this.geodeticDatum, other.geodeticDatum) - && Objects.equal(this.geologicalContextID, other.geologicalContextID) && Objects - .equal(this.georeferencedBy, other.georeferencedBy) && Objects - .equal(this.georeferencedDate, other.georeferencedDate) && Objects - .equal(this.georeferenceProtocol, other.georeferenceProtocol) && Objects - .equal(this.georeferenceRemarks, other.georeferenceRemarks) && Objects - .equal(this.georeferenceSources, other.georeferenceSources) && Objects - .equal(this.georeferenceVerificationStatus, other.georeferenceVerificationStatus) && Objects - .equal(this.group, other.group) && Objects.equal(this.habitat, other.habitat) && Objects - .equal(this.higherGeography, other.higherGeography) && Objects - .equal(this.higherGeographyID, other.higherGeographyID) && Objects - .equal(this.highestBiostratigraphicZone, other.highestBiostratigraphicZone) && Objects - .equal(this.identificationID, other.identificationID) && Objects - .equal(this.identificationQualifier, other.identificationQualifier) && Objects - .equal(this.identificationReferences, other.identificationReferences) && Objects - .equal(this.identificationRemarks, other.identificationRemarks) && Objects - .equal(this.identificationVerificationStatus, other.identificationVerificationStatus) && Objects - .equal(this.identifiedBy, other.identifiedBy) && Objects.equal(this.individualCount, other.individualCount) - && Objects.equal(this.island, other.island) && Objects.equal(this.islandGroup, other.islandGroup) && Objects - .equal(this.latestAgeOrHighestStage, other.latestAgeOrHighestStage) && Objects - .equal(this.latestEonOrHighestEonothem, other.latestEonOrHighestEonothem) && Objects - .equal(this.latestEpochOrHighestSeries, other.latestEpochOrHighestSeries) && Objects - .equal(this.latestEraOrHighestErathem, other.latestEraOrHighestErathem) && Objects - .equal(this.latestPeriodOrHighestSystem, other.latestPeriodOrHighestSystem) && Objects - .equal(this.lifeStage, other.lifeStage) && Objects - .equal(this.lithostratigraphicTerms, other.lithostratigraphicTerms) && Objects - .equal(this.locality, other.locality) && Objects.equal(this.locationAccordingTo, other.locationAccordingTo) - && Objects.equal(this.locationID, other.locationID) && Objects - .equal(this.locationRemarks, other.locationRemarks) && Objects - .equal(this.lowestBiostratigraphicZone, other.lowestBiostratigraphicZone) && Objects - .equal(this.materialSampleID, other.materialSampleID) && Objects - .equal(this.maximumDepthInMeters, other.maximumDepthInMeters) && Objects - .equal(this.maximumDistanceAboveSurfaceInMeters, other.maximumDistanceAboveSurfaceInMeters) && Objects - .equal(this.maximumElevationInMeters, other.maximumElevationInMeters) && Objects - .equal(this.member, other.member) && Objects.equal(this.minimumDepthInMeters, other.minimumDepthInMeters) - && Objects.equal(this.minimumDistanceAboveSurfaceInMeters, other.minimumDistanceAboveSurfaceInMeters) - && Objects.equal(this.minimumElevationInMeters, other.minimumElevationInMeters) && Objects - .equal(this.month, other.month) && Objects.equal(this.municipality, other.municipality) && Objects - .equal(this.occurrenceID, other.occurrenceID) && Objects - .equal(this.occurrenceRemarks, other.occurrenceRemarks) && Objects - .equal(this.occurrenceStatus, other.occurrenceStatus) && Objects.equal(this.organismID, other.organismID) - && Objects.equal(this.organismName, other.organismName) && Objects - .equal(this.organismQuantity, other.organismQuantity) && Objects - .equal(this.organismQuantityType, other.organismQuantityType) && Objects - .equal(this.organismRemarks, other.organismRemarks) && Objects - .equal(this.organismScope, other.organismScope) && Objects - .equal(this.otherCatalogNumbers, other.otherCatalogNumbers) && Objects - .equal(this.parentEventID, other.parentEventID) && Objects - .equal(this.pointRadiusSpatialFit, other.pointRadiusSpatialFit) && Objects - .equal(this.preparations, other.preparations) && Objects - .equal(this.previousIdentifications, other.previousIdentifications) && Objects - .equal(this.recordedBy, other.recordedBy) && Objects.equal(this.recordNumber, other.recordNumber) - && Objects.equal(this.reproductiveCondition, other.reproductiveCondition) && Objects - .equal(this.samplingEffort, other.samplingEffort) && Objects - .equal(this.sampleSizeUnit, other.sampleSizeUnit) && Objects - .equal(this.sampleSizeValue, other.sampleSizeValue) && Objects - .equal(this.samplingProtocol, other.samplingProtocol) && Objects.equal(this.sex, other.sex) && Objects - .equal(this.startDayOfYear, other.startDayOfYear) && Objects.equal(this.stateProvince, other.stateProvince) - && Objects.equal(this.typeStatus, other.typeStatus) && Objects - .equal(this.verbatimCoordinates, other.verbatimCoordinates) && Objects - .equal(this.verbatimCoordinateSystem, other.verbatimCoordinateSystem) && Objects - .equal(this.verbatimDepth, other.verbatimDepth) && Objects - .equal(this.verbatimElevation, other.verbatimElevation) && Objects - .equal(this.verbatimEventDate, other.verbatimEventDate) && Objects - .equal(this.verbatimLatitude, other.verbatimLatitude) && Objects - .equal(this.verbatimLocality, other.verbatimLocality) && Objects - .equal(this.verbatimLongitude, other.verbatimLongitude) && Objects - .equal(this.verbatimSRS, other.verbatimSRS) && Objects.equal(this.waterBody, other.waterBody) && Objects - .equal(this.year, other.year); - } -} diff --git a/src/main/java/org/gbif/dwca/record/DarwinCoreTaxon.java b/src/main/java/org/gbif/dwca/record/DarwinCoreTaxon.java deleted file mode 100644 index a98b0e775..000000000 --- a/src/main/java/org/gbif/dwca/record/DarwinCoreTaxon.java +++ /dev/null @@ -1,767 +0,0 @@ -package org.gbif.dwca.record; - -import org.gbif.dwc.terms.Term; - -import java.lang.reflect.Method; -import java.util.regex.Pattern; - -import com.google.common.base.Objects; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DarwinCoreTaxon { - - private static final Logger LOG = LoggerFactory.getLogger(DarwinCoreTaxon.class); - private static final String CLASSIFICATION_DELIMITER = " | "; - private static final Pattern NORM_AUTHORS = Pattern.compile("[^a-z0-9]+"); - private String type; - private String modified; - private String language; - private String license; - private String rightsHolder; - private String accessRights; - private String bibliographicCitation; - private String references; - - private String institutionID; - private String collectionID; - private String datasetID; - private String institutionCode; - private String collectionCode; - private String datasetName; - private String ownerInstitutionCode; - private String basisOfRecord; - private String informationWithheld; - private String dataGeneralizations; - private String dynamicProperties; - private String taxonID; - private String scientificNameID; - private String acceptedNameUsageID; - private String parentNameUsageID; - private String originalNameUsageID; - private String nameAccordingToID; - private String namePublishedInID; - private String taxonConceptID; - private String scientificName; - private String acceptedNameUsage; - private String parentNameUsage; - private String originalNameUsage; - private String nameAccordingTo; - private String namePublishedIn; - private String namePublishedInYear; - private String higherClassification; - private String kingdom; - private String phylum; - private String classs; - private String order; - private String family; - private String genus; - private String subgenus; - private String specificEpithet; - private String infraspecificEpithet; - private String taxonRank; - private String verbatimTaxonRank; - private String scientificNameAuthorship; - private String vernacularName; - private String nomenclaturalCode; - private String taxonomicStatus; - private String nomenclaturalStatus; - private String taxonRemarks; - - public DarwinCoreTaxon() { - } - - public DarwinCoreTaxon(String scientificName) { - this.scientificName = norm(scientificName); - } - - public String buildHigherClassification(Character lowestRank) { - StringBuilder buf = new StringBuilder(); - if (kingdom != null) { - buf.append(StringUtils.capitalize(kingdom.toLowerCase())); - buf.append(CLASSIFICATION_DELIMITER); - } - if (lowestRank == null || lowestRank != 'k') { - if (phylum != null) { - buf.append(StringUtils.capitalize(phylum.toLowerCase())); - buf.append(CLASSIFICATION_DELIMITER); - } - if (lowestRank == null || lowestRank != 'p') { - if (classs != null) { - buf.append(StringUtils.capitalize(classs.toLowerCase())); - buf.append(CLASSIFICATION_DELIMITER); - } - if (lowestRank == null || lowestRank != 'c') { - if (order != null) { - buf.append(StringUtils.capitalize(order.toLowerCase())); - buf.append(CLASSIFICATION_DELIMITER); - } - if (lowestRank == null || lowestRank != 'o') { - if (family != null) { - buf.append(StringUtils.capitalize(family.toLowerCase())); - buf.append(CLASSIFICATION_DELIMITER); - } - if (lowestRank == null || lowestRank != 'f') { - if (genus != null) { - buf.append(StringUtils.capitalize(genus.toLowerCase())); - buf.append(CLASSIFICATION_DELIMITER); - } - if (lowestRank == null || lowestRank != 'g') { - if (subgenus != null) { - buf.append(StringUtils.capitalize(subgenus.toLowerCase())); - buf.append(CLASSIFICATION_DELIMITER); - } - } - } - } - } - } - } - - if (buf.length() > CLASSIFICATION_DELIMITER.length()) { - buf.delete(buf.length() - CLASSIFICATION_DELIMITER.length(), buf.length()); - } - return buf.toString(); - } - - public String getFullScientificName() { - if (scientificNameAuthorship != null && scientificName != null) { - String normedSciName = NORM_AUTHORS.matcher(scientificName.toLowerCase()).replaceAll(" "); - String normedAuthors = NORM_AUTHORS.matcher(scientificNameAuthorship.toLowerCase()).replaceAll(" "); - if (!normedSciName.contains(normedAuthors)) { - return scientificName + " " + scientificNameAuthorship; - } - } - if (scientificName == null) { - String sciname = null; - if (this.genus != null) { - if (specificEpithet != null) { - sciname = genus + " " + specificEpithet; - if (infraspecificEpithet != null) { - sciname += " " + infraspecificEpithet; - } - // potentially add authorship in this case - if (sciname != null && scientificNameAuthorship != null) { - sciname += " " + scientificNameAuthorship; - } - } else { - sciname = subgenus != null ? subgenus : genus; - } - } - return sciname; - } - return scientificName; - } - - public String getLowestScientificName() { - String sciname = getFullScientificName(); - if (sciname == null) { - if (family != null) { - sciname = family; - } else if (order != null) { - sciname = order; - } else if (classs != null) { - sciname = classs; - } else if (phylum != null) { - sciname = phylum; - } else if (kingdom != null) { - sciname = kingdom; - } - } - return sciname; - } - - /** - * Gets a dwc property by its concept term. - * This method is only able to access official Darwin Core or Dublin Core terms, not any custom extensions. - * - * @param prop the concept term to lookup - * - * @return the terms value, null or IllegalArgumentException for unsupported terms - */ - public String getProperty(Term prop) { - String getter = String.format("get%s", getPropertyName(prop)); - try { - Method m = getClass().getMethod(getter); - Object val = m.invoke(this); - return val == null ? null : val.toString(); - - } catch (NoSuchMethodException e) { - throw new IllegalArgumentException("non existing dwc property: " + prop); - - } catch (Exception e) { - // should never happen - throw new RuntimeException(e); - } - } - - private String getPropertyName(Term prop) { - String propName = StringUtils.capitalize(prop.simpleName()); - if (propName.equalsIgnoreCase("Class")) { - propName = "Classs"; - } - return propName; - } - - public String getTaxonRankInterpreted() { - if (scientificName != null || taxonRank != null) { - return taxonRank; - } - if (genus != null && specificEpithet != null && infraspecificEpithet != null) { - if (taxonRank != null) { - return taxonRank; - } - if (verbatimTaxonRank != null) { - return verbatimTaxonRank; - } - return "infraspecies"; - } - if (genus != null && specificEpithet != null) { - return "species"; - } - if (subgenus != null) { - return "subgenus"; - } - if (genus != null) { - return "genus"; - } - if (family != null) { - return "family"; - } - if (order != null) { - return "order"; - } - if (classs != null) { - return "class"; - } - if (phylum != null) { - return "phylum"; - } - if (kingdom != null) { - return "kingdom"; - } - return null; - } - - /** - * The method tries to best assemble the most complete scientific name possible incl the name authorship. - * It first tries to use scientificName and scientificNameAuthorship if existing. - * Otherwise it uses the atomized name parts. Warning: this uses the genus property which might be wrong in case - * of synonym names, see https://code.google.com/p/darwincore/issues/detail?id=151 - * Note also that the assembled name never includes a rank marker. - * - * @return the best guess of the full scientific name with authorship - */ - protected String norm(String x) { - x = StringUtils.trimToNull(x); - if (x != null && (x.equalsIgnoreCase("\\N") || x.equalsIgnoreCase("NULL"))) { - x = null; - } - return x; - } - - public boolean setProperty(Term prop, String value) { - if (prop == null) { - return false; - } - String setterName = null; - try { - setterName = String.format("set%s", getPropertyName(prop)); - Method m = getClass().getMethod(setterName, String.class); - m.invoke(this, value); - } catch (Exception e) { - LOG.warn("Trying to access bad dwc property setter: " + setterName + " for property " + prop); - return false; - } - return true; - } - - @Override - public String toString() { - return new ToStringBuilder(this).append("taxonID", this.taxonID) - .append("scientificName", this.scientificName) - .toString(); - } - - public String getAcceptedNameUsage() { - return acceptedNameUsage; - } - - public String getAcceptedNameUsageID() { - return acceptedNameUsageID; - } - - public String getAccessRights() { - return accessRights; - } - - public String getBasisOfRecord() { - return basisOfRecord; - } - - public String getBibliographicCitation() { - return bibliographicCitation; - } - - public String getClasss() { - return classs; - } - - public String getCollectionCode() { - return collectionCode; - } - - public String getCollectionID() { - return collectionID; - } - - public String getDataGeneralizations() { - return dataGeneralizations; - } - - public String getDatasetID() { - return datasetID; - } - - public String getDatasetName() { - return datasetName; - } - - public String getDynamicProperties() { - return dynamicProperties; - } - - public String getFamily() { - return family; - } - - public String getGenus() { - return genus; - } - - public String getHigherClassification() { - return higherClassification; - } - - public String getInformationWithheld() { - return informationWithheld; - } - - public String getInfraspecificEpithet() { - return infraspecificEpithet; - } - - public String getInstitutionCode() { - return institutionCode; - } - - public String getInstitutionID() { - return institutionID; - } - - public String getKingdom() { - return kingdom; - } - - public String getLanguage() { - return language; - } - - public String getLicense() { - return license; - } - - public String getModified() { - return modified; - } - - public String getNameAccordingTo() { - return nameAccordingTo; - } - - public String getNameAccordingToID() { - return nameAccordingToID; - } - - public String getNamePublishedIn() { - return namePublishedIn; - } - - public String getNamePublishedInID() { - return namePublishedInID; - } - - public String getNamePublishedInYear() { - return namePublishedInYear; - } - - public String getNomenclaturalCode() { - return nomenclaturalCode; - } - - public String getNomenclaturalStatus() { - return nomenclaturalStatus; - } - - public String getOrder() { - return order; - } - - public String getOriginalNameUsage() { - return originalNameUsage; - } - - public String getOriginalNameUsageID() { - return originalNameUsageID; - } - - public String getOwnerInstitutionCode() { - return ownerInstitutionCode; - } - - public String getParentNameUsage() { - return parentNameUsage; - } - - public String getParentNameUsageID() { - return parentNameUsageID; - } - - public String getPhylum() { - return phylum; - } - - public String getReferences() { - return references; - } - - public String getRightsHolder() { - return rightsHolder; - } - - public String getScientificName() { - return scientificName; - } - - public String getScientificNameAuthorship() { - return scientificNameAuthorship; - } - - public String getScientificNameID() { - return scientificNameID; - } - - public String getSpecificEpithet() { - return specificEpithet; - } - - public String getSubgenus() { - return subgenus; - } - - public String getTaxonConceptID() { - return taxonConceptID; - } - - public String getTaxonID() { - return taxonID; - } - - public String getTaxonomicStatus() { - return taxonomicStatus; - } - - public String getTaxonRank() { - return taxonRank; - } - - public String getTaxonRemarks() { - return taxonRemarks; - } - - public String getType() { - return type; - } - - public String getVerbatimTaxonRank() { - return verbatimTaxonRank; - } - - public String getVernacularName() { - return vernacularName; - } - - public void setAcceptedNameUsage(String acceptedNameUsage) { - this.acceptedNameUsage = acceptedNameUsage; - } - - public void setAcceptedNameUsageID(String acceptedNameUsageID) { - this.acceptedNameUsageID = acceptedNameUsageID; - } - - public void setAccessRights(String accessRights) { - this.accessRights = norm(accessRights); - } - - public void setBasisOfRecord(String basisOfRecord) { - this.basisOfRecord = norm(basisOfRecord); - } - - public void setBibliographicCitation(String bibliographicCitation) { - this.bibliographicCitation = bibliographicCitation; - } - - public void setClasss(String classs) { - this.classs = norm(classs); - } - - public void setCollectionCode(String collectionCode) { - this.collectionCode = norm(collectionCode); - } - - public void setCollectionID(String collectionID) { - this.collectionID = norm(collectionID); - } - - public void setDataGeneralizations(String dataGeneralizations) { - this.dataGeneralizations = norm(dataGeneralizations); - } - - public void setDatasetID(String datasetID) { - this.datasetID = norm(datasetID); - } - - public void setDatasetName(String datasetName) { - this.datasetName = datasetName; - } - - public void setDynamicProperties(String dynamicProperties) { - this.dynamicProperties = dynamicProperties; - } - - public void setFamily(String family) { - this.family = norm(family); - } - - public void setGenus(String genus) { - this.genus = norm(genus); - } - - public void setHigherClassification(String higherClassification) { - this.higherClassification = higherClassification; - } - - public void setInformationWithheld(String informationWithheld) { - this.informationWithheld = norm(informationWithheld); - } - - public void setInfraspecificEpithet(String infraspecificEpithet) { - this.infraspecificEpithet = norm(infraspecificEpithet); - } - - public void setInstitutionCode(String institutionCode) { - this.institutionCode = norm(institutionCode); - } - - public void setInstitutionID(String institutionID) { - this.institutionID = institutionID; - } - - public void setKingdom(String kingdom) { - this.kingdom = norm(kingdom); - } - - public void setLanguage(String language) { - this.language = norm(language); - } - - public void setLicense(String license) { - this.license = norm(license); - } - - public void setModified(String modified) { - this.modified = norm(modified); - } - - public void setNameAccordingTo(String nameAccordingTo) { - this.nameAccordingTo = nameAccordingTo; - } - - public void setNameAccordingToID(String nameAccordingToID) { - this.nameAccordingToID = nameAccordingToID; - } - - public void setNamePublishedIn(String namePublishedIn) { - this.namePublishedIn = norm(namePublishedIn); - } - - public void setNamePublishedInID(String namePublishedInID) { - this.namePublishedInID = namePublishedInID; - } - - public void setNamePublishedInYear(String namePublishedInYear) { - this.namePublishedInYear = namePublishedInYear; - } - - public void setNomenclaturalCode(String nomenclaturalCode) { - this.nomenclaturalCode = norm(nomenclaturalCode); - } - - public void setNomenclaturalStatus(String nomenclaturalStatus) { - this.nomenclaturalStatus = norm(nomenclaturalStatus); - } - - public void setOrder(String order) { - this.order = norm(order); - } - - public void setOriginalNameUsage(String originalNameUsage) { - this.originalNameUsage = originalNameUsage; - } - - public void setOriginalNameUsageID(String originalNameUsageID) { - this.originalNameUsageID = originalNameUsageID; - } - - public void setOwnerInstitutionCode(String ownerInstitutionCode) { - this.ownerInstitutionCode = ownerInstitutionCode; - } - - public void setParentNameUsage(String parentNameUsage) { - this.parentNameUsage = parentNameUsage; - } - - public void setParentNameUsageID(String parentNameUsageID) { - this.parentNameUsageID = parentNameUsageID; - } - - public void setPhylum(String phylum) { - this.phylum = norm(phylum); - } - - public void setReferences(String references) { - this.references = norm(references); - } - - public void setRightsHolder(String rightsHolder) { - this.rightsHolder = norm(rightsHolder); - } - - public void setScientificName(String scientificName) { - this.scientificName = norm(scientificName); - } - - public void setScientificNameAuthorship(String scientificNameAuthorship) { - this.scientificNameAuthorship = norm(scientificNameAuthorship); - } - - public void setScientificNameID(String scientificNameID) { - this.scientificNameID = scientificNameID; - } - - public void setSpecificEpithet(String specificEpithet) { - this.specificEpithet = norm(specificEpithet); - } - - public void setSubgenus(String subgenus) { - this.subgenus = norm(subgenus); - } - - public void setTaxonConceptID(String taxonConceptID) { - this.taxonConceptID = taxonConceptID; - } - - public void setTaxonID(String taxonID) { - this.taxonID = norm(taxonID); - } - - public void setTaxonomicStatus(String taxonomicStatus) { - this.taxonomicStatus = norm(taxonomicStatus); - } - - public void setTaxonRank(String taxonRank) { - this.taxonRank = norm(taxonRank); - } - - public void setTaxonRemarks(String taxonRemarks) { - this.taxonRemarks = norm(taxonRemarks); - } - - public void setType(String type) { - this.type = type; - } - - public void setVerbatimTaxonRank(String verbatimTaxonRank) { - this.verbatimTaxonRank = verbatimTaxonRank; - } - - public void setVernacularName(String vernacularName) { - this.vernacularName = vernacularName; - } - - @Override - public int hashCode() { - return Objects - .hashCode(type, modified, language, license, rightsHolder, accessRights, bibliographicCitation, references, - institutionID, collectionID, datasetID, institutionCode, collectionCode, datasetName, ownerInstitutionCode, - basisOfRecord, informationWithheld, dataGeneralizations, dynamicProperties, taxonID, scientificNameID, - acceptedNameUsageID, parentNameUsageID, originalNameUsageID, nameAccordingToID, namePublishedInID, - taxonConceptID, scientificName, acceptedNameUsage, parentNameUsage, originalNameUsage, nameAccordingTo, - namePublishedIn, namePublishedInYear, higherClassification, kingdom, phylum, classs, order, family, genus, - subgenus, specificEpithet, infraspecificEpithet, taxonRank, verbatimTaxonRank, scientificNameAuthorship, - vernacularName, nomenclaturalCode, taxonomicStatus, nomenclaturalStatus, taxonRemarks); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - final DarwinCoreTaxon other = (DarwinCoreTaxon) obj; - return Objects.equal(this.type, other.type) && Objects.equal(this.modified, other.modified) && Objects - .equal(this.language, other.language) && Objects.equal(this.license, other.license) && Objects - .equal(this.rightsHolder, other.rightsHolder) && Objects.equal(this.accessRights, other.accessRights) - && Objects.equal(this.bibliographicCitation, other.bibliographicCitation) && Objects - .equal(this.references, other.references) && Objects.equal(this.institutionID, other.institutionID) && Objects - .equal(this.collectionID, other.collectionID) && Objects.equal(this.datasetID, other.datasetID) && Objects - .equal(this.institutionCode, other.institutionCode) && Objects - .equal(this.collectionCode, other.collectionCode) && Objects.equal(this.datasetName, other.datasetName) - && Objects.equal(this.ownerInstitutionCode, other.ownerInstitutionCode) && Objects - .equal(this.basisOfRecord, other.basisOfRecord) && Objects - .equal(this.informationWithheld, other.informationWithheld) && Objects - .equal(this.dataGeneralizations, other.dataGeneralizations) && Objects - .equal(this.dynamicProperties, other.dynamicProperties) && Objects.equal(this.taxonID, other.taxonID) - && Objects.equal(this.scientificNameID, other.scientificNameID) && Objects - .equal(this.acceptedNameUsageID, other.acceptedNameUsageID) && Objects - .equal(this.parentNameUsageID, other.parentNameUsageID) && Objects - .equal(this.originalNameUsageID, other.originalNameUsageID) && Objects - .equal(this.nameAccordingToID, other.nameAccordingToID) && Objects - .equal(this.namePublishedInID, other.namePublishedInID) && Objects - .equal(this.taxonConceptID, other.taxonConceptID) && Objects - .equal(this.scientificName, other.scientificName) && Objects - .equal(this.acceptedNameUsage, other.acceptedNameUsage) && Objects - .equal(this.parentNameUsage, other.parentNameUsage) && Objects - .equal(this.originalNameUsage, other.originalNameUsage) && Objects - .equal(this.nameAccordingTo, other.nameAccordingTo) && Objects - .equal(this.namePublishedIn, other.namePublishedIn) && Objects - .equal(this.namePublishedInYear, other.namePublishedInYear) && Objects - .equal(this.higherClassification, other.higherClassification) && Objects.equal(this.kingdom, other.kingdom) - && Objects.equal(this.phylum, other.phylum) && Objects.equal(this.classs, other.classs) && Objects - .equal(this.order, other.order) && Objects.equal(this.family, other.family) && Objects - .equal(this.genus, other.genus) && Objects.equal(this.subgenus, other.subgenus) && Objects - .equal(this.specificEpithet, other.specificEpithet) && Objects - .equal(this.infraspecificEpithet, other.infraspecificEpithet) && Objects - .equal(this.taxonRank, other.taxonRank) && Objects.equal(this.verbatimTaxonRank, other.verbatimTaxonRank) - && Objects.equal(this.scientificNameAuthorship, other.scientificNameAuthorship) && Objects - .equal(this.vernacularName, other.vernacularName) && Objects - .equal(this.nomenclaturalCode, other.nomenclaturalCode) && Objects - .equal(this.taxonomicStatus, other.taxonomicStatus) && Objects - .equal(this.nomenclaturalStatus, other.nomenclaturalStatus) && Objects - .equal(this.taxonRemarks, other.taxonRemarks); - } -} diff --git a/src/test/java/org/gbif/dwca/io/ArchiveTest.java b/src/test/java/org/gbif/dwca/io/ArchiveTest.java index e3f439326..e9a5d8087 100644 --- a/src/test/java/org/gbif/dwca/io/ArchiveTest.java +++ b/src/test/java/org/gbif/dwca/io/ArchiveTest.java @@ -1,54 +1,27 @@ package org.gbif.dwca.io; -import org.gbif.dwc.terms.DcTerm; +import org.gbif.dwc.DwcFiles; import org.gbif.dwc.terms.DwcTerm; import org.gbif.dwc.terms.Term; -import org.gbif.dwca.record.DarwinCoreRecord; +import org.gbif.dwca.record.StarRecord; import org.gbif.utils.file.FileUtils; -import org.gbif.utils.file.csv.CSVReader; import org.junit.Test; -import org.mockito.Matchers; import java.io.File; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class ArchiveTest { @Test public void testIteratorDwc() throws Exception { - File csv = FileUtils.getClasspathFile("null_data.txt"); - CSVReader reader = new CSVReader(csv, "utf8", "\t", null, 1); + Archive arch = DwcFiles.fromLocation(FileUtils.getClasspathFile("simplest-archive").toPath()); - Archive arch = new Archive(); - ArchiveField id = new ArchiveField(0, null, null, null); - ArchiveField taxStatus = new ArchiveField(1, DwcTerm.taxonomicStatus, "a", null); - ArchiveField dcmodified = new ArchiveField(6, DcTerm.modified, "mod", null); - - ArchiveFile core = mock(ArchiveFile.class); - when(core.getCSVReader()).thenReturn(reader); - when(core.getId()).thenReturn(id); - when(core.getArchive()).thenReturn(arch); - when(core.getField(Matchers.any())).thenReturn(taxStatus); - Map fields = new HashMap(); - fields.put(DwcTerm.taxonomicStatus, taxStatus); - fields.put(DcTerm.modified, dcmodified); - when(core.getFields()).thenReturn(fields); - when(core.hasTerm(eq(DwcTerm.taxonomicStatus))).thenReturn(true); - when(core.hasTerm(eq(DcTerm.modified))).thenReturn(true); - arch.setCore(core); - - Iterator iter = arch.iteratorDwc(); - while (iter.hasNext()) { - DarwinCoreRecord rec = iter.next(); - assertEquals("a", rec.getTaxonomicStatus()); - assertEquals("mod", rec.getModified()); + for (StarRecord rec : arch) { + assertEquals("Quercus alba", rec.core().value(DwcTerm.scientificName)); + assertEquals("Species", rec.core().value(DwcTerm.taxonRank)); } } diff --git a/src/test/java/org/gbif/dwca/io/ScanArchiveForScientificName.java b/src/test/java/org/gbif/dwca/io/ScanArchiveForScientificName.java index b8f07ce8d..cbfbb095e 100644 --- a/src/test/java/org/gbif/dwca/io/ScanArchiveForScientificName.java +++ b/src/test/java/org/gbif/dwca/io/ScanArchiveForScientificName.java @@ -1,36 +1,29 @@ package org.gbif.dwca.io; +import org.gbif.dwc.DwcFiles; import org.gbif.dwc.terms.DwcTerm; -import org.gbif.dwca.io.Archive; -import org.gbif.dwca.io.ArchiveFactory; -import org.gbif.dwca.io.UnsupportedArchiveException; -import org.gbif.dwca.record.DarwinCoreRecord; +import org.gbif.dwca.record.StarRecord; +import org.gbif.utils.file.FileUtils; -import java.io.File; import java.io.IOException; -import java.util.Iterator; public class ScanArchiveForScientificName { public static void main(String[] args) throws IOException, UnsupportedArchiveException { - // opens csv files with headers or dwc-a direcotries with a meta.xml descriptor - Archive arch = ArchiveFactory - .openArchive(new File("/Volumes/Scratch/ecat-data-col/checklists/beac2c55-d889-4358-a414-b1db79ba3536/dwc-a")); + // opens CSV files with headers or dwc-a directories with a meta.xml descriptor + Archive arch = DwcFiles.fromLocation(FileUtils.getClasspathFile("archive-dwc").toPath()); // does scientific name exist? if (!arch.getCore().hasTerm(DwcTerm.scientificName)) { - System.out.println("This application requires dwc-a with scientific names"); + System.out.println("This application requires a DWC-A with scientific names"); System.exit(1); } - // loop over core darwin core records - Iterator iter = arch.iteratorDwc(); - DarwinCoreRecord dwc; - while (iter.hasNext()) { - dwc = iter.next(); - if (dwc.getScientificName().startsWith("Ambispora callosa")) { - System.out.println(dwc.getScientificName()); - System.out.println(dwc.getScientificNameAuthorship()); + // loop over core Darwin Core records + for (StarRecord dwc : arch) { + if (dwc.core().value(DwcTerm.scientificName).startsWith("Ambispora callosa")) { + System.out.println(dwc.core().value(DwcTerm.scientificName)); + System.out.println(dwc.core().value(DwcTerm.scientificNameAuthorship)); System.out.println(dwc); } } diff --git a/src/test/java/org/gbif/dwca/record/DarwinCoreRecordTest.java b/src/test/java/org/gbif/dwca/record/DarwinCoreRecordTest.java deleted file mode 100644 index 3bd9ae968..000000000 --- a/src/test/java/org/gbif/dwca/record/DarwinCoreRecordTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.gbif.dwca.record; - -import org.gbif.dwc.terms.DwcTerm; -import org.gbif.dwca.io.ArchiveField; -import org.gbif.dwca.record.DarwinCoreRecord; -import org.gbif.dwca.record.RecordImpl; - -import java.util.Date; -import java.util.HashSet; -import java.util.Set; - -import com.google.common.collect.ImmutableSet; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -public class DarwinCoreRecordTest { - - @Test - public void testProperties() { - final Set IGNORE = ImmutableSet.of(DwcTerm.GROUP_MEASUREMENTORFACT, DwcTerm.GROUP_RESOURCERELATIONSHIP); - - DarwinCoreRecord dwc = new DarwinCoreRecord(); - for (DwcTerm t : DwcTerm.values()) { - // only test non class terms - if (t.isClass()) { - continue; - } - - if (IGNORE.contains(t.getGroup())) { - try { - dwc.getProperty(t); - fail("term " + t.qualifiedName() + " should not exist on DarwinCoreRecord"); - } catch (IllegalArgumentException e) { - // expected - } - - } else { - String val = new Date().toString(); - dwc.setProperty(t, val); - assertEquals("missing term " + t.qualifiedName(), val, dwc.getProperty(t)); - } - } - } - - @Test - public void testDefaultValue() { - final String DATASET = "ITIS"; - ArchiveField id = new ArchiveField(0, DwcTerm.taxonID, null, null); - Set fields = new HashSet(); - fields.add(new ArchiveField(1, DwcTerm.datasetName, DATASET, null)); - RecordImpl rec = new RecordImpl(id, fields, DwcTerm.Taxon, true, true); - - String[] row = {"5432", "IPNI"}; - rec.setRow(row); - assertEquals(row[1], rec.value(DwcTerm.datasetName)); - - row = new String[] {"5432", null}; - rec.setRow(row); - assertEquals(DATASET, rec.value(DwcTerm.datasetName)); - - row = new String[] {"5432", ""}; - rec.setRow(row); - assertEquals(DATASET, rec.value(DwcTerm.datasetName)); - } -} diff --git a/src/test/java/org/gbif/dwca/record/DarwinCoreTaxonTest.java b/src/test/java/org/gbif/dwca/record/DarwinCoreTaxonTest.java deleted file mode 100644 index a1a947992..000000000 --- a/src/test/java/org/gbif/dwca/record/DarwinCoreTaxonTest.java +++ /dev/null @@ -1,194 +0,0 @@ -package org.gbif.dwca.record; - -import org.gbif.dwc.terms.DwcTerm; -import org.gbif.dwc.terms.GbifTerm; -import org.gbif.dwca.record.DarwinCoreTaxon; - -import java.util.Date; -import java.util.Set; - -import com.google.common.collect.ImmutableSet; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -public class DarwinCoreTaxonTest { - - @Test - public void testGetFullScientificName() { - DarwinCoreTaxon dwc = new DarwinCoreTaxon("Festuca x brinkmannii A. Braun"); - dwc.setScientificNameAuthorship("A. Braun"); - assertEquals("Festuca x brinkmannii A. Braun", dwc.getFullScientificName()); - assertEquals(dwc.getFullScientificName(), dwc.getLowestScientificName()); - - dwc = new DarwinCoreTaxon("Festuca x brinkmannii A. Braun"); - dwc.setScientificNameAuthorship("A.Braun"); - assertEquals("Festuca x brinkmannii A. Braun", dwc.getFullScientificName()); - assertEquals(dwc.getFullScientificName(), dwc.getLowestScientificName()); - - dwc = new DarwinCoreTaxon("Festuca x brinkmannii"); - dwc.setScientificNameAuthorship("A. Braun"); - assertEquals("Festuca x brinkmannii A. Braun", dwc.getFullScientificName()); - assertEquals(dwc.getFullScientificName(), dwc.getLowestScientificName()); - - dwc = new DarwinCoreTaxon("Festuca A. Braun brinkmannii subsp. brinkmannii"); - dwc.setScientificNameAuthorship("A. Braun"); - assertEquals("Festuca A. Braun brinkmannii subsp. brinkmannii", dwc.getFullScientificName()); - assertEquals(dwc.getFullScientificName(), dwc.getLowestScientificName()); - - dwc = new DarwinCoreTaxon("Festuca brinkmannii"); - dwc.setScientificNameAuthorship("A. Braun"); - assertEquals("Festuca brinkmannii A. Braun", dwc.getFullScientificName()); - assertEquals(dwc.getFullScientificName(), dwc.getLowestScientificName()); - - dwc = new DarwinCoreTaxon(" "); - dwc.setScientificNameAuthorship("Rafinesque, 1795"); - dwc.setKingdom("Plantae"); - assertNull(dwc.getFullScientificName()); - assertEquals("Plantae", dwc.getLowestScientificName()); - - dwc = new DarwinCoreTaxon(" "); - dwc.setScientificNameAuthorship("L."); - dwc.setKingdom("Plantae"); - dwc.setFamily("Asteraceae"); - assertNull(dwc.getFullScientificName()); - assertEquals("Asteraceae", dwc.getLowestScientificName()); - - dwc = new DarwinCoreTaxon(); - dwc.setScientificNameAuthorship("L."); - dwc.setKingdom("Plantae"); - dwc.setGenus("Poa"); - assertEquals("Poa", dwc.getFullScientificName()); - assertEquals(dwc.getFullScientificName(), dwc.getLowestScientificName()); - - dwc.setSpecificEpithet("annua"); - assertEquals("Poa annua L.", dwc.getFullScientificName()); - assertEquals(dwc.getFullScientificName(), dwc.getLowestScientificName()); - - dwc.setScientificNameAuthorship(""); - assertEquals("Poa annua", dwc.getFullScientificName()); - assertEquals(dwc.getFullScientificName(), dwc.getLowestScientificName()); - - dwc.setScientificNameAuthorship("L."); - dwc.setInfraspecificEpithet("alpina"); - assertEquals("Poa annua alpina L.", dwc.getFullScientificName()); - assertEquals(dwc.getFullScientificName(), dwc.getLowestScientificName()); - - dwc.setVerbatimTaxonRank("var."); - assertEquals("Poa annua alpina L.", dwc.getFullScientificName()); - assertEquals(dwc.getFullScientificName(), dwc.getLowestScientificName()); - - // test not identical authorships - dwc = new DarwinCoreTaxon(); - dwc.setScientificName("Aagaardia protensa Saether, 2000"); - dwc.setGenus("Aagaardia"); - dwc.setSpecificEpithet("protensa"); - dwc.setScientificNameAuthorship("Saether 2000"); - assertEquals(dwc.getScientificName(), dwc.getFullScientificName()); - - // test genus - dwc = new DarwinCoreTaxon(); - dwc.setScientificName("Aagaardia protensa Saether, 2000"); - dwc.setGenus("Aagaardia"); - dwc.setSpecificEpithet("protensa"); - dwc.setScientificNameAuthorship("Saether 2000"); - assertEquals(dwc.getScientificName(), dwc.getFullScientificName()); - - // test authors with single letter that is part of the name - dwc = new DarwinCoreTaxon(); - dwc.setScientificName("Trifolium repens"); - dwc.setGenus("Trifolium"); - dwc.setSpecificEpithet("repens"); - dwc.setScientificNameAuthorship("L."); - assertEquals("Trifolium repens", dwc.getScientificName()); - assertEquals("Trifolium repens L.", dwc.getFullScientificName()); - - dwc = new DarwinCoreTaxon(); - dwc.setScientificName("Trifolium thalii"); - dwc.setScientificNameAuthorship("Vill."); - assertEquals("Trifolium thalii Vill.", dwc.getFullScientificName()); - - dwc = new DarwinCoreTaxon(); - dwc.setScientificName("Trifolium alpestre"); - dwc.setScientificNameAuthorship("L."); - assertEquals("Trifolium alpestre L.", dwc.getFullScientificName()); - - // autonyms ??? - dwc = new DarwinCoreTaxon(); - dwc.setScientificName("Trifolium alpestre alpestre"); - dwc.setScientificNameAuthorship("L."); - // this would be really correct for autonyms... - //assertEquals("Trifolium alpestre L. alpestre", dwc.getFullScientificName()); - assertEquals("Trifolium alpestre alpestre L.", dwc.getFullScientificName()); - } - - @Test - public void testInterpretedRank() { - DarwinCoreTaxon dwc = new DarwinCoreTaxon("Festuca brinkmannii A. Braun"); - dwc.setKingdom("PLANTAE"); - dwc.setPhylum("Magnoliophyta"); - dwc.setFamily("Poaceae"); - dwc.setGenus("Festuca"); - dwc.setTaxonRank("species"); - assertEquals("species", dwc.getTaxonRankInterpreted()); - - dwc.setSpecificEpithet("brinkmannii"); - assertEquals("species", dwc.getTaxonRankInterpreted()); - - dwc.setInfraspecificEpithet("nonexistii"); - assertEquals("species", dwc.getTaxonRankInterpreted()); - - dwc.setScientificName(null); - assertEquals("species", dwc.getTaxonRankInterpreted()); - - dwc.setTaxonRank(null); - assertEquals("infraspecies", dwc.getTaxonRankInterpreted()); - - dwc.setVerbatimTaxonRank("var."); - assertEquals("var.", dwc.getTaxonRankInterpreted()); - - dwc.setSpecificEpithet(null); - assertEquals("genus", dwc.getTaxonRankInterpreted()); - - dwc.setGenus(null); - assertEquals("family", dwc.getTaxonRankInterpreted()); - } - - @Test - public void testHigherClassification() { - DarwinCoreTaxon dwc = new DarwinCoreTaxon("Festuca brinkmannii A. Braun"); - dwc.setKingdom("PLANTAE"); - dwc.setPhylum("Magnoliophyta"); - dwc.setFamily("Poaceae"); - dwc.setGenus("Festuca"); - assertEquals("Plantae | Magnoliophyta | Poaceae | Festuca", dwc.buildHigherClassification(null)); - assertEquals("Plantae | Magnoliophyta | Poaceae", dwc.buildHigherClassification('f')); - assertEquals("Plantae | Magnoliophyta", dwc.buildHigherClassification('o')); - } - - @Test - public void testProperties() { - Set groups = ImmutableSet.of(DwcTerm.GROUP_TAXON, DwcTerm.GROUP_RECORD); - DarwinCoreTaxon dwc = new DarwinCoreTaxon(); - for (DwcTerm t : DwcTerm.values()) { - if (groups.contains(t.getGroup()) && !t.isClass()){ - String val = new Date().toString(); - dwc.setProperty(t, val); - try { - dwc.getProperty(t); - assertEquals(val, dwc.getProperty(t)); - } catch (Exception e) { - System.err.println(e.getMessage()); - } - } - } - } - - @Test(expected = IllegalArgumentException.class) - public void testInvalidProperties() { - DarwinCoreTaxon dwc = new DarwinCoreTaxon(); - dwc.getProperty(GbifTerm.canonicalName); - } -} diff --git a/src/test/resources/simplest-archive/meta.xml b/src/test/resources/simplest-archive/meta.xml new file mode 100644 index 000000000..73f710221 --- /dev/null +++ b/src/test/resources/simplest-archive/meta.xml @@ -0,0 +1,11 @@ + + + + + taxa.txt + + + + + + diff --git a/src/test/resources/simplest-archive/taxa.txt b/src/test/resources/simplest-archive/taxa.txt new file mode 100644 index 000000000..336195693 --- /dev/null +++ b/src/test/resources/simplest-archive/taxa.txt @@ -0,0 +1,3 @@ +TaxonID ScientificName TaxonRank +1 Quercus alba Species +2 Quercus alba Species