From 50a14e43212bfdcf4673da394db005bc2066d679 Mon Sep 17 00:00:00 2001 From: Arcane94 Date: Tue, 13 Mar 2018 16:33:03 +0530 Subject: [PATCH] Requested changes --- .../service/api/GeoLocationBasedService.java | 12 +-- .../impl/GeoLocationBasedServiceImpl.java | 101 +++++++----------- .../GeoLocationProviderServiceImpl.java | 11 +- .../html_templates/modal/traffic_point.html | 82 +++++++------- .../cdmf.unit.geo-devices/public/js/app.js | 6 +- .../public/js/geo_exit_fence.js | 8 +- .../public/js/geo_fencing.js | 12 +-- .../public/js/geo_proximity.js | 6 +- .../public/js/geo_stationary.js | 10 +- .../public/js/geo_within.js | 8 +- .../public/js/show_alert_in_map.js | 4 - .../public/js/websocket.js | 6 +- 12 files changed, 111 insertions(+), 155 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 8396457e3f..aa84f83071 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 @@ -306,7 +306,7 @@ public interface GeoLocationBasedService { produces = "application/json", httpMethod = "POST", value = "Create Geo alerts for geo clusters", - notes = "", + notes = "Creating geo alerts for cluster of devices", response = Response.class, tags = "Geo Service Management", extensions = { @@ -424,7 +424,7 @@ public interface GeoLocationBasedService { produces = "application/json", httpMethod = "GET", value = "Update Geo alerts for geo clusters", - notes = "", + notes = "Updating an existing geo alert that was defined for geo clusters", response = Response.class, tags = "Geo Service Management", extensions = { @@ -541,7 +541,7 @@ public interface GeoLocationBasedService { produces = "application/json", httpMethod = "GET", value = "Retrieve Geo alerts for geo clusters", - notes = "", + notes = "Retrieve all the defined alerts for a specific alert type", response = Response.class, tags = "Geo Service Management", extensions = { @@ -663,7 +663,7 @@ public interface GeoLocationBasedService { produces = "application/json", httpMethod = "GET", value = "Retrieve Geo alerts history for geo clusters", - notes = "", + notes = "Retrieving geo alert history of all defined alerts for geo clusters", response = Response.class, tags = "Geo Service Management", extensions = { @@ -786,8 +786,8 @@ public interface GeoLocationBasedService { consumes = "application/json", produces = "application/json", httpMethod = "DELETE", - value = "Deletes Geo alerts for the device", - notes = "", + value = "Deletes Geo alerts for geo clusters", + notes = "Deleting any type of a geo alert that was defined for geo clusters", response = Response.class, tags = "Geo Service Management", extensions = { 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 34fbaae517..89f7c1aa7a 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 @@ -192,11 +192,6 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { @Produces("application/json") public Response createGeoAlertsForGeoClusters(Alert alert, @PathParam("alertType") String alertType) { try { - // this is the user who initiates the request - String authorizedUser = MultitenantUtils.getTenantAwareUsername( - CarbonContext.getThreadLocalCarbonContext().getUsername() - ); - GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService(); geoService.createGeoAlert(alert, alertType); return Response.ok().build(); @@ -255,11 +250,6 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { @Produces("application/json") public Response updateGeoAlertsForGeoClusters(Alert alert, @PathParam("alertType") String alertType) { try { - // this is the user who initiates the request - String authorizedUser = MultitenantUtils.getTenantAwareUsername( - CarbonContext.getThreadLocalCarbonContext().getUsername() - ); - GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService(); geoService.updateGeoAlert(alert, alertType); return Response.ok().build(); @@ -314,11 +304,6 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { @Produces("application/json") public Response removeGeoAlertsForGeoClusters(@PathParam("alertType") String alertType, @QueryParam("queryName") String queryName) { try { - // this is the user who initiates the request - String authorizedUser = MultitenantUtils.getTenantAwareUsername( - CarbonContext.getThreadLocalCarbonContext().getUsername() - ); - GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService(); geoService.removeGeoAlert(alertType, queryName); return Response.ok().build(); @@ -387,34 +372,34 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { @Produces("application/json") public Response getGeoAlertsForGeoClusters(@PathParam("alertType") String alertType) { try { - - // this is the user who initiates the request - String authorizedUser = MultitenantUtils.getTenantAwareUsername( - CarbonContext.getThreadLocalCarbonContext().getUsername() - ); - GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService(); - - if (GeoServices.ALERT_TYPE_WITHIN.equals(alertType)) { - List alerts = geoService.getWithinAlerts(); - return Response.ok().entity(alerts).build(); - } else if (GeoServices.ALERT_TYPE_EXIT.equals(alertType)) { - List alerts = geoService.getExitAlerts(); - return Response.ok().entity(alerts).build(); - } else if (GeoServices.ALERT_TYPE_SPEED.equals(alertType)) { - String result = geoService.getSpeedAlerts(); - return Response.ok().entity(result).build(); - } else if (GeoServices.ALERT_TYPE_PROXIMITY.equals(alertType)) { - String result = geoService.getProximityAlerts(); - return Response.ok().entity(result).build(); - } else if (GeoServices.ALERT_TYPE_STATIONARY.equals(alertType)) { - List alerts = geoService.getStationaryAlerts(); - return Response.ok().entity(alerts).build(); - } else if (GeoServices.ALERT_TYPE_TRAFFIC.equals(alertType)) { - List alerts = geoService.getTrafficAlerts(); - return Response.ok().entity(alerts).build(); + List alerts = null; + String result = null; + + switch (alertType) { + case GeoServices.ALERT_TYPE_WITHIN: + alerts = geoService.getWithinAlerts(); + break; + case GeoServices.ALERT_TYPE_EXIT: + alerts = geoService.getExitAlerts(); + break; + case GeoServices.ALERT_TYPE_STATIONARY: + alerts = geoService.getStationaryAlerts(); + break; + case GeoServices.ALERT_TYPE_TRAFFIC: + alerts = geoService.getTrafficAlerts(); + break; + case GeoServices.ALERT_TYPE_SPEED: + result = geoService.getSpeedAlerts(); + return Response.ok().entity(result).build(); + case GeoServices.ALERT_TYPE_PROXIMITY: + result = geoService.getProximityAlerts(); + return Response.ok().entity(result).build(); + default: + throw new GeoLocationBasedServiceException("Invalid Alert Type"); } - return null; + return Response.ok().entity(alerts).build(); + } catch (GeoLocationBasedServiceException e) { String error = "Error occurred while getting the geo alerts for " + alertType + " alert"; log.error(error, e); @@ -493,25 +478,21 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { String authorizedUser = MultitenantUtils.getTenantAwareUsername( CarbonContext.getThreadLocalCarbonContext().getUsername()); - try { - String tenantDomain = MultitenantUtils.getTenantDomain(authorizedUser); - int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain); - AnalyticsDataAPI analyticsDataAPI = DeviceMgtAPIUtils.getAnalyticsDataAPI(); - List searchResults = analyticsDataAPI.search(tenantId, tableName, query, - 0, - 100, - sortByFields); - List events = getEventBeans(analyticsDataAPI, tenantId, tableName, new ArrayList(), - searchResults); - return Response.ok().entity(events).build(); - } catch (AnalyticsException | UserStoreException e) { - log.error("Failed to perform search on table: " + tableName + " : " + e.getMessage(), e); - throw DeviceMgtUtil.buildBadRequestException( - Constants.ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT); - } - } catch (Exception e) { - log.error(e.getMessage()); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); + String tenantDomain = MultitenantUtils.getTenantDomain(authorizedUser); + int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain); + AnalyticsDataAPI analyticsDataAPI = DeviceMgtAPIUtils.getAnalyticsDataAPI(); + List searchResults = analyticsDataAPI.search(tenantId, tableName, query, + 0, + 100, + sortByFields); + List events = getEventBeans(analyticsDataAPI, tenantId, tableName, new ArrayList(), + searchResults); + return Response.ok().entity(events).build(); + + } catch (AnalyticsException | UserStoreException e) { + log.error("Failed to perform search on table: " + tableName + " : " + e.getMessage(), e); + throw DeviceMgtUtil.buildBadRequestException( + Constants.ErrorMessages.STATUS_BAD_REQUEST_MESSAGE_DEFAULT); } } 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 0122f6adfe..6be4f67488 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 @@ -73,6 +73,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Collections; import static org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoServices.DAS_PORT; import static org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoServices.DEFAULT_HTTP_PROTOCOL; @@ -171,7 +172,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic resource = registry.get(registryPath); } catch (RegistryException e) { log.error("Error while reading the registry path: " + registryPath); - return null; + return Collections.emptyList(); } try { @@ -266,7 +267,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic resource = registry.get(registryPath); } catch (RegistryException e) { log.error("Error while reading the registry path: " + registryPath); - return null; + return Collections.emptyList(); } try { @@ -612,7 +613,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic if ("Traffic".equals(alertType)) { return "Geo-ExecutionPlan-Traffic_" + queryName + "_alert"; } else { - if (alertType.equals("Speed")) { + if ("Speed".equals(alertType)) { return "Geo-ExecutionPlan-" + alertType + "---" + "_alert"; } return "Geo-ExecutionPlan-" + alertType + "_" + queryName + "---" + "_alert"; @@ -891,7 +892,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic resource = registry.get(registryPath); } catch (RegistryException e) { log.error("Error while reading the registry path: " + registryPath); - return null; + return Collections.emptyList(); } try { @@ -988,7 +989,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic resource = registry.get(registryPath); } catch (RegistryException e) { log.error("Error while reading the registry path: " + registryPath); - return null; + return Collections.emptyList(); } try { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-devices/public/assets/html_templates/modal/traffic_point.html b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-devices/public/assets/html_templates/modal/traffic_point.html index a290eb97eb..834cd47b4a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-devices/public/assets/html_templates/modal/traffic_point.html +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-devices/public/assets/html_templates/modal/traffic_point.html @@ -20,20 +20,23 @@ -