Skip to content

Commit

Permalink
Merge Project custom property instead of replace in update method #934
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed May 4, 2024
1 parent f3a59ff commit c6a855f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions grails-app/services/au/org/ala/ecodata/ProjectService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ class ProjectService {
props = includeProjectActivities(props, projectActivities)

try {
// Custom currently holds keys "details" and "dataSets". Only update the "custom" properties
// that are supplied in the update, leaving the others intact.
if (project.custom && props.custom) {
project.custom.putAll(props.remove('custom'))
}
bindEmbeddedProperties(project, props)
commonService.updateProperties(project, props)
if (shouldUpdateCollectory) {
Expand Down
22 changes: 22 additions & 0 deletions src/test/groovy/au/org/ala/ecodata/ProjectServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -828,4 +828,26 @@ class ProjectServiceSpec extends MongoSpec implements ServiceUnitTest<ProjectSer
}
void "The update method merges the Project custom property"() {
setup:
Map dataSet = [name: 'Test Data Set', description: 'Test Description', dataSetId:'d1']
Project project = new Project(projectId: '345', name: "Project 345", isMERIT: true, hubId:"12345", custom:[dataSets:[dataSet], details:[name:'name']])
project.save(flush: true, failOnError: true)
when:
Map resp = service.update([custom:[details:[name:'name 2']]], project.projectId, false)
then:
resp.status == 'ok'
Project actual = Project.findByProjectId(project.projectId)
actual.projectId == project.projectId
actual.name == project.name
actual.isMERIT == project.isMERIT
actual.hubId == project.hubId
actual.custom.dataSets == project.custom.dataSets
actual.custom.details == [name:'name 2']
}
}

0 comments on commit c6a855f

Please sign in to comment.