Skip to content

Commit

Permalink
Merge pull request #3424 from akvo/issue/3423-assignments
Browse files Browse the repository at this point in the history
[#3423] Delete `DataPointAssigment` when removing `SurveyAssignment`
  • Loading branch information
stellanl authored Feb 18, 2020
2 parents d67e198 + e7472de commit f85f2d7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion GAE/src/org/akvo/flow/rest/SurveyAssignmentRestService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012,2017,2019 Stichting Akvo (Akvo Foundation)
* Copyright (C) 2012,2017,2019,2020 Stichting Akvo (Akvo Foundation)
*
* This file is part of Akvo FLOW.
*
Expand All @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;

import org.akvo.flow.dao.DataPointAssignmentDao;
import org.akvo.flow.dao.SurveyAssignmentDao;
import org.akvo.flow.domain.persistent.DataPointAssignment;
import org.akvo.flow.domain.persistent.SurveyAssignment;
Expand Down Expand Up @@ -59,6 +60,8 @@ public class SurveyAssignmentRestService {

private DeviceSurveyJobQueueDAO deviceSurveyJobQueueDAO = new DeviceSurveyJobQueueDAO();

private DataPointAssignmentDao dataPointAssignmentDao = new DataPointAssignmentDao();

@RequestMapping(method = RequestMethod.GET, value = "")
@ResponseBody
public Map<String, List<SurveyAssignmentDto>> listAll() {
Expand Down Expand Up @@ -99,6 +102,7 @@ public Map<String, RestStatusDto> deleteById(@PathVariable("id")
statusDto.setStatus("failed");
if (sa != null) {
deleteExistingDeviceSurveyJobQueueItems(sa);
deleteExistingDatapointAssignments(sa);
surveyAssignmentDao.delete(sa);
statusDto.setStatus("ok");
}
Expand Down Expand Up @@ -199,6 +203,11 @@ private void deleteExistingDeviceSurveyJobQueueItems(SurveyAssignment assignment
deviceSurveyJobQueueDAO.delete(deviceAssignmentsToDelete);
}

private void deleteExistingDatapointAssignments(SurveyAssignment assignment) {
List<DataPointAssignment> dataPointAssignments = dataPointAssignmentDao.listBySurveyAssignment(assignment.getKey().getId());
dataPointAssignmentDao.delete(dataPointAssignments);
}

/**
* creates and saves DeviceSurveyJobQueue objects for each device/survey pair in the assignment.
*/
Expand Down

0 comments on commit f85f2d7

Please # to comment.