From 84608f2f580adf300dacce46355183fd216e70ec Mon Sep 17 00:00:00 2001 From: Pahansith Date: Thu, 5 Nov 2020 09:49:39 +0530 Subject: [PATCH] Fix issue in Geo fence get by fence name --- .../impl/GeoLocationBasedServiceImpl.java | 2 +- .../mgt/core/dao/impl/GeofenceDAOImpl.java | 30 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) 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 aa41922d5a..144b1228b7 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 @@ -659,7 +659,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { @QueryParam("name") String name) { try { GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService(); - if (offset != 0 && limit != 0) { + if (offset >= 0 && limit != 0) { PaginationRequest request = new PaginationRequest(offset, limit); if (name != null && !name.isEmpty()) { request.setProperty(DeviceManagementConstants.GeoServices.FENCE_NAME, name); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GeofenceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GeofenceDAOImpl.java index 452c2ecc3a..e02c381196 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GeofenceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GeofenceDAOImpl.java @@ -166,7 +166,35 @@ public class GeofenceDAOImpl implements GeofenceDAO { @Override public List getGeoFencesOfTenant(String fenceName, int tenantId) throws DeviceManagementDAOException { - return null; + try { + List geofenceData; + Connection conn = this.getConnection(); + String sql = "SELECT " + + "ID, " + + "FENCE_NAME, " + + "DESCRIPTION, " + + "LATITUDE, " + + "LONGITUDE, " + + "RADIUS, " + + "GEO_JSON, " + + "FENCE_SHAPE, " + + "OWNER, " + + "TENANT_ID " + + "FROM DM_GEOFENCE " + + "WHERE FENCE_NAME LIKE ? AND TENANT_ID = ? "; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, fenceName + "%"); + stmt.setInt(2, tenantId); + try (ResultSet rst = stmt.executeQuery()) { + geofenceData = extractGeofenceData(rst); + } + } + return geofenceData; + } catch (SQLException e) { + String msg = "Error occurred while retrieving Geofence of the tenant " + tenantId; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } } @Override