Skip to content

Commit

Permalink
Optionally adds species URL to download #945
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed May 15, 2024
1 parent bb8c9b6 commit 383462a
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
3 changes: 3 additions & 0 deletions grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ app {
if (!ala.baseURL) {
ala.baseURL = "https://www.ala.org.au"
}
bie.ws.url = "https://www.bie.ala.org.au/ws"
bie.url = "https://www.bie.ala.org.au"

if (!collectory.baseURL) {
//collectory.baseURL = "https://collectory-dev.ala.org.au/"
collectory.baseURL = "https://collections-test.ala.org.au/"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package au.org.ala.ecodata.metadata

import pl.touk.excel.export.getters.Getter

class SpeciesUrlGetter extends OutputDataGetter implements Getter<String> {
String biePrefix
SpeciesUrlGetter(String propertyName, Map dataNode, Map<String, Object> documentMap, TimeZone timeZone, String biePrefix) {
super(propertyName, dataNode, documentMap, timeZone)
this.biePrefix = biePrefix
}

@Override
def species(Object node, Value outputValue) {
def val = outputValue.value
if (!val?.name) {
return ""
}

return val?.guid ? biePrefix+val.guid : "Unmatched name"
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class ProjectXlsExporter extends ProjectExporter {
super(exporter)
this.projectService = projectService
distinctElectorates = new ArrayList()
useSpeciesUrlGetter = true
setupManagementUnits(managementUnitService)
setupFundingAbn(organisationService)
setupProgramData(programService)
Expand All @@ -185,6 +186,7 @@ class ProjectXlsExporter extends ProjectExporter {
super(exporter, tabsToExport, [:], TimeZone.default)
this.projectService = projectService
this.formSectionPerTab = formSectionPerTab
useSpeciesUrlGetter = true
addDataDescriptionToDownload(downloadMetadata)
distinctElectorates = new ArrayList(electorates?:[])
distinctElectorates.sort()
Expand Down
19 changes: 19 additions & 0 deletions src/main/groovy/au/org/ala/ecodata/reporting/TabbedExporter.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import au.org.ala.ecodata.metadata.OutputDateGetter
import au.org.ala.ecodata.metadata.OutputMetadata
import au.org.ala.ecodata.metadata.OutputModelProcessor
import au.org.ala.ecodata.metadata.OutputNumberGetter
import au.org.ala.ecodata.metadata.SpeciesUrlGetter
import grails.util.Holders
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
Expand All @@ -26,6 +27,7 @@ class TabbedExporter {
ReportingService reportingService = Holders.grailsApplication.mainContext.getBean("reportingService")
ActivityFormService activityFormService = Holders.grailsApplication.mainContext.getBean("activityFormService")
OutputModelProcessor processor = new OutputModelProcessor()
String biePrefix = Holders.grailsApplication.config.getProperty("bie.url")+'/species/'

static String DATE_CELL_FORMAT = "dd/MM/yyyy"
Map<String, AdditionalSheet> sheets
Expand All @@ -35,6 +37,7 @@ class TabbedExporter {
TimeZone timeZone
Boolean useDateGetter = false
Boolean useNumberGetter = false
boolean useSpeciesUrlGetter = false
// These fields map full activity names to shortened names that are compatible with Excel tabs.
protected Map<String, String> activitySheetNames = [:]
protected Map<String, List<AdditionalSheet>> typedActivitySheets = [:]
Expand Down Expand Up @@ -232,6 +235,22 @@ class TabbedExporter {
getter:new OutputNumberGetter(propertyPath, dataNode, documentMap, timeZone)]
fieldConfiguration << field
}
else if ((dataNode.dataType == 'species') && useSpeciesUrlGetter) {
// Return a property for the species name and a property for the species URL
Map nameField = field + [
header:outputMetadata.getLabel(viewNode, dataNode),
property:propertyPath,
getter:new OutputDataGetter(propertyPath, dataNode, documentMap, timeZone)]
fieldConfiguration << nameField

Map urlField = field + [
description: "Link to species in the ALA",
header:outputMetadata.getLabel(viewNode, dataNode),
property:propertyPath,
getter:new SpeciesUrlGetter(propertyPath, dataNode, documentMap, timeZone, biePrefix)
]
fieldConfiguration << urlField
}
else {
field += [
header:outputMetadata.getLabel(viewNode, dataNode),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package au.org.ala.ecodata.reporting

import au.org.ala.ecodata.*
import au.org.ala.ecodata.metadata.OutputDataGetter
import au.org.ala.ecodata.metadata.SpeciesUrlGetter
import grails.testing.gorm.DomainUnitTest
import grails.testing.web.GrailsWebUnitTest
import grails.util.Holders
Expand Down Expand Up @@ -97,6 +99,49 @@ class TabbedExporterSpec extends Specification implements GrailsWebUnitTest, Dom

}

def "Species data types will be expanded into two export columns if useSpeciesUrlGetter is true"() {
setup:
String type = 'form'
ActivityForm form = buildMockForm(type, buildFormTemplateWithSpecies())

when:
tabbedExporter.useSpeciesUrlGetter = true
List config = tabbedExporter.getActivityExportConfig(type, true)

then:
1 * activityFormService.findVersionedActivityForm(type) >> [form]

config.size() == 3
config[1].header == 'Species label'
config[1].property == 'form.species'
config[1].getter instanceof OutputDataGetter

config[2].header == 'Species label'
config[2].property == 'form.species'
config[2].getter instanceof SpeciesUrlGetter

}

def "Species data types will only export the species name if useSpeciesUrlGetter is false"() {
setup:
String type = 'form'
ActivityForm form = buildMockForm(type, buildFormTemplateWithSpecies())

when:
tabbedExporter.useSpeciesUrlGetter = false
List config = tabbedExporter.getActivityExportConfig(type, true)

then:
1 * activityFormService.findVersionedActivityForm(type) >> [form]

config.size() == 2
config[1].header == 'Species label'
config[1].property == 'form.species'
config[1].getter instanceof OutputDataGetter
}



private ActivityForm buildMockForm(String name, Map template) {
ActivityForm form = new ActivityForm(name:name, formVersion:1)
FormSection section = new FormSection(name:name, template:template)
Expand Down Expand Up @@ -142,4 +187,25 @@ class TabbedExporterSpec extends Specification implements GrailsWebUnitTest, Dom
]
]
}

private Map buildFormTemplateWithSpecies() {
[
dataModel:[
[
name:"species",
dataType:"species"
]
],
viewModel:[
[type:'row', items:[
[
type:'speciesSelect',
source:'species',
preLabel:'Species label'
]
]]

]
]
}
}

0 comments on commit 383462a

Please sign in to comment.