Skip to content

Commit

Permalink
Fixed name check for orgs to create #2880
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Dec 2, 2024
1 parent 35e7b12 commit 1f3fbd1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion grails-app/services/au/org/ala/merit/ImportService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class ImportService {
}
else {
refreshOrganisationList()
projectDetails.associatedOrgs[0].organisationId = orgCreationResult.resp.organisationId
projectDetails.project.associatedOrgs[0].organisationId = orgCreationResult.resp.organisationId
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/main/groovy/au/org/ala/merit/GmsMapper.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package au.org.ala.merit

import au.com.bytecode.opencsv.CSVWriter
import org.apache.commons.lang.WordUtils
import org.apache.commons.validator.EmailValidator

import java.text.DecimalFormat
Expand Down Expand Up @@ -285,20 +286,24 @@ class GmsMapper {
abnLookup = abnLookupService.lookupOrganisationDetailsByABN(abn)
if (abnLookup && !abnLookup.error) {
List names = [abnLookup.entityName] + abnLookup.businessNames
organisation = organisations.find { it.name in names }
if (contractName) {
names << contractName
}
organisation = organisations.find { Map org ->
names.find{it && (it.toLowerCase() == org.name?.toLowerCase())}
}
if (organisation) {
error = "An existing organisation name was matched via the entity/business name ${organisation.name} but the ABN doesn't match the abn of the MERIT organisation (${organisation.abn})"
} else {
createOrganisation = true
String name
if (contractName) {
name = contractName
organisation = abnLookup + [name:contractName, contractNames: [contractName]]
}
else {
name = abnLookup.businessNames ? abnLookup.businessNames[0] : abnLookup.entityName
organisation = abnLookup + [name: name]
name = WordUtils.capitalizeFully(abnLookup.entityName)
}
organisation = abnLookup + [name: name]
messages << "An organisation will be created with ABN: ${abn} and name: ${name}"
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/test/groovy/au/org/ala/merit/GmsMapperSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ class GmsMapperSpec extends Specification{
1 * abnLookupService.lookupOrganisationDetailsByABN(abn) >> abnValue

and:
result.project.associatedOrgs == [[organisationId:null, name:"Test org 12345678900", description:"Recipient"]]
result.messages[0] == "An organisation will be created with ABN: 12345678900 and name: Test org 12345678900"
result.project.associatedOrgs == [[organisationId:null, name:"Test Org 12345678900", description:"Recipient"]]
result.messages[0] == "An organisation will be created with ABN: 12345678900 and name: Test Org 12345678900"
}

def "The organisation relationship can be derived from the program"(){
Expand All @@ -266,8 +266,8 @@ class GmsMapperSpec extends Specification{
1 * abnLookupService.lookupOrganisationDetailsByABN(abn) >> abnValue

and:
result.project.associatedOrgs == [[organisationId:null, name:"Test org 12345678900", description:"Recipient"]]
result.messages[0] == "An organisation will be created with ABN: 12345678900 and name: Test org 12345678900"
result.project.associatedOrgs == [[organisationId:null, name:"Test Org 12345678900", description:"Recipient"]]
result.messages[0] == "An organisation will be created with ABN: 12345678900 and name: Test Org 12345678900"
}

def "If an ABN is supplied in the project load, the looked up entity name cannot match another MERIT organisation"(){
Expand Down

0 comments on commit 1f3fbd1

Please sign in to comment.