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

AtlasOfLivingAustralia/biocollect#1596 #1006

Merged
merged 1 commit into from
Sep 16, 2024
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
17 changes: 7 additions & 10 deletions grails-app/services/au/org/ala/ecodata/MetadataService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MetadataService {
SpeciesReMatchService speciesReMatchService
HubService hubService
ProjectService projectService
RecordService recordService

/**
* @deprecated use versioned API to retrieve activity form definitions
Expand Down Expand Up @@ -896,17 +897,13 @@ class MetadataService {
data
}

Map autoPopulateSpeciesData (Map data, int limit = 10) {
Map autoPopulateSpeciesData (Map data) {
String searchName = (data?.scientificName)?.trim()
if (!data?.guid && (searchName)) {
def result = speciesReMatchService.searchBie(searchName, limit)
// find the name that exactly matches the search name
def bestMatch = result?.autoCompleteList?.find {
it.matchedNames?.findResult { String name ->
name.equalsIgnoreCase(searchName)
|| name.equalsIgnoreCase(data.name)
|| name.equalsIgnoreCase(data.commonName)
}
Map bestMatch = speciesReMatchService.searchByName(searchName)
if(!bestMatch && data.commonName) {
String commonName = data.commonName
bestMatch = speciesReMatchService.searchByName(commonName, false, true)
}

if (bestMatch) {
Expand All @@ -917,7 +914,7 @@ class MetadataService {
}

if(!data?.name) {
data.name = data?.commonName ? data?.scientificName + '(' + data?.commonName + ')' : data?.scientificName
data.name = recordService.formatTaxonName(data, RecordService.SCIENTIFIC_NAME_COMMON_NAME)
}

data
Expand Down
37 changes: 37 additions & 0 deletions grails-app/services/au/org/ala/ecodata/RecordService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class RecordService {

final def ignores = ["action", "controller", "associatedMedia"]
private static final List<String> EXCLUDED_RECORD_PROPERTIES = ["_id", "activityId", "dateCreated", "json", "outputId", "projectActivityId", "projectId", "status", "dataResourceUid"]
static final String COMMON_NAME = 'COMMONNAME'
static final String SCIENTIFIC_NAME = 'SCIENTIFICNAME'
static final String COMMON_NAME_SCIENTIFIC_NAME = 'COMMONNAME(SCIENTIFICNAME)'
static final String SCIENTIFIC_NAME_COMMON_NAME = 'SCIENTIFICNAME(COMMONNAME)'

def getProjectActivityService() {
grailsApplication.mainContext.projectActivityService
Expand Down Expand Up @@ -1119,4 +1123,37 @@ class RecordService {
commonService.updateProperties(output, props)
}
}

/** format species by specific type **/
String formatTaxonName (Map data, String displayType) {
String name = ''
switch (displayType){
case COMMON_NAME_SCIENTIFIC_NAME:
if (data.commonName && data.scientificName) {
name = "${data.commonName} (${data.scientificName})"
} else if (data.commonName) {
name = data.commonName
} else if (data.scientificName) {
name = data.scientificName
}
break
case SCIENTIFIC_NAME_COMMON_NAME:
if (data.scientificName && data.commonName) {
name = "${data.scientificName} (${data.commonName})"
} else if (data.scientificName) {
name = data.scientificName
} else if (data.commonName) {
name = data.commonName
}
break
case COMMON_NAME:
name = data.commonName ?: data.scientificName ?: ""
break
case SCIENTIFIC_NAME:
name = data.scientificName ?: ""
break
}

name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class SpeciesReMatchService {
}

resp
})
}) as Map
}

Map searchByVernacularNameOnNameMatchingServer (String name) {
Expand All @@ -139,6 +139,6 @@ class SpeciesReMatchService {
}

resp
})
}) as Map
}
}
29 changes: 29 additions & 0 deletions src/test/groovy/au/org/ala/ecodata/RecordServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,34 @@ class RecordServiceSpec extends MongoSpec implements ServiceUnitTest<RecordServi
recordMap.recordNumber == "${prefix}/bioActivity/index/a1"
}

def "formatTaxonName should format name based on displayType"() {
setup:
Map data = [commonName: commonName, scientificName: scientificName]

when:
String result = service.formatTaxonName(data, displayType)

then:
result == expectedName

where:
commonName | scientificName | displayType | expectedName
'Blackbird' | 'Turdus merula' | service.COMMON_NAME_SCIENTIFIC_NAME | 'Blackbird (Turdus merula)'
'Blackbird' | 'Turdus merula' | service.SCIENTIFIC_NAME_COMMON_NAME | 'Turdus merula (Blackbird)'
'Blackbird' | 'Turdus merula' | service.COMMON_NAME | 'Blackbird'
null | 'Turdus merula' | service.COMMON_NAME | 'Turdus merula'
'Blackbird' | 'Turdus merula' | service.SCIENTIFIC_NAME | 'Turdus merula'
null | 'Turdus merula' | service.SCIENTIFIC_NAME | 'Turdus merula'
null | 'Turdus merula' | service.COMMON_NAME_SCIENTIFIC_NAME | 'Turdus merula'
null | 'Turdus merula' | service.SCIENTIFIC_NAME_COMMON_NAME | 'Turdus merula'
'Blackbird' | null | service.COMMON_NAME_SCIENTIFIC_NAME | 'Blackbird'
'Blackbird' | null | service.SCIENTIFIC_NAME_COMMON_NAME | 'Blackbird'
'Blackbird' | null | service.COMMON_NAME | 'Blackbird'
null | null | service.COMMON_NAME | ''
null | null | service.SCIENTIFIC_NAME | ''
null | null | service.COMMON_NAME_SCIENTIFIC_NAME | ''
null | null | service.SCIENTIFIC_NAME_COMMON_NAME | ''
}

}

Loading