Skip to content

Commit 0b9aeed

Browse files
authored
Merge pull request #946 from AtlasOfLivingAustralia/feature/issue945
Optionally adds species URL to download #945
2 parents bb8c9b6 + 1d63d99 commit 0b9aeed

File tree

8 files changed

+120
-2
lines changed

8 files changed

+120
-2
lines changed

grails-app/conf/application.groovy

+3
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ app {
501501
if (!ala.baseURL) {
502502
ala.baseURL = "https://www.ala.org.au"
503503
}
504+
bie.ws.url = "https://bie-ws.ala.org.au/"
505+
bie.url = "https://bie.ala.org.au/"
506+
504507
if (!collectory.baseURL) {
505508
//collectory.baseURL = "https://collectory-dev.ala.org.au/"
506509
collectory.baseURL = "https://collections-test.ala.org.au/"

grails-app/domain/au/org/ala/ecodata/Record.groovy

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import org.bson.types.ObjectId
66

77
class Record {
88
// def grailsApplication
9+
/** Represents a species guid that was unable to be matched against the ALA names list */
10+
static final String UNMATCHED_GUID = "A_GUID"
911

1012
static mapping = {
1113
occurrenceID index: true

grails-app/services/au/org/ala/ecodata/ParatooService.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -2052,7 +2052,7 @@ class ParatooService {
20522052
}
20532053

20542054
// record is only created if guid is present
2055-
result.guid = result.guid ?: "A_GUID"
2055+
result.guid = result.guid ?: Record.UNMATCHED_GUID
20562056
result
20572057
}
20582058
}

grails-app/services/au/org/ala/ecodata/SpeciesReMatchService.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class SpeciesReMatchService {
8585
name = name?.toLowerCase() ?: ""
8686
cacheService.get('bie-search-auto-' + name, {
8787
def encodedQuery = URLEncoder.encode(name ?: '', "UTF-8")
88-
def url = "${grailsApplication.config.getProperty('bie.url')}ws/search/auto.jsonp?q=${encodedQuery}&limit=${limit}&idxType=TAXON"
88+
def url = "${grailsApplication.config.getProperty('bie.ws.url')}ws/search/auto.jsonp?q=${encodedQuery}&limit=${limit}&idxType=TAXON"
8989

9090
webService.getJson(url)
9191
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package au.org.ala.ecodata.metadata
2+
3+
import pl.touk.excel.export.getters.Getter
4+
import au.org.ala.ecodata.Record
5+
6+
class SpeciesUrlGetter extends OutputDataGetter implements Getter<String> {
7+
String biePrefix
8+
SpeciesUrlGetter(String propertyName, Map dataNode, Map<String, Object> documentMap, TimeZone timeZone, String biePrefix) {
9+
super(propertyName, dataNode, documentMap, timeZone)
10+
this.biePrefix = biePrefix
11+
}
12+
13+
@Override
14+
def species(Object node, Value outputValue) {
15+
def val = outputValue.value
16+
if (!val?.name) {
17+
return ""
18+
}
19+
if (!val?.guid || val.guid == Record.UNMATCHED_GUID) {
20+
return "Unmatched name"
21+
}
22+
return biePrefix+val.guid
23+
}
24+
25+
26+
}

src/main/groovy/au/org/ala/ecodata/reporting/ProjectXlsExporter.groovy

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class ProjectXlsExporter extends ProjectExporter {
176176
super(exporter)
177177
this.projectService = projectService
178178
distinctElectorates = new ArrayList()
179+
useSpeciesUrlGetter = true
179180
setupManagementUnits(managementUnitService)
180181
setupFundingAbn(organisationService)
181182
setupProgramData(programService)
@@ -185,6 +186,7 @@ class ProjectXlsExporter extends ProjectExporter {
185186
super(exporter, tabsToExport, [:], TimeZone.default)
186187
this.projectService = projectService
187188
this.formSectionPerTab = formSectionPerTab
189+
useSpeciesUrlGetter = true
188190
addDataDescriptionToDownload(downloadMetadata)
189191
distinctElectorates = new ArrayList(electorates?:[])
190192
distinctElectorates.sort()

src/main/groovy/au/org/ala/ecodata/reporting/TabbedExporter.groovy

+19
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import au.org.ala.ecodata.metadata.OutputDateGetter
66
import au.org.ala.ecodata.metadata.OutputMetadata
77
import au.org.ala.ecodata.metadata.OutputModelProcessor
88
import au.org.ala.ecodata.metadata.OutputNumberGetter
9+
import au.org.ala.ecodata.metadata.SpeciesUrlGetter
910
import grails.util.Holders
1011
import org.apache.commons.logging.Log
1112
import org.apache.commons.logging.LogFactory
@@ -26,6 +27,7 @@ class TabbedExporter {
2627
ReportingService reportingService = Holders.grailsApplication.mainContext.getBean("reportingService")
2728
ActivityFormService activityFormService = Holders.grailsApplication.mainContext.getBean("activityFormService")
2829
OutputModelProcessor processor = new OutputModelProcessor()
30+
String biePrefix = Holders.grailsApplication.config.getProperty("bie.url")+'species/'
2931

3032
static String DATE_CELL_FORMAT = "dd/MM/yyyy"
3133
Map<String, AdditionalSheet> sheets
@@ -35,6 +37,7 @@ class TabbedExporter {
3537
TimeZone timeZone
3638
Boolean useDateGetter = false
3739
Boolean useNumberGetter = false
40+
boolean useSpeciesUrlGetter = false
3841
// These fields map full activity names to shortened names that are compatible with Excel tabs.
3942
protected Map<String, String> activitySheetNames = [:]
4043
protected Map<String, List<AdditionalSheet>> typedActivitySheets = [:]
@@ -232,6 +235,22 @@ class TabbedExporter {
232235
getter:new OutputNumberGetter(propertyPath, dataNode, documentMap, timeZone)]
233236
fieldConfiguration << field
234237
}
238+
else if ((dataNode.dataType == 'species') && useSpeciesUrlGetter) {
239+
// Return a property for the species name and a property for the species URL
240+
Map nameField = field + [
241+
header:outputMetadata.getLabel(viewNode, dataNode),
242+
property:propertyPath,
243+
getter:new OutputDataGetter(propertyPath, dataNode, documentMap, timeZone)]
244+
fieldConfiguration << nameField
245+
246+
Map urlField = field + [
247+
description: "Link to species in the ALA",
248+
header:outputMetadata.getLabel(viewNode, dataNode),
249+
property:propertyPath,
250+
getter:new SpeciesUrlGetter(propertyPath, dataNode, documentMap, timeZone, biePrefix)
251+
]
252+
fieldConfiguration << urlField
253+
}
235254
else {
236255
field += [
237256
header:outputMetadata.getLabel(viewNode, dataNode),

src/test/groovy/au/org/ala/ecodata/reporting/TabbedExporterSpec.groovy

+66
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package au.org.ala.ecodata.reporting
22

33
import au.org.ala.ecodata.*
4+
import au.org.ala.ecodata.metadata.OutputDataGetter
5+
import au.org.ala.ecodata.metadata.SpeciesUrlGetter
46
import grails.testing.gorm.DomainUnitTest
57
import grails.testing.web.GrailsWebUnitTest
68
import grails.util.Holders
@@ -97,6 +99,49 @@ class TabbedExporterSpec extends Specification implements GrailsWebUnitTest, Dom
9799

98100
}
99101

102+
def "Species data types will be expanded into two export columns if useSpeciesUrlGetter is true"() {
103+
setup:
104+
String type = 'form'
105+
ActivityForm form = buildMockForm(type, buildFormTemplateWithSpecies())
106+
107+
when:
108+
tabbedExporter.useSpeciesUrlGetter = true
109+
List config = tabbedExporter.getActivityExportConfig(type, true)
110+
111+
then:
112+
1 * activityFormService.findVersionedActivityForm(type) >> [form]
113+
114+
config.size() == 3
115+
config[1].header == 'Species label'
116+
config[1].property == 'form.species'
117+
config[1].getter instanceof OutputDataGetter
118+
119+
config[2].header == 'Species label'
120+
config[2].property == 'form.species'
121+
config[2].getter instanceof SpeciesUrlGetter
122+
123+
}
124+
125+
def "Species data types will only export the species name if useSpeciesUrlGetter is false"() {
126+
setup:
127+
String type = 'form'
128+
ActivityForm form = buildMockForm(type, buildFormTemplateWithSpecies())
129+
130+
when:
131+
tabbedExporter.useSpeciesUrlGetter = false
132+
List config = tabbedExporter.getActivityExportConfig(type, true)
133+
134+
then:
135+
1 * activityFormService.findVersionedActivityForm(type) >> [form]
136+
137+
config.size() == 2
138+
config[1].header == 'Species label'
139+
config[1].property == 'form.species'
140+
config[1].getter instanceof OutputDataGetter
141+
}
142+
143+
144+
100145
private ActivityForm buildMockForm(String name, Map template) {
101146
ActivityForm form = new ActivityForm(name:name, formVersion:1)
102147
FormSection section = new FormSection(name:name, template:template)
@@ -142,4 +187,25 @@ class TabbedExporterSpec extends Specification implements GrailsWebUnitTest, Dom
142187
]
143188
]
144189
}
190+
191+
private Map buildFormTemplateWithSpecies() {
192+
[
193+
dataModel:[
194+
[
195+
name:"species",
196+
dataType:"species"
197+
]
198+
],
199+
viewModel:[
200+
[type:'row', items:[
201+
[
202+
type:'speciesSelect',
203+
source:'species',
204+
preLabel:'Species label'
205+
]
206+
]]
207+
208+
]
209+
]
210+
}
145211
}

0 commit comments

Comments
 (0)