Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[#3423] Delete DataPointAssigment when removing SurveyAssignment #3424

Merged
merged 2 commits into from
Feb 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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