diff --git a/grails-app/conf/application.groovy b/grails-app/conf/application.groovy index 3a77d5315..2938f86e0 100644 --- a/grails-app/conf/application.groovy +++ b/grails-app/conf/application.groovy @@ -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/" diff --git a/src/main/groovy/au/org/ala/ecodata/metadata/SpeciesUrlGetter.groovy b/src/main/groovy/au/org/ala/ecodata/metadata/SpeciesUrlGetter.groovy new file mode 100644 index 000000000..296fe17eb --- /dev/null +++ b/src/main/groovy/au/org/ala/ecodata/metadata/SpeciesUrlGetter.groovy @@ -0,0 +1,23 @@ +package au.org.ala.ecodata.metadata + +import pl.touk.excel.export.getters.Getter + +class SpeciesUrlGetter extends OutputDataGetter implements Getter { + String biePrefix + SpeciesUrlGetter(String propertyName, Map dataNode, Map 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" + } + + +} diff --git a/src/main/groovy/au/org/ala/ecodata/reporting/ProjectXlsExporter.groovy b/src/main/groovy/au/org/ala/ecodata/reporting/ProjectXlsExporter.groovy index ff2e8e1cc..7d236ee70 100644 --- a/src/main/groovy/au/org/ala/ecodata/reporting/ProjectXlsExporter.groovy +++ b/src/main/groovy/au/org/ala/ecodata/reporting/ProjectXlsExporter.groovy @@ -176,6 +176,7 @@ class ProjectXlsExporter extends ProjectExporter { super(exporter) this.projectService = projectService distinctElectorates = new ArrayList() + useSpeciesUrlGetter = true setupManagementUnits(managementUnitService) setupFundingAbn(organisationService) setupProgramData(programService) @@ -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() diff --git a/src/main/groovy/au/org/ala/ecodata/reporting/TabbedExporter.groovy b/src/main/groovy/au/org/ala/ecodata/reporting/TabbedExporter.groovy index 4664a347e..17efdc3f9 100644 --- a/src/main/groovy/au/org/ala/ecodata/reporting/TabbedExporter.groovy +++ b/src/main/groovy/au/org/ala/ecodata/reporting/TabbedExporter.groovy @@ -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 @@ -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 sheets @@ -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 activitySheetNames = [:] protected Map> typedActivitySheets = [:] @@ -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), diff --git a/src/test/groovy/au/org/ala/ecodata/reporting/TabbedExporterSpec.groovy b/src/test/groovy/au/org/ala/ecodata/reporting/TabbedExporterSpec.groovy index 81d261aa5..695749d37 100644 --- a/src/test/groovy/au/org/ala/ecodata/reporting/TabbedExporterSpec.groovy +++ b/src/test/groovy/au/org/ala/ecodata/reporting/TabbedExporterSpec.groovy @@ -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 @@ -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) @@ -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' + ] + ]] + + ] + ] + } }