Merge branch 'geofence-group-issue' into 'master'

Fix geofence update issue

See merge request entgra/carbon-device-mgt!737
revert-70ac1926
Dharmakeerthi Lasantha 4 years ago
commit 28f7bc78c0

@ -116,7 +116,7 @@ public interface GeofenceDAO {
* @param groupIdsToDelete group ids to be removed from the mapping table * @param groupIdsToDelete group ids to be removed from the mapping table
* @throws DeviceManagementDAOException error occurred while deleting group id mapping records * @throws DeviceManagementDAOException error occurred while deleting group id mapping records
*/ */
void deleteGeofenceGroupMapping(List<Integer> groupIdsToDelete) throws DeviceManagementDAOException; void deleteGeofenceGroupMapping(List<Integer> groupIdsToDelete, int fenceId) throws DeviceManagementDAOException;
/** /**
* Create geofence-event mapping records * Create geofence-event mapping records

@ -356,13 +356,14 @@ public class GeofenceDAOImpl implements GeofenceDAO {
} }
@Override @Override
public void deleteGeofenceGroupMapping(List<Integer> groupIdsToDelete) throws DeviceManagementDAOException { public void deleteGeofenceGroupMapping(List<Integer> groupIdsToDelete, int fenceId) throws DeviceManagementDAOException {
try { try {
Connection conn = this.getConnection(); Connection conn = this.getConnection();
String sql = "DELETE FROM DM_GEOFENCE_GROUP_MAPPING WHERE GROUP_ID = ?"; String sql = "DELETE FROM DM_GEOFENCE_GROUP_MAPPING WHERE GROUP_ID = ? AND FENCE_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
for (Integer groupId : groupIdsToDelete) { for (Integer groupId : groupIdsToDelete) {
stmt.setInt(1, groupId); stmt.setInt(1, groupId);
stmt.setInt(2, fenceId);
stmt.addBatch(); stmt.addBatch();
} }
stmt.executeBatch(); stmt.executeBatch();

@ -1503,7 +1503,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
} }
List<Integer> groupIdsOfGeoFence = geofenceDAO.getGroupIdsOfGeoFence(fenceId); List<Integer> groupIdsOfGeoFence = geofenceDAO.getGroupIdsOfGeoFence(fenceId);
if (!groupIdsOfGeoFence.isEmpty()) { if (!groupIdsOfGeoFence.isEmpty()) {
geofenceDAO.deleteGeofenceGroupMapping(groupIdsOfGeoFence); geofenceDAO.deleteGeofenceGroupMapping(groupIdsOfGeoFence, fenceId);
} }
geofenceDAO.deleteGeofenceById(fenceId); geofenceDAO.deleteGeofenceById(fenceId);
DeviceManagementDAOFactory.commitTransaction(); DeviceManagementDAOFactory.commitTransaction();
@ -1554,7 +1554,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
groupIdsToAdd.add(newGroupId); groupIdsToAdd.add(newGroupId);
} }
} }
geofenceDAO.deleteGeofenceGroupMapping(groupIdsToDelete); geofenceDAO.deleteGeofenceGroupMapping(groupIdsToDelete, fenceId);
geofenceDAO.createGeofenceGroupMapping(geofenceData, groupIdsToAdd); geofenceDAO.createGeofenceGroupMapping(geofenceData, groupIdsToAdd);
DeviceManagementDAOFactory.commitTransaction(); DeviceManagementDAOFactory.commitTransaction();
if (updatedRowCount > 0) { if (updatedRowCount > 0) {

Loading…
Cancel
Save