Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't unnecessarily re-query projects for organisation #3016 #3026

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions grails-app/services/au/org/ala/merit/OrganisationService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,11 @@ class OrganisationService {
[type: 'Performance expectations framework - self assessment worksheet', period: Period.years(1), bulkEditable: true, businessDaysToCompleteReport:5, adhoc:true]
]

/** Overrides the parent to add Green Army reports to the results */
def get(String id, view = '') {

String url = "${grailsApplication.config.getProperty('ecodata.baseUrl')}organisation/$id?view=$view"
Map organisation = webService.getJson(url)

def projects = []
def resp = projectService.search(organisationId: id, isMERIT:true, view:'enhanced')
if (resp?.resp?.projects) {
projects += resp.resp.projects
}
resp = projectService.search(orgIdSvcProvider: id, isMERIT:true, view:'enhanced')
if (resp?.resp?.projects) {
projects += resp.resp.projects.findAll{!projects.find{project -> project.projectId == it.projectId} }
}
organisation.projects = projects
if (view != 'flat') {
organisation.reports = getReportsForOrganisation(organisation, getReportConfig(id))
}
Expand Down
59 changes: 1 addition & 58 deletions src/test/groovy/au/org/ala/merit/OrganisationServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,63 +43,6 @@ class OrganisationServiceSpec extends Specification implements ServiceUnitTest<O
1 * activityService.search([type:['t1', 't2'], projectId:['1', '2', '3'], dateProperty:'plannedEndDate', startDate:"2014-01-01T00:00:00+0000", endDate:'2016-02-28T00:00:00+0000'])
}

void "the projects for an organisation should include projects for which the organisation is the service provider"() {
given:
def orgId = '1234'
def organisation = [organisationId:orgId, name:'name', description:'description']
def serviceProviderProjects = ['1', '2', '3', '4'].collect{[projectId:it, name:'p'+it]}
def organisationProjects = ['5', '6', '7', '8', '9'].collect{[projectId:it, name:'p'+it]}
def organisationProjectsWithDuplicates = ['3', '4', '5', '6', '7', '8', '9'].collect{[projectId:it, name:'p'+it]}

webService.getJson(_) >> organisation

when: "the organisation is not a service provider for any projects"
organisation = service.get(orgId)
def projects = organisation.projects

then:
1 * projectService.search([organisationId:orgId, view:'enhanced', isMERIT:true]) >> [resp:[projects:organisationProjects]]
1 * projectService.search([orgIdSvcProvider:orgId, view:'enhanced', isMERIT:true]) >> [resp:[projects:[]]]

projects.size() == organisationProjects.size()
projects == organisationProjects

when: "the organisation is exclusively a service provider"
organisation = service.get(orgId)
projects = organisation.projects


then:
1 * projectService.search([organisationId:orgId, view:'enhanced', isMERIT:true]) >> [resp:[projects:[]]]
1 * projectService.search([orgIdSvcProvider:orgId, view:'enhanced', isMERIT:true]) >> [resp:[projects:serviceProviderProjects]]

projects.size() == serviceProviderProjects.size()
projects == serviceProviderProjects

when:"the organisation is a service provider and runs it's own projects as well"
organisation = service.get(orgId)
projects = organisation.projects

then: "both sets of projects should be returned"
1 * projectService.search([organisationId:orgId, view:'enhanced', isMERIT:true]) >> [resp:[projects:organisationProjects]]
1 * projectService.search([orgIdSvcProvider:orgId, view:'enhanced', isMERIT:true]) >> [resp:[projects:serviceProviderProjects]]

projects.size() == serviceProviderProjects.size() + organisationProjects.size()
projects == organisationProjects + serviceProviderProjects

when: "there is overlap between the organisation and service provider projects"
organisation = service.get(orgId)
projects = organisation.projects

then: "there should be no duplicate projects returned"
1 * projectService.search([organisationId:orgId, view:'enhanced', isMERIT:true]) >> [resp:[projects:organisationProjectsWithDuplicates]]
1 * projectService.search([orgIdSvcProvider:orgId, view:'enhanced', isMERIT:true]) >> [resp:[projects:serviceProviderProjects]]

projects.size() == serviceProviderProjects.size() + organisationProjects.size()
projects.sort{it.projectId} == (organisationProjects + serviceProviderProjects).sort{it.projectId}

}

def "Checking if abn already exist in db"(){
setup:
String ordId = "123"
Expand Down Expand Up @@ -272,7 +215,7 @@ class OrganisationServiceSpec extends Specification implements ServiceUnitTest<O
then:
1 * webService.getJson({it.endsWith('organisation/o1?view=')}) >> [organisationId:"o1"]
1 * reportService.get("r1") >> [reportId:"r1", organisationId:"o1", activityId:'a1']
1 * reportService.cancelReport("r1", ['a1'], "Testing", [organisationId:"o1", projects:[], reports:null], [])
1 * reportService.cancelReport("r1", ['a1'], "Testing", [organisationId:"o1", reports:null], [])
1 * webService.getJson({it.endsWith('permissions/getMembersForOrganisation/o1')}) >> []
}

Expand Down