diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GeoService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GeoService.java index 34ede516ac..7f34536ede 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GeoService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GeoService.java @@ -150,7 +150,7 @@ public interface GeoService { * Create Geo alerts */ @POST - @Path("alerts/{executionPlanType}/{deviceType}/{deviceId}") + @Path("alerts/{alertType}/{deviceType}/{deviceId}") @ApiOperation( consumes = "application/json", produces = "application/json", @@ -206,16 +206,16 @@ public interface GeoService { @Size(max = 45) String deviceType, @ApiParam( - name = "executionPlanType", - value = "The execution plan type, such as Within, Speed, Stationary", + name = "alertType", + value = "The alert type, such as Within, Speed, Stationary", required = true) - @PathParam("executionPlanType") String executionPlanType); + @PathParam("alertType") String alertType); /** * Update Geo alerts */ @PUT - @Path("alerts/{executionPlanType}/{deviceType}/{deviceId}") + @Path("alerts/{alertType}/{deviceType}/{deviceId}") @ApiOperation( consumes = "application/json", produces = "application/json", @@ -271,16 +271,16 @@ public interface GeoService { @Size(max = 45) String deviceType, @ApiParam( - name = "executionPlanType", - value = "The execution plan type, such as Within, Speed, Stationary", + name = "alertType", + value = "The alert type, such as Within, Speed, Stationary", required = true) - @PathParam("executionPlanType") String executionPlanType); + @PathParam("alertType") String alertType); /** * Retrieve Geo alerts */ @GET - @Path("alerts/{executionPlanType}/{deviceType}/{deviceId}") + @Path("alerts/{alertType}/{deviceType}/{deviceId}") @ApiOperation( consumes = "application/json", produces = "application/json", @@ -335,10 +335,10 @@ public interface GeoService { @Size(max = 45) String deviceType, @ApiParam( - name = "executionPlanType", - value = "The execution plan type, such as Within, Speed, Stationary", + name = "alertType", + value = "The alert type, such as Within, Speed, Stationary", required = true) - @PathParam("executionPlanType") String executionPlanType); + @PathParam("alertType") String alertType); /** * Retrieve Geo alerts history @@ -410,7 +410,7 @@ public interface GeoService { @QueryParam("to") long to); @DELETE - @Path("alerts/{executionPlanType}/{deviceType}/{deviceId}") + @Path("alerts/{alertType}/{deviceType}/{deviceId}") @ApiOperation( consumes = "application/json", produces = "application/json", @@ -459,10 +459,10 @@ public interface GeoService { required = true) @PathParam("deviceType") String deviceType, @ApiParam( - name = "executionPlanType", - value = "The execution plan type, such as Within, Speed, Stationary", + name = "alertType", + value = "The alert type, such as Within, Speed, Stationary", required = true) - @PathParam("executionPlanType") String executionPlanType, + @PathParam("alertType") String alertType, @ApiParam( name = "queryName", value = "The query name.", 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 f90bfbc6ac..ffd793eef8 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 @@ -116,13 +116,13 @@ public class GeoServiceImpl implements GeoService { } } - @Path("alerts/{executionPlanType}/{deviceType}/{deviceId}") + @Path("alerts/{alertType}/{deviceType}/{deviceId}") @POST @Consumes("application/json") @Produces("application/json") public Response createGeoAlerts(Alert alert, @PathParam("deviceId") String deviceId, @PathParam("deviceType") String deviceType, - @PathParam("executionPlanType") String executionPlanType) { + @PathParam("alertType") String alertType) { try { if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized( new DeviceIdentifier(deviceId, deviceType), @@ -140,7 +140,7 @@ public class GeoServiceImpl implements GeoService { identifier.setType(deviceType); org.wso2.carbon.device.mgt.common.geo.service.GeoService geoService = DeviceMgtAPIUtils.getGeoService(); - geoService.createGeoAlert(alert, identifier, executionPlanType); + geoService.createGeoAlert(alert, identifier, alertType); return Response.ok().build(); } catch (DeviceAccessAuthorizationException | GeoServiceException e) { String error = "Error occurred while creating the geo alert for " + deviceType + " with id: " + deviceId; @@ -149,13 +149,13 @@ public class GeoServiceImpl implements GeoService { } } - @Path("alerts/{executionPlanType}/{deviceType}/{deviceId}") + @Path("alerts/{alertType}/{deviceType}/{deviceId}") @PUT @Consumes("application/json") @Produces("application/json") public Response updateGeoAlerts(Alert alert, @PathParam("deviceId") String deviceId, @PathParam("deviceType") String deviceType, - @PathParam("executionPlanType") String executionPlanType) { + @PathParam("alertType") String alertType) { try { if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized( new DeviceIdentifier(deviceId, deviceType), @@ -173,7 +173,7 @@ public class GeoServiceImpl implements GeoService { identifier.setType(deviceType); org.wso2.carbon.device.mgt.common.geo.service.GeoService geoService = DeviceMgtAPIUtils.getGeoService(); - geoService.updateGeoAlert(alert, identifier, executionPlanType); + geoService.updateGeoAlert(alert, identifier, alertType); return Response.ok().build(); } catch (DeviceAccessAuthorizationException | GeoServiceException e) { String error = "Error occurred while creating the geo alert for " + deviceType + " with id: " + deviceId; @@ -182,13 +182,13 @@ public class GeoServiceImpl implements GeoService { } } - @Path("alerts/{executionPlanType}/{deviceType}/{deviceId}") + @Path("alerts/{alertType}/{deviceType}/{deviceId}") @DELETE @Consumes("application/json") @Produces("application/json") public Response removeGeoAlerts(@PathParam("deviceId") String deviceId, @PathParam("deviceType") String deviceType, - @PathParam("executionPlanType") String executionPlanType, + @PathParam("alertType") String alertType, @QueryParam("queryName") String queryName) { try { if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized( @@ -207,7 +207,7 @@ public class GeoServiceImpl implements GeoService { identifier.setType(deviceType); org.wso2.carbon.device.mgt.common.geo.service.GeoService geoService = DeviceMgtAPIUtils.getGeoService(); - geoService.removeGeoAlert(executionPlanType, identifier, queryName); + geoService.removeGeoAlert(alertType, identifier, queryName); return Response.ok().build(); } catch (DeviceAccessAuthorizationException | GeoServiceException e) { String error = "Error occurred while removing the geo alert for " + deviceType + " with id: " + deviceId; @@ -216,13 +216,13 @@ public class GeoServiceImpl implements GeoService { } } - @Path("alerts/{executionPlanType}/{deviceType}/{deviceId}") + @Path("alerts/{alertType}/{deviceType}/{deviceId}") @GET @Consumes("application/json") @Produces("application/json") public Response getGeoAlerts(@PathParam("deviceId") String deviceId, @PathParam("deviceType") String deviceType, - @PathParam("executionPlanType") String executionPlanType) { + @PathParam("alertType") String alertType) { try { if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized( new DeviceIdentifier(deviceId, deviceType), @@ -241,22 +241,22 @@ public class GeoServiceImpl implements GeoService { org.wso2.carbon.device.mgt.common.geo.service.GeoService geoService = DeviceMgtAPIUtils.getGeoService(); - if (GeoServices.EXECUTION_PLAN_TYPE_WITHIN.equals(executionPlanType)) { + if (GeoServices.ALERT_TYPE_WITHIN.equals(alertType)) { List alerts = geoService.getWithinAlerts(identifier); return Response.ok().entity(alerts).build(); - } else if (GeoServices.EXECUTION_PLAN_TYPE_EXIT.equals(executionPlanType)) { + } else if (GeoServices.ALERT_TYPE_EXIT.equals(alertType)) { List alerts = geoService.getExitAlerts(identifier); return Response.ok().entity(alerts).build(); - } else if (GeoServices.EXECUTION_PLAN_TYPE_SPEED.equals(executionPlanType)) { + } else if (GeoServices.ALERT_TYPE_SPEED.equals(alertType)) { String result = geoService.getSpeedAlerts(identifier); return Response.ok().entity(result).build(); - } else if (GeoServices.EXECUTION_PLAN_TYPE_PROXIMITY.equals(executionPlanType)) { + } else if (GeoServices.ALERT_TYPE_PROXIMITY.equals(alertType)) { String result = geoService.getProximityAlerts(identifier); return Response.ok().entity(result).build(); - } else if (GeoServices.EXECUTION_PLAN_TYPE_STATIONARY.equals(executionPlanType)) { + } else if (GeoServices.ALERT_TYPE_STATIONARY.equals(alertType)) { List alerts = geoService.getStationaryAlerts(identifier); return Response.ok().entity(alerts).build(); - } else if (GeoServices.EXECUTION_PLAN_TYPE_TRAFFIC.equals(executionPlanType)) { + } else if (GeoServices.ALERT_TYPE_TRAFFIC.equals(alertType)) { List alerts = geoService.getTrafficAlerts(identifier); return Response.ok().entity(alerts).build(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java index 25aa80354d..3aa85254f8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java @@ -99,12 +99,12 @@ public final class DeviceManagementConstants { throw new AssertionError(); } - public static final String EXECUTION_PLAN_TYPE_SPEED = "Speed"; - public static final String EXECUTION_PLAN_TYPE_WITHIN = "Within"; - public static final String EXECUTION_PLAN_TYPE_EXIT = "Exit"; - public static final String EXECUTION_PLAN_TYPE_PROXIMITY = "Proximity"; - public static final String EXECUTION_PLAN_TYPE_STATIONARY = "Stationery"; - public static final String EXECUTION_PLAN_TYPE_TRAFFIC = "Traffic"; + public static final String ALERT_TYPE_SPEED = "Speed"; + public static final String ALERT_TYPE_WITHIN = "Within"; + public static final String ALERT_TYPE_EXIT = "Exit"; + public static final String ALERT_TYPE_PROXIMITY = "Proximity"; + public static final String ALERT_TYPE_STATIONARY = "Stationery"; + public static final String ALERT_TYPE_TRAFFIC = "Traffic"; public static final String REGISTRY_PATH_FOR_ALERTS = "/_system/governance/geo/alerts/"; public static final String PROXIMITY_DISTANCE = "proximityDistance"; public static final String PROXIMITY_TIME = "proximityTime"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/geo/service/GeoService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/geo/service/GeoService.java index 679fedb4ed..1880634c77 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/geo/service/GeoService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/geo/service/GeoService.java @@ -32,13 +32,13 @@ public interface GeoService { List getExitAlerts(DeviceIdentifier identifier) throws GeoServiceException; - boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String executionPlanType) + boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType) throws GeoServiceException; - boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String executionPlanType) + boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType) throws GeoServiceException; - boolean removeGeoAlert(String executionPlanType, DeviceIdentifier identifier, String queryName) + boolean removeGeoAlert(String alertType, DeviceIdentifier identifier, String queryName) throws GeoServiceException; String getSpeedAlerts(DeviceIdentifier identifier) throws GeoServiceException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoServcieManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoServcieManagerImpl.java index bad8a2c94c..400a7b1693 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoServcieManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoServcieManagerImpl.java @@ -114,7 +114,7 @@ public class GeoServcieManagerImpl implements GeoService { Registry registry = getGovernanceRegistry(); String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS + - GeoServices.EXECUTION_PLAN_TYPE_WITHIN + "/" + identifier.getId() + "/"; + GeoServices.ALERT_TYPE_WITHIN + "/" + identifier.getId() + "/"; Resource resource; try { resource = registry.get(registryPath); @@ -162,7 +162,7 @@ public class GeoServcieManagerImpl implements GeoService { Registry registry = getGovernanceRegistry(); String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS + - GeoServices.EXECUTION_PLAN_TYPE_EXIT + "/" + identifier.getId() + "/"; + GeoServices.ALERT_TYPE_EXIT + "/" + identifier.getId() + "/"; Resource resource; try { resource = registry.get(registryPath); @@ -206,18 +206,18 @@ public class GeoServcieManagerImpl implements GeoService { } @Override - public boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String executionPlanType) + public boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType) throws GeoServiceException { - return saveGeoAlert(alert, identifier, executionPlanType, false); + return saveGeoAlert(alert, identifier, alertType, false); } @Override - public boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String executionPlanType) + public boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType) throws GeoServiceException { - return saveGeoAlert(alert, identifier, executionPlanType, true); + return saveGeoAlert(alert, identifier, alertType, true); } - public boolean saveGeoAlert(Alert alert, DeviceIdentifier identifier, String executionPlanType, boolean isUpdate) + public boolean saveGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType, boolean isUpdate) throws GeoServiceException { Type type = new TypeToken>() { @@ -228,40 +228,40 @@ public class GeoServcieManagerImpl implements GeoService { Map options = new HashMap<>(); Object content = null; - if (GeoServices.EXECUTION_PLAN_TYPE_WITHIN.equals(executionPlanType)) { + if (GeoServices.ALERT_TYPE_WITHIN.equals(alertType)) { options.put(GeoServices.QUERY_NAME, alert.getQueryName()); options.put(GeoServices.AREA_NAME, alert.getCustomName()); content = parseMap.get(GeoServices.GEO_FENCE_GEO_JSON); - } else if (GeoServices.EXECUTION_PLAN_TYPE_EXIT.equals(executionPlanType)) { + } else if (GeoServices.ALERT_TYPE_EXIT.equals(alertType)) { options.put(GeoServices.QUERY_NAME, alert.getQueryName()); options.put(GeoServices.AREA_NAME, alert.getCustomName()); content = parseMap.get(GeoServices.GEO_FENCE_GEO_JSON); - } else if (GeoServices.EXECUTION_PLAN_TYPE_SPEED.equals(executionPlanType)) { + } else if (GeoServices.ALERT_TYPE_SPEED.equals(alertType)) { content = parseMap.get(GeoServices.SPEED_ALERT_VALUE); - } else if (GeoServices.EXECUTION_PLAN_TYPE_PROXIMITY.equals(executionPlanType)) { + } else if (GeoServices.ALERT_TYPE_PROXIMITY.equals(alertType)) { options.put(GeoServices.PROXIMITY_DISTANCE, alert.getProximityDistance()); options.put(GeoServices.PROXIMITY_TIME, alert.getProximityTime()); content = alert.getParseData(); - } else if (GeoServices.EXECUTION_PLAN_TYPE_STATIONARY.equals(executionPlanType)) { + } else if (GeoServices.ALERT_TYPE_STATIONARY.equals(alertType)) { options.put(GeoServices.QUERY_NAME, alert.getQueryName()); options.put(GeoServices.AREA_NAME, alert.getCustomName()); options.put(GeoServices.STATIONARY_TIME, alert.getStationeryTime()); options.put(GeoServices.FLUCTUATION_RADIUS, alert.getFluctuationRadius()); content = alert.getParseData(); - } else if (GeoServices.EXECUTION_PLAN_TYPE_TRAFFIC.equals(executionPlanType)) { + } else if (GeoServices.ALERT_TYPE_TRAFFIC.equals(alertType)) { content = parseMap.get(GeoServices.GEO_FENCE_GEO_JSON); } else { throw new GeoServiceException( - "Unrecognized execution plan type: " + executionPlanType + " while creating geo alert"); + "Unrecognized execution plan type: " + alertType + " while creating geo alert"); } //persist alert in registry - updateRegistry(getRegistryPath(executionPlanType, identifier, alert.getQueryName()), identifier, content, + updateRegistry(getRegistryPath(alertType, identifier, alert.getQueryName()), identifier, content, options); //deploy alert into event processor @@ -269,11 +269,11 @@ public class GeoServcieManagerImpl implements GeoService { String action = (isUpdate ? "updating" : "creating"); try { eventprocessorStub = getEventProcessorAdminServiceStub(); - String parsedTemplate = parseTemplate(executionPlanType, parseMap); + String parsedTemplate = parseTemplate(alertType, parseMap); String validationResponse = eventprocessorStub.validateExecutionPlan(parsedTemplate); if (validationResponse.equals("success")) { if (isUpdate) { - String executionPlanName = getExecutionPlanName(executionPlanType, alert.getQueryName(), + String executionPlanName = getExecutionPlanName(alertType, alert.getQueryName(), identifier.getId()); eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName); } else { @@ -289,68 +289,71 @@ public class GeoServcieManagerImpl implements GeoService { log.error("Execution plan validation failed: " + validationResponse); } throw new GeoServiceException( - "Error occurred while " + action + " geo " + executionPlanType + " alert for " + + "Error occurred while " + action + " geo " + alertType + " alert for " + identifier.getType() + " with id: " + identifier.getId()); } return true; } catch (AxisFault axisFault) { throw new GeoServiceException( "Event processor admin service initialization failed while " + action + " geo alert '" + - executionPlanType + "' for " + identifier.getType() + " " + + alertType + "' for " + identifier.getType() + " " + "device with id: " + identifier.getId(), axisFault ); } catch (IOException e) { throw new GeoServiceException( "Event processor admin service failed while " + action + " geo alert '" + - executionPlanType + "' for " + identifier.getType() + " " + + alertType + "' for " + identifier.getType() + " " + "device with id: " + identifier.getId(), e); } catch (JWTClientException e) { throw new GeoServiceException( - "JWT token creation failed while " + action + " geo alert '" + executionPlanType + "' for " + + "JWT token creation failed while " + action + " geo alert '" + alertType + "' for " + identifier.getType() + " device with id:" + identifier.getId(), e); } finally { cleanup(eventprocessorStub); } } - private String getRegistryPath(String executionPlanType, DeviceIdentifier identifier, String queryName) + private String getRegistryPath(String alertType, DeviceIdentifier identifier, String queryName) throws GeoServiceException { String path = ""; - if (GeoServices.EXECUTION_PLAN_TYPE_WITHIN.equals(executionPlanType)) { - path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.EXECUTION_PLAN_TYPE_WITHIN + + if (GeoServices.ALERT_TYPE_WITHIN.equals(alertType)) { + path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_WITHIN + "/" + identifier.getId() + "/" + queryName; - } else if (GeoServices.EXECUTION_PLAN_TYPE_SPEED.equals(executionPlanType)) { - path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.EXECUTION_PLAN_TYPE_SPEED + + } else if (GeoServices.ALERT_TYPE_EXIT.equals(alertType)) { + path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_EXIT + + "/" + identifier.getId() + "/" + queryName; + } else if (GeoServices.ALERT_TYPE_SPEED.equals(alertType)) { + path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_SPEED + "/" + identifier.getId(); - } else if (GeoServices.EXECUTION_PLAN_TYPE_PROXIMITY.equals(executionPlanType)) { - path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.EXECUTION_PLAN_TYPE_PROXIMITY + + } else if (GeoServices.ALERT_TYPE_PROXIMITY.equals(alertType)) { + path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_PROXIMITY + "/" + identifier.getId() + "/" + queryName; - } else if (GeoServices.EXECUTION_PLAN_TYPE_STATIONARY.equals(executionPlanType)) { - path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.EXECUTION_PLAN_TYPE_STATIONARY + + } else if (GeoServices.ALERT_TYPE_STATIONARY.equals(alertType)) { + path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_STATIONARY + "/" + identifier.getId() + "/" + queryName; - } else if (GeoServices.EXECUTION_PLAN_TYPE_TRAFFIC.equals(executionPlanType)) { - path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.EXECUTION_PLAN_TYPE_TRAFFIC + + } else if (GeoServices.ALERT_TYPE_TRAFFIC.equals(alertType)) { + path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_TRAFFIC + "/" + identifier.getId() + "/" + queryName; } else { throw new GeoServiceException( - "Unrecognized execution plan type: " + executionPlanType); + "Unrecognized execution plan type: " + alertType); } return path; } - private String getExecutionPlanName(String executionPlanType, String queryName, String deviceId) { - if ("Traffic".equals(executionPlanType)) { + private String getExecutionPlanName(String alertType, String queryName, String deviceId) { + if ("Traffic".equals(alertType)) { return "Geo-ExecutionPlan-Traffic_" + queryName + "_alert"; } else { - return "Geo-ExecutionPlan-" + executionPlanType + "_" + queryName + "---_" + deviceId + "_alert"; + return "Geo-ExecutionPlan-" + alertType + "_" + queryName + "---_" + deviceId + "_alert"; } } @Override - public boolean removeGeoAlert(String executionPlanType, DeviceIdentifier identifier, String queryName) + public boolean removeGeoAlert(String alertType, DeviceIdentifier identifier, String queryName) throws GeoServiceException { - removeFromRegistry(executionPlanType, identifier, queryName); - String executionPlanName = getExecutionPlanName(executionPlanType, queryName, identifier.getId()); + removeFromRegistry(alertType, identifier, queryName); + String executionPlanName = getExecutionPlanName(alertType, queryName, identifier.getId()); EventProcessorAdminServiceStub eventprocessorStub = null; try { eventprocessorStub = getEventProcessorAdminServiceStub(); @@ -359,13 +362,13 @@ public class GeoServcieManagerImpl implements GeoService { } catch (IOException e) { throw new GeoServiceException( "Event processor admin service stub invocation failed while removing geo alert '" + - executionPlanType + + alertType + "': " + executionPlanName + " for " + identifier.getType() + " device with id:" + identifier.getId(), e ); } catch (JWTClientException e) { throw new GeoServiceException( - "JWT token creation failed while removing geo alert '" + executionPlanType + "': " + + "JWT token creation failed while removing geo alert '" + alertType + "': " + executionPlanName + " for " + identifier.getType() + " device with id:" + identifier.getId(), e ); @@ -374,15 +377,15 @@ public class GeoServcieManagerImpl implements GeoService { } } - private void removeFromRegistry(String executionPlanType, DeviceIdentifier identifier, String queryName) + private void removeFromRegistry(String alertType, DeviceIdentifier identifier, String queryName) throws GeoServiceException { String path = "unknown"; try { - path = getRegistryPath(executionPlanType, identifier, queryName); + path = getRegistryPath(alertType, identifier, queryName); getGovernanceRegistry().delete(path); } catch (RegistryException e) { throw new GeoServiceException( - "Error occurred while removing " + executionPlanType + " alert for " + identifier.getType() + + "Error occurred while removing " + alertType + " alert for " + identifier.getType() + " device with id:" + identifier.getId() + " from the path: " + path); } } @@ -438,7 +441,7 @@ public class GeoServcieManagerImpl implements GeoService { try { Registry registry = getGovernanceRegistry(); Resource resource = registry.get(GeoServices.REGISTRY_PATH_FOR_ALERTS + - GeoServices.EXECUTION_PLAN_TYPE_SPEED + "/" + identifier.getId()); + GeoServices.ALERT_TYPE_SPEED + "/" + identifier.getId()); if (resource == null) { return "{'content': false}"; } @@ -456,7 +459,7 @@ public class GeoServcieManagerImpl implements GeoService { try { Registry registry = getGovernanceRegistry(); Resource resource = registry.get(GeoServices.REGISTRY_PATH_FOR_ALERTS + - GeoServices.EXECUTION_PLAN_TYPE_PROXIMITY + GeoServices.ALERT_TYPE_PROXIMITY + "/" + identifier.getId()); if (resource != null) { Properties props = resource.getProperties(); @@ -480,7 +483,7 @@ public class GeoServcieManagerImpl implements GeoService { Registry registry = getGovernanceRegistry(); String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS + - GeoServices.EXECUTION_PLAN_TYPE_STATIONARY + "/" + identifier.getId() + "/"; + GeoServices.ALERT_TYPE_STATIONARY + "/" + identifier.getId() + "/"; Resource resource; try { resource = registry.get(registryPath); @@ -531,7 +534,7 @@ public class GeoServcieManagerImpl implements GeoService { public List getTrafficAlerts(DeviceIdentifier identifier) throws GeoServiceException { Registry registry = getGovernanceRegistry(); String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS + - GeoServices.EXECUTION_PLAN_TYPE_STATIONARY + "/" + identifier.getId() + "/"; + GeoServices.ALERT_TYPE_STATIONARY + "/" + identifier.getId() + "/"; Resource resource; try { resource = registry.get(registryPath); @@ -587,8 +590,8 @@ public class GeoServcieManagerImpl implements GeoService { } } - private String parseTemplate(String executionPlan, Map parseMap) throws GeoServiceException { - String templatePath = "alerts/Geo-ExecutionPlan-" + executionPlan + "_alert.siddhiql"; + private String parseTemplate(String alertType, Map parseMap) throws GeoServiceException { + String templatePath = "alerts/Geo-ExecutionPlan-" + alertType + "_alert.siddhiql"; InputStream resource = getClass().getClassLoader().getResourceAsStream(templatePath); if (resource == null) { throw new GeoServiceException("Could not find template in path : " + templatePath);