Skip to content

Commit

Permalink
Changed bulkUpdate to use DataSetSummaryService #3174
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed May 6, 2024
1 parent b9419ec commit bd7494f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.apache.http.HttpStatus
class DataSetSummaryService {

static String DATA_SET_PATH_PREFIX = 'dataSetSummary/'
static String BULK_UPDATE_PATH = 'bulkUpdate/'
WebService webService
GrailsApplication grailsApplication

Expand All @@ -29,6 +30,12 @@ class DataSetSummaryService {
webService.doPost(url, dataSet)
}

Map bulkUpdateDataSets(String projectId, List dataSets) {
String url = grailsApplication.config.getProperty('ecodata.baseUrl')+
DATA_SET_PATH_PREFIX+BULK_UPDATE_PATH+projectId
webService.doPost(url, [dataSets:dataSets])
}

Map deleteDataSet(String projectId, String dataSetId) {
String url = grailsApplication.config.getProperty('ecodata.baseUrl')+DATA_SET_PATH_PREFIX+projectId+'/'+dataSetId
int status = webService.doDelete(url)
Expand Down
14 changes: 10 additions & 4 deletions grails-app/services/au/org/ala/merit/ProjectService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ProjectService {
ProjectConfigurationService projectConfigurationService
def programService
LockService lockService
DataSetSummaryService dataSetSummaryService

def get(id, levelOfDetail = "", includeDeleted = false) {

Expand Down Expand Up @@ -2120,13 +2121,15 @@ class ProjectService {
* @return
*/
Map bulkUpdateDataSetSummaries(String projectId, String reportId, List dataSetIds, Map properties) {
boolean dirty = false

List errors = []
Map project = get(projectId)
List<Map> toUpdate = []
dataSetIds?.each { String dataSetId ->

Map dataSet = project.custom?.dataSets?.find{it.dataSetId == dataSetId}
if (dataSet) {
boolean dirty = false
// Associate the data set with the report
if (!dataSet.reportId) {
dataSet.reportId = reportId
Expand All @@ -2150,6 +2153,9 @@ class ProjectService {
dirty = true
}
}
if (dirty) {
toUpdate << dataSet
}
}
else {
errors << "Report ${reportId} references data set ${dataSetId} which does not exist in project ${projectId}"
Expand All @@ -2161,13 +2167,13 @@ class ProjectService {
}.each {
it.reportId = null
it.publicationStatus = null
dirty = true
toUpdate << it
}

Map result = [:]
if (dirty) {
if (toUpdate) {
// Save the changes to the data sets
result = updateUnchecked(project.projectId, [custom: project.custom])
result = dataSetSummaryService.bulkUpdateDataSets(projectId, toUpdate)
if (result?.error) {
errors << result.error
}
Expand Down

0 comments on commit bd7494f

Please sign in to comment.