diff --git a/grails-app/services/au/org/ala/merit/ImportService.groovy b/grails-app/services/au/org/ala/merit/ImportService.groovy index 24a11f16d..f8b3cc60c 100644 --- a/grails-app/services/au/org/ala/merit/ImportService.groovy +++ b/grails-app/services/au/org/ala/merit/ImportService.groovy @@ -405,7 +405,7 @@ class ImportService { } else { refreshOrganisationList() - projectDetails.associatedOrgs[0].organisationId = orgCreationResult.resp.organisationId + projectDetails.project.associatedOrgs[0].organisationId = orgCreationResult.resp.organisationId } } diff --git a/src/main/groovy/au/org/ala/merit/GmsMapper.groovy b/src/main/groovy/au/org/ala/merit/GmsMapper.groovy index 1bb131e2c..be79041d2 100644 --- a/src/main/groovy/au/org/ala/merit/GmsMapper.groovy +++ b/src/main/groovy/au/org/ala/merit/GmsMapper.groovy @@ -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 @@ -285,7 +286,12 @@ 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 { @@ -293,12 +299,11 @@ class GmsMapper { 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 { diff --git a/src/test/groovy/au/org/ala/merit/GmsMapperSpec.groovy b/src/test/groovy/au/org/ala/merit/GmsMapperSpec.groovy index f70b4511d..c23573a95 100644 --- a/src/test/groovy/au/org/ala/merit/GmsMapperSpec.groovy +++ b/src/test/groovy/au/org/ala/merit/GmsMapperSpec.groovy @@ -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"(){ @@ -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"(){