Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- updated species search of bulk import
- added species format code
  • Loading branch information
temi committed Sep 4, 2024
1 parent aa2d51f commit d112b94
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 12 deletions.
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 | ''
}
}

0 comments on commit d112b94

Please sign in to comment.