Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more attributes to event and occurrence files #1075

Merged
merged 2 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions grails-app/services/au/org/ala/ecodata/RecordService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1580,9 +1580,32 @@ class RecordService {
}
}

addUnlistedAttributesToResult(record, result)
result
}

Map addUnlistedAttributesToResult(Map record, Map<String, Map> result) {
List ignoreAttributes = ["multimedia", "measurementsOrFacts"]
if (record.occurrenceID) {
copyMissingAttributes(record, result[DWC_OCCURRENCE], ignoreAttributes)
}
else if (record.eventID) {
copyMissingAttributes(record, result[DWC_EVENT], ignoreAttributes)
}

result
}

Map copyMissingAttributes (Map source, Map destination, List ignoreAttributes = []) {
source.each { key, value ->
if (!destination.containsKey(key) && key !in ignoreAttributes) {
destination[key] = value
}
}

destination
}

/**
* Transform a darwin core value before entering into event core.
* @param config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,13 @@ class HarvestControllerSpec extends Specification {
case "Event.csv":
CSVReader readerCSV = new CSVReader(new StringReader(content))
List<String[]> lines = readerCSV.readAll()
assert lines[0] == ["eventID","parentEventID","eventType","eventDate","eventRemarks","samplingProtocol","geodeticDatum", "locationID", "endDate", "dataSharingLicense", "license", "name", "pActivityFormName", "startDate"]
assert lines[1] == ["pa1", "", "Survey", "${yesterdayStr}/${nowStr}", "Test event remarks", "opportunistic", "","" , nowStr, "CC BY 4.0", "", "Test Project Activity", "testForm", yesterdayStr]
List headers = lines[0]
List expectedHeaders = ["eventID","parentEventID","eventType","eventDate","eventRemarks","samplingProtocol","geodeticDatum", "locationID", "endDate", "dataSharingLicense", "license", "name", "pActivityFormName", "startDate"]
List expectedValues = ["pa1", "", "Survey", "${yesterdayStr}/${nowStr}", "Test event remarks", "opportunistic", "","" , nowStr, "CC BY 4.0", "", "Test Project Activity", "testForm", yesterdayStr]
expectedHeaders.eachWithIndex { header, index ->
int csvIndex = headers.findIndexOf { it == header }
assert lines[1][csvIndex] == expectedValues[index]
}
assert lines[2][0] == "activity1"
assert lines[2][1] == "pa1"
assert lines[2][2] == "SiteVisit"
Expand All @@ -228,8 +233,13 @@ class HarvestControllerSpec extends Specification {
// check Occurrence.csv
CSVReader readerCSV = new CSVReader(new StringReader(content))
List<String[]> lines = readerCSV.readAll()
assert lines[0] == ["eventID","occurrenceID","basisOfRecord","scientificName","occurrenceStatus","individualCount"]
assert lines[1] == ["activity1","outputSpecies1","HumanObservation","Anura","present","1"]
List headers = lines[0]
List expectedHeaders = ["eventID","occurrenceID","basisOfRecord","scientificName","occurrenceStatus","individualCount"]
List expectedValues = ["activity1","outputSpecies1","HumanObservation","Anura","present","1"]
expectedHeaders.eachWithIndex { header, index ->
int csvIndex = headers.findIndexOf { it == header }
assert lines[1][csvIndex] == expectedValues[index]
}
assert lines.size() == 2
break
case "MeasurementOrFact.csv":
Expand Down