From 0d3701be88d18dabc9d2ba609171ac09b350ea4a Mon Sep 17 00:00:00 2001 From: dunithd Date: Thu, 29 Jun 2017 18:25:28 +0530 Subject: [PATCH 1/3] Checking whether the geo location service has been enabled before reading stats from analytics server --- .../mgt/jaxrs/service/impl/GeoServiceImpl.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoServiceImpl.java index ffd793eef80..5a371e25d85 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoServiceImpl.java @@ -37,6 +37,9 @@ import org.wso2.carbon.device.mgt.common.geo.service.Event; import org.wso2.carbon.device.mgt.common.geo.service.GeoFence; import org.wso2.carbon.device.mgt.common.geo.service.GeoServiceException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; +import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.jaxrs.service.api.GeoService; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; @@ -73,6 +76,15 @@ public class GeoServiceImpl implements GeoService { public Response getGeoDeviceStats(@PathParam("deviceId") String deviceId, @PathParam("deviceType") String deviceType, @QueryParam("from") long from, @QueryParam("to") long to) { + //First, check whether the Geo Location service has been enabled in the cdmf-config.xml file + DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance() + .getDeviceManagementConfig(); + if (deviceManagementConfig != null) { + if(!deviceManagementConfig.getGeoLocationConfiguration().getPublishLocationOperationResponse()){ + log.warn("Failed to fetch geo location stats since the GeoLocation service has not been enabled."); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + } + } String tableName = "IOT_PER_DEVICE_STREAM_GEO_FUSEDSPATIALEVENT"; String fromDate = String.valueOf(from); String toDate = String.valueOf(to); From 07c525667c79692a1e542a46def8dd02ac545376 Mon Sep 17 00:00:00 2001 From: dunithd Date: Thu, 29 Jun 2017 18:27:04 +0530 Subject: [PATCH 2/3] Removing an unused import --- .../carbon/device/mgt/jaxrs/service/impl/GeoServiceImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoServiceImpl.java index 5a371e25d85..29ea4325838 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoServiceImpl.java @@ -37,7 +37,6 @@ import org.wso2.carbon.device.mgt.common.geo.service.Event; import org.wso2.carbon.device.mgt.common.geo.service.GeoFence; import org.wso2.carbon.device.mgt.common.geo.service.GeoServiceException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; -import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.jaxrs.service.api.GeoService; From cffecfaf3a8aa7469a476947aec582ae56b19dd5 Mon Sep 17 00:00:00 2001 From: dunithd Date: Fri, 30 Jun 2017 10:45:40 +0530 Subject: [PATCH 3/3] Removing the warning message and changing the HTTP response status code to 400 --- .../carbon/device/mgt/jaxrs/service/impl/GeoServiceImpl.java | 3 +-- 1 file changed, 1 insertion(+), 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/GeoServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoServiceImpl.java index 29ea4325838..b81df06d52d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoServiceImpl.java @@ -80,8 +80,7 @@ public class GeoServiceImpl implements GeoService { .getDeviceManagementConfig(); if (deviceManagementConfig != null) { if(!deviceManagementConfig.getGeoLocationConfiguration().getPublishLocationOperationResponse()){ - log.warn("Failed to fetch geo location stats since the GeoLocation service has not been enabled."); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + return Response.status(Response.Status.BAD_REQUEST.getStatusCode()).build(); } } String tableName = "IOT_PER_DEVICE_STREAM_GEO_FUSEDSPATIALEVENT";