Skip to content

Commit

Permalink
IPPRS / RCS reporting WIP #3369
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Dec 6, 2024
1 parent 4eb5c56 commit 72f92d1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions grails-app/conf/spring/resources.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import au.org.ala.merit.MeritServletContextConfig
import au.org.ala.merit.StatisticsFactory
import au.org.ala.merit.hub.HubAwareLinkGenerator
import au.org.ala.merit.reports.NHTOutputReportLifecycleListener
import au.org.ala.merit.reports.RegionalCapacityServicesReportLifecycleListener
import au.org.ala.merit.util.ProjectGroupingHelper

// Place your Spring DSL code here
Expand All @@ -23,6 +24,7 @@ beans = {
NHTOutputReport(NHTOutputReportLifecycleListener)
GrantsandOthersProgressReport(NHTOutputReportLifecycleListener)
ProcurementOutputReport(NHTOutputReportLifecycleListener)
RegionalCapacityServicesReport(RegionalCapacityServicesReportLifecycleListener)

meritServletContextConfig(MeritServletContextConfig)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package au.org.ala.merit.command

import au.org.ala.merit.ReportService
import au.org.ala.merit.reports.ReportLifecycleListener
import grails.artefact.Controller
import grails.core.GrailsApplication
import grails.validation.Validateable
Expand Down Expand Up @@ -40,6 +41,9 @@ abstract class EditOrViewReportCommand implements Validateable {
model.saveReportUrl = linkGenerator.link(controller:entityType, action:'saveReport', id:id)
model.documentOwner = [activityId:model.activity?.activityId, reportId:reportId]
model.documentOwner[getEntityIdField()] = id

ReportLifecycleListener listener = reportService.reportLifeCycleListener(model.report)
model.putAll(listener.getContextData(entity, model.report))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package au.org.ala.merit.reports

import au.org.ala.merit.OrganisationService
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired

@Slf4j
class RegionalCapacityServicesReportLifecycleListener extends ReportLifecycleListener {

@Autowired
OrganisationService organisationService

Map getContextData(Map organisation, Map report) {
List outputTargets = organisation.custom?.details?.services?.targets
Map periodTargets = getTargetsForReportPeriod(report, outputTargets)
BigDecimal budget = new BigDecimal(0) // TODO get budget from the correct period of the budget table
[periodTargets:periodTargets, budget:budget]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,18 @@ class ReportLifecycleListener {
result
}

static Map getTargetsForReportPeriod(Map report, List<Map> outputTargets) {
String endDate = report.toDate

outputTargets?.collectEntries { Map outputTarget ->
String scoreId = outputTarget.scoreId
String previousPeriod = ''
Map matchingPeriodTarget = outputTarget?.periodTargets?.find { Map periodTarget ->
previousPeriod < endDate && periodTarget.period >= endDate
}
[(scoreId): matchingPeriodTarget?.target]
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ class ReportLifecycleListenerSpec extends Specification {
[entityType:"au.org.ala.ecodata.DataSetSummary", entityIds:["5b1255a4-3b91-4fae-a243-02bd4d163898"]]]
}

def "getTargetForReportPeriod should return the correct target for the report period"() {
setup:
Map report = [toDate: '2023-12-31']
String scoreId = 'score1'
List<Map> values = [
[scoreId: 'score1', periodTargets: [
[period: '2023-01-01', target: 10],
[period: '2023-12-31', target: 20],
[period: '2024-01-01', target: 30]
]],
[scoreId: 'score2', periodTargets: [
[period: '2023-01-01', target: 5],
[period: '2023-12-31', target: 15]
]]
]

when:
def result = ReportLifecycleListener.getTargetForReportPeriod(report, scoreId, values)

then:
result == [period: '2023-12-31', target: 20]
}

private static Map nhtActivityForm() {
File file = new File('forms/nht/nhtOutputReport.json')

Expand Down

0 comments on commit 72f92d1

Please sign in to comment.