diff --git a/grails-app/services/au/org/ala/profile/OpusService.groovy b/grails-app/services/au/org/ala/profile/OpusService.groovy index 72505cd..f1a3bed 100644 --- a/grails-app/services/au/org/ala/profile/OpusService.groovy +++ b/grails-app/services/au/org/ala/profile/OpusService.groovy @@ -72,6 +72,8 @@ class OpusService extends BaseDataAccessService { opus.markDirty('approvedLists') } opus.approvedLists.addAll(json.approvedLists) + } else { + opus.approvedLists.removeAll(opus.approvedLists) } if (json.featureLists) { @@ -82,6 +84,8 @@ class OpusService extends BaseDataAccessService { opus.markDirty('featureLists') } opus.featureLists.addAll(json.featureLists) + } else { + opus.featureLists.removeAll(opus.featureLists) } opus.featureListSectionName = json.featureListSectionName ? json.featureListSectionName : null; diff --git a/src/integration-test/groovy/au/org/ala/profile/OpusServiceSpec.groovy b/src/integration-test/groovy/au/org/ala/profile/OpusServiceSpec.groovy index fd1aa55..0f88beb 100644 --- a/src/integration-test/groovy/au/org/ala/profile/OpusServiceSpec.groovy +++ b/src/integration-test/groovy/au/org/ala/profile/OpusServiceSpec.groovy @@ -7,6 +7,7 @@ import au.org.ala.web.UserDetails import grails.gorm.transactions.Rollback import grails.gsp.PageRenderer import grails.testing.mixin.integration.Integration +import net.sf.json.JSONObject import org.springframework.beans.factory.annotation.Autowired import org.springframework.web.multipart.commons.CommonsMultipartFile @@ -271,4 +272,92 @@ class OpusServiceSpec extends BaseIntegrationSpec { 1 * service.attachmentService.saveAttachment(_, _, _, _, _) 0 * service.attachmentService.deleteAttachment(_, _, _, _) } -} + + def "update opus for approved lists"() { + given: + Opus opus1 = new Opus(title: "opus1", dataResourceUid: "123", glossary: new Glossary(), approvedLists: ["dr123", "dr345"]) + + def opus2 = [ + title : "opus1", + dataResourceUid : "123", + approvedLists : ["dr123"], + ] + + + JSONObject json1 = new JSONObject(opus2) + save opus1 + + when: + Opus updateOpus = service.updateOpus(opus1.uuid, json1) + + then: + updateOpus.approvedLists.size() == json1.approvedLists.size() + } + + def "update opus for featured lists"() { + given: + Opus opus1 = new Opus(title: "opus1", dataResourceUid: "123", glossary: new Glossary(), featureLists: ["dr123", "dr345", "dr678"]) + + def opus2 = [ + title : "opus1", + dataResourceUid : "123", + featureLists : ["dr345"], + ] + + + JSONObject json1 = new JSONObject(opus2) + save opus1 + + when: + Opus updateOpus = service.updateOpus(opus1.uuid, json1) + + then: + updateOpus.featureLists.size() == json1.featureLists.size() + } + + def "update opus for approved lists and feature lists"() { + given: + Opus opus1 = new Opus(title: "opus1", dataResourceUid: "123", glossary: new Glossary(), approvedLists: ["dr123", "dr345"], featureLists: ["fl123","fl456","fl789"]) + + def opus2 = [ + title : "opus1", + dataResourceUid : "123", + approvedLists : ["dr123"], + featureLists : ["fl123", "fl456"] + ] + + + JSONObject json1 = new JSONObject(opus2) + save opus1 + + when: + Opus updateOpus = service.updateOpus(opus1.uuid, json1) + + then: + updateOpus.approvedLists.size() == json1.approvedLists.size() + updateOpus.featureLists.size() == json1.featureLists.size() + } + + def "update opus for approved lists and feature lists are empty"() { + given: + Opus opus1 = new Opus(title: "opus1", dataResourceUid: "123", glossary: new Glossary(), approvedLists: [], featureLists: []) + + def opus2 = [ + title : "opus1", + dataResourceUid : "123", + approvedLists : [], + featureLists : [] + ] + + + JSONObject json1 = new JSONObject(opus2) + save opus1 + + when: + Opus updateOpus = service.updateOpus(opus1.uuid, json1) + + then: + updateOpus.approvedLists.size() == json1.approvedLists.size() + updateOpus.featureLists.size() == json1.featureLists.size() + } +} \ No newline at end of file