From a0b882f7553f361b6728fe7aadc4c913e2bda469 Mon Sep 17 00:00:00 2001 From: "tcdlpds@gmail.com" Date: Fri, 2 Oct 2020 06:33:58 +0530 Subject: [PATCH] Fix geo fence deleting issue --- .../mgt/jaxrs/service/api/GeoLocationBasedService.java | 4 ++-- .../jaxrs/service/impl/GeoLocationBasedServiceImpl.java | 5 ++--- .../core/geo/service/GeoLocationProviderServiceImpl.java | 9 +++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GeoLocationBasedService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GeoLocationBasedService.java index 21747fc774..d0e87c6c40 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GeoLocationBasedService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GeoLocationBasedService.java @@ -48,6 +48,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @SwaggerDefinition( @@ -972,8 +973,7 @@ public interface GeoLocationBasedService { @DELETE @Path("/geo-fence/{fenceId}") @ApiOperation( - consumes = "application/json", - produces = "application/json", + consumes = MediaType.APPLICATION_JSON, httpMethod = "DELETE", value = "Delete Geo fence", notes = "Delete an existing geo fence", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index c854e80958..726afa5129 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -678,10 +678,9 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { } - @Path("/geo-fence/{fenceId}") @DELETE - @Consumes("application/json") - @Produces("application/json") + @Override + @Path("/geo-fence/{fenceId}") public Response deleteGeofence(@PathParam("fenceId") int fenceId) { try { GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java index 080e729fc2..d54818ca9c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java @@ -1327,7 +1327,12 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic public boolean deleteGeofenceData(int fenceId) throws GeoLocationBasedServiceException { try { DeviceManagementDAOFactory.beginTransaction(); - return geofenceDAO.deleteGeofenceById(fenceId) > 0; + if (geofenceDAO.deleteGeofenceById(fenceId) > 0) { + DeviceManagementDAOFactory.commitTransaction(); + return true; + } + DeviceManagementDAOFactory.rollbackTransaction(); + return false; } catch (DeviceManagementDAOException e) { String msg = "Error occurred while deleting geofence"; log.error(msg, e); @@ -1337,7 +1342,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } finally { - DeviceManagementDAOFactory.commitTransaction(); + DeviceManagementDAOFactory.closeConnection(); } }