Refactoring "executionPlanType" -> "alertType"

revert-70aa11f8
Rasika Perera 8 years ago
parent e1c5c72b1b
commit ce6ab9b354

@ -150,7 +150,7 @@ public interface GeoService {
* Create Geo alerts * Create Geo alerts
*/ */
@POST @POST
@Path("alerts/{executionPlanType}/{deviceType}/{deviceId}") @Path("alerts/{alertType}/{deviceType}/{deviceId}")
@ApiOperation( @ApiOperation(
consumes = "application/json", consumes = "application/json",
produces = "application/json", produces = "application/json",
@ -206,16 +206,16 @@ public interface GeoService {
@Size(max = 45) @Size(max = 45)
String deviceType, String deviceType,
@ApiParam( @ApiParam(
name = "executionPlanType", name = "alertType",
value = "The execution plan type, such as Within, Speed, Stationary", value = "The alert type, such as Within, Speed, Stationary",
required = true) required = true)
@PathParam("executionPlanType") String executionPlanType); @PathParam("alertType") String alertType);
/** /**
* Update Geo alerts * Update Geo alerts
*/ */
@PUT @PUT
@Path("alerts/{executionPlanType}/{deviceType}/{deviceId}") @Path("alerts/{alertType}/{deviceType}/{deviceId}")
@ApiOperation( @ApiOperation(
consumes = "application/json", consumes = "application/json",
produces = "application/json", produces = "application/json",
@ -271,16 +271,16 @@ public interface GeoService {
@Size(max = 45) @Size(max = 45)
String deviceType, String deviceType,
@ApiParam( @ApiParam(
name = "executionPlanType", name = "alertType",
value = "The execution plan type, such as Within, Speed, Stationary", value = "The alert type, such as Within, Speed, Stationary",
required = true) required = true)
@PathParam("executionPlanType") String executionPlanType); @PathParam("alertType") String alertType);
/** /**
* Retrieve Geo alerts * Retrieve Geo alerts
*/ */
@GET @GET
@Path("alerts/{executionPlanType}/{deviceType}/{deviceId}") @Path("alerts/{alertType}/{deviceType}/{deviceId}")
@ApiOperation( @ApiOperation(
consumes = "application/json", consumes = "application/json",
produces = "application/json", produces = "application/json",
@ -335,10 +335,10 @@ public interface GeoService {
@Size(max = 45) @Size(max = 45)
String deviceType, String deviceType,
@ApiParam( @ApiParam(
name = "executionPlanType", name = "alertType",
value = "The execution plan type, such as Within, Speed, Stationary", value = "The alert type, such as Within, Speed, Stationary",
required = true) required = true)
@PathParam("executionPlanType") String executionPlanType); @PathParam("alertType") String alertType);
/** /**
* Retrieve Geo alerts history * Retrieve Geo alerts history
@ -410,7 +410,7 @@ public interface GeoService {
@QueryParam("to") long to); @QueryParam("to") long to);
@DELETE @DELETE
@Path("alerts/{executionPlanType}/{deviceType}/{deviceId}") @Path("alerts/{alertType}/{deviceType}/{deviceId}")
@ApiOperation( @ApiOperation(
consumes = "application/json", consumes = "application/json",
produces = "application/json", produces = "application/json",
@ -459,10 +459,10 @@ public interface GeoService {
required = true) required = true)
@PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
@ApiParam( @ApiParam(
name = "executionPlanType", name = "alertType",
value = "The execution plan type, such as Within, Speed, Stationary", value = "The alert type, such as Within, Speed, Stationary",
required = true) required = true)
@PathParam("executionPlanType") String executionPlanType, @PathParam("alertType") String alertType,
@ApiParam( @ApiParam(
name = "queryName", name = "queryName",
value = "The query name.", value = "The query name.",

@ -116,13 +116,13 @@ public class GeoServiceImpl implements GeoService {
} }
} }
@Path("alerts/{executionPlanType}/{deviceType}/{deviceId}") @Path("alerts/{alertType}/{deviceType}/{deviceId}")
@POST @POST
@Consumes("application/json") @Consumes("application/json")
@Produces("application/json") @Produces("application/json")
public Response createGeoAlerts(Alert alert, @PathParam("deviceId") String deviceId, public Response createGeoAlerts(Alert alert, @PathParam("deviceId") String deviceId,
@PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
@PathParam("executionPlanType") String executionPlanType) { @PathParam("alertType") String alertType) {
try { try {
if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized( if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized(
new DeviceIdentifier(deviceId, deviceType), new DeviceIdentifier(deviceId, deviceType),
@ -140,7 +140,7 @@ public class GeoServiceImpl implements GeoService {
identifier.setType(deviceType); identifier.setType(deviceType);
org.wso2.carbon.device.mgt.common.geo.service.GeoService geoService = DeviceMgtAPIUtils.getGeoService(); 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(); return Response.ok().build();
} catch (DeviceAccessAuthorizationException | GeoServiceException e) { } catch (DeviceAccessAuthorizationException | GeoServiceException e) {
String error = "Error occurred while creating the geo alert for " + deviceType + " with id: " + deviceId; 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 @PUT
@Consumes("application/json") @Consumes("application/json")
@Produces("application/json") @Produces("application/json")
public Response updateGeoAlerts(Alert alert, @PathParam("deviceId") String deviceId, public Response updateGeoAlerts(Alert alert, @PathParam("deviceId") String deviceId,
@PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
@PathParam("executionPlanType") String executionPlanType) { @PathParam("alertType") String alertType) {
try { try {
if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized( if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized(
new DeviceIdentifier(deviceId, deviceType), new DeviceIdentifier(deviceId, deviceType),
@ -173,7 +173,7 @@ public class GeoServiceImpl implements GeoService {
identifier.setType(deviceType); identifier.setType(deviceType);
org.wso2.carbon.device.mgt.common.geo.service.GeoService geoService = DeviceMgtAPIUtils.getGeoService(); 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(); return Response.ok().build();
} catch (DeviceAccessAuthorizationException | GeoServiceException e) { } catch (DeviceAccessAuthorizationException | GeoServiceException e) {
String error = "Error occurred while creating the geo alert for " + deviceType + " with id: " + deviceId; 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 @DELETE
@Consumes("application/json") @Consumes("application/json")
@Produces("application/json") @Produces("application/json")
public Response removeGeoAlerts(@PathParam("deviceId") String deviceId, public Response removeGeoAlerts(@PathParam("deviceId") String deviceId,
@PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
@PathParam("executionPlanType") String executionPlanType, @PathParam("alertType") String alertType,
@QueryParam("queryName") String queryName) { @QueryParam("queryName") String queryName) {
try { try {
if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized( if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized(
@ -207,7 +207,7 @@ public class GeoServiceImpl implements GeoService {
identifier.setType(deviceType); identifier.setType(deviceType);
org.wso2.carbon.device.mgt.common.geo.service.GeoService geoService = DeviceMgtAPIUtils.getGeoService(); 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(); return Response.ok().build();
} catch (DeviceAccessAuthorizationException | GeoServiceException e) { } catch (DeviceAccessAuthorizationException | GeoServiceException e) {
String error = "Error occurred while removing the geo alert for " + deviceType + " with id: " + deviceId; 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 @GET
@Consumes("application/json") @Consumes("application/json")
@Produces("application/json") @Produces("application/json")
public Response getGeoAlerts(@PathParam("deviceId") String deviceId, public Response getGeoAlerts(@PathParam("deviceId") String deviceId,
@PathParam("deviceType") String deviceType, @PathParam("deviceType") String deviceType,
@PathParam("executionPlanType") String executionPlanType) { @PathParam("alertType") String alertType) {
try { try {
if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized( if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized(
new DeviceIdentifier(deviceId, deviceType), 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(); 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<GeoFence> alerts = geoService.getWithinAlerts(identifier); List<GeoFence> alerts = geoService.getWithinAlerts(identifier);
return Response.ok().entity(alerts).build(); return Response.ok().entity(alerts).build();
} else if (GeoServices.EXECUTION_PLAN_TYPE_EXIT.equals(executionPlanType)) { } else if (GeoServices.ALERT_TYPE_EXIT.equals(alertType)) {
List<GeoFence> alerts = geoService.getExitAlerts(identifier); List<GeoFence> alerts = geoService.getExitAlerts(identifier);
return Response.ok().entity(alerts).build(); 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); String result = geoService.getSpeedAlerts(identifier);
return Response.ok().entity(result).build(); 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); String result = geoService.getProximityAlerts(identifier);
return Response.ok().entity(result).build(); return Response.ok().entity(result).build();
} else if (GeoServices.EXECUTION_PLAN_TYPE_STATIONARY.equals(executionPlanType)) { } else if (GeoServices.ALERT_TYPE_STATIONARY.equals(alertType)) {
List<GeoFence> alerts = geoService.getStationaryAlerts(identifier); List<GeoFence> alerts = geoService.getStationaryAlerts(identifier);
return Response.ok().entity(alerts).build(); return Response.ok().entity(alerts).build();
} else if (GeoServices.EXECUTION_PLAN_TYPE_TRAFFIC.equals(executionPlanType)) { } else if (GeoServices.ALERT_TYPE_TRAFFIC.equals(alertType)) {
List<GeoFence> alerts = geoService.getTrafficAlerts(identifier); List<GeoFence> alerts = geoService.getTrafficAlerts(identifier);
return Response.ok().entity(alerts).build(); return Response.ok().entity(alerts).build();
} }

@ -99,12 +99,12 @@ public final class DeviceManagementConstants {
throw new AssertionError(); throw new AssertionError();
} }
public static final String EXECUTION_PLAN_TYPE_SPEED = "Speed"; public static final String ALERT_TYPE_SPEED = "Speed";
public static final String EXECUTION_PLAN_TYPE_WITHIN = "Within"; public static final String ALERT_TYPE_WITHIN = "Within";
public static final String EXECUTION_PLAN_TYPE_EXIT = "Exit"; public static final String ALERT_TYPE_EXIT = "Exit";
public static final String EXECUTION_PLAN_TYPE_PROXIMITY = "Proximity"; public static final String ALERT_TYPE_PROXIMITY = "Proximity";
public static final String EXECUTION_PLAN_TYPE_STATIONARY = "Stationery"; public static final String ALERT_TYPE_STATIONARY = "Stationery";
public static final String EXECUTION_PLAN_TYPE_TRAFFIC = "Traffic"; public static final String ALERT_TYPE_TRAFFIC = "Traffic";
public static final String REGISTRY_PATH_FOR_ALERTS = "/_system/governance/geo/alerts/"; public static final String REGISTRY_PATH_FOR_ALERTS = "/_system/governance/geo/alerts/";
public static final String PROXIMITY_DISTANCE = "proximityDistance"; public static final String PROXIMITY_DISTANCE = "proximityDistance";
public static final String PROXIMITY_TIME = "proximityTime"; public static final String PROXIMITY_TIME = "proximityTime";

@ -32,13 +32,13 @@ public interface GeoService {
List<GeoFence> getExitAlerts(DeviceIdentifier identifier) throws GeoServiceException; List<GeoFence> getExitAlerts(DeviceIdentifier identifier) throws GeoServiceException;
boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String executionPlanType) boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
throws GeoServiceException; throws GeoServiceException;
boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String executionPlanType) boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
throws GeoServiceException; throws GeoServiceException;
boolean removeGeoAlert(String executionPlanType, DeviceIdentifier identifier, String queryName) boolean removeGeoAlert(String alertType, DeviceIdentifier identifier, String queryName)
throws GeoServiceException; throws GeoServiceException;
String getSpeedAlerts(DeviceIdentifier identifier) throws GeoServiceException; String getSpeedAlerts(DeviceIdentifier identifier) throws GeoServiceException;

@ -114,7 +114,7 @@ public class GeoServcieManagerImpl implements GeoService {
Registry registry = getGovernanceRegistry(); Registry registry = getGovernanceRegistry();
String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS + String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS +
GeoServices.EXECUTION_PLAN_TYPE_WITHIN + "/" + identifier.getId() + "/"; GeoServices.ALERT_TYPE_WITHIN + "/" + identifier.getId() + "/";
Resource resource; Resource resource;
try { try {
resource = registry.get(registryPath); resource = registry.get(registryPath);
@ -162,7 +162,7 @@ public class GeoServcieManagerImpl implements GeoService {
Registry registry = getGovernanceRegistry(); Registry registry = getGovernanceRegistry();
String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS + String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS +
GeoServices.EXECUTION_PLAN_TYPE_EXIT + "/" + identifier.getId() + "/"; GeoServices.ALERT_TYPE_EXIT + "/" + identifier.getId() + "/";
Resource resource; Resource resource;
try { try {
resource = registry.get(registryPath); resource = registry.get(registryPath);
@ -206,18 +206,18 @@ public class GeoServcieManagerImpl implements GeoService {
} }
@Override @Override
public boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String executionPlanType) public boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
throws GeoServiceException { throws GeoServiceException {
return saveGeoAlert(alert, identifier, executionPlanType, false); return saveGeoAlert(alert, identifier, alertType, false);
} }
@Override @Override
public boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String executionPlanType) public boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
throws GeoServiceException { 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 { throws GeoServiceException {
Type type = new TypeToken<Map<String, String>>() { Type type = new TypeToken<Map<String, String>>() {
@ -228,40 +228,40 @@ public class GeoServcieManagerImpl implements GeoService {
Map<String, String> options = new HashMap<>(); Map<String, String> options = new HashMap<>();
Object content = null; 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.QUERY_NAME, alert.getQueryName());
options.put(GeoServices.AREA_NAME, alert.getCustomName()); options.put(GeoServices.AREA_NAME, alert.getCustomName());
content = parseMap.get(GeoServices.GEO_FENCE_GEO_JSON); 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.QUERY_NAME, alert.getQueryName());
options.put(GeoServices.AREA_NAME, alert.getCustomName()); options.put(GeoServices.AREA_NAME, alert.getCustomName());
content = parseMap.get(GeoServices.GEO_FENCE_GEO_JSON); 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); 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_DISTANCE, alert.getProximityDistance());
options.put(GeoServices.PROXIMITY_TIME, alert.getProximityTime()); options.put(GeoServices.PROXIMITY_TIME, alert.getProximityTime());
content = alert.getParseData(); 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.QUERY_NAME, alert.getQueryName());
options.put(GeoServices.AREA_NAME, alert.getCustomName()); options.put(GeoServices.AREA_NAME, alert.getCustomName());
options.put(GeoServices.STATIONARY_TIME, alert.getStationeryTime()); options.put(GeoServices.STATIONARY_TIME, alert.getStationeryTime());
options.put(GeoServices.FLUCTUATION_RADIUS, alert.getFluctuationRadius()); options.put(GeoServices.FLUCTUATION_RADIUS, alert.getFluctuationRadius());
content = alert.getParseData(); 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); content = parseMap.get(GeoServices.GEO_FENCE_GEO_JSON);
} else { } else {
throw new GeoServiceException( 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 //persist alert in registry
updateRegistry(getRegistryPath(executionPlanType, identifier, alert.getQueryName()), identifier, content, updateRegistry(getRegistryPath(alertType, identifier, alert.getQueryName()), identifier, content,
options); options);
//deploy alert into event processor //deploy alert into event processor
@ -269,11 +269,11 @@ public class GeoServcieManagerImpl implements GeoService {
String action = (isUpdate ? "updating" : "creating"); String action = (isUpdate ? "updating" : "creating");
try { try {
eventprocessorStub = getEventProcessorAdminServiceStub(); eventprocessorStub = getEventProcessorAdminServiceStub();
String parsedTemplate = parseTemplate(executionPlanType, parseMap); String parsedTemplate = parseTemplate(alertType, parseMap);
String validationResponse = eventprocessorStub.validateExecutionPlan(parsedTemplate); String validationResponse = eventprocessorStub.validateExecutionPlan(parsedTemplate);
if (validationResponse.equals("success")) { if (validationResponse.equals("success")) {
if (isUpdate) { if (isUpdate) {
String executionPlanName = getExecutionPlanName(executionPlanType, alert.getQueryName(), String executionPlanName = getExecutionPlanName(alertType, alert.getQueryName(),
identifier.getId()); identifier.getId());
eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName); eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName);
} else { } else {
@ -289,68 +289,71 @@ public class GeoServcieManagerImpl implements GeoService {
log.error("Execution plan validation failed: " + validationResponse); log.error("Execution plan validation failed: " + validationResponse);
} }
throw new GeoServiceException( 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()); identifier.getType() + " with id: " + identifier.getId());
} }
return true; return true;
} catch (AxisFault axisFault) { } catch (AxisFault axisFault) {
throw new GeoServiceException( throw new GeoServiceException(
"Event processor admin service initialization failed while " + action + " geo alert '" + "Event processor admin service initialization failed while " + action + " geo alert '" +
executionPlanType + "' for " + identifier.getType() + " " + alertType + "' for " + identifier.getType() + " " +
"device with id: " + identifier.getId(), axisFault "device with id: " + identifier.getId(), axisFault
); );
} catch (IOException e) { } catch (IOException e) {
throw new GeoServiceException( throw new GeoServiceException(
"Event processor admin service failed while " + action + " geo alert '" + "Event processor admin service failed while " + action + " geo alert '" +
executionPlanType + "' for " + identifier.getType() + " " + alertType + "' for " + identifier.getType() + " " +
"device with id: " + identifier.getId(), e); "device with id: " + identifier.getId(), e);
} catch (JWTClientException e) { } catch (JWTClientException e) {
throw new GeoServiceException( 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); identifier.getType() + " device with id:" + identifier.getId(), e);
} finally { } finally {
cleanup(eventprocessorStub); cleanup(eventprocessorStub);
} }
} }
private String getRegistryPath(String executionPlanType, DeviceIdentifier identifier, String queryName) private String getRegistryPath(String alertType, DeviceIdentifier identifier, String queryName)
throws GeoServiceException { throws GeoServiceException {
String path = ""; String path = "";
if (GeoServices.EXECUTION_PLAN_TYPE_WITHIN.equals(executionPlanType)) { if (GeoServices.ALERT_TYPE_WITHIN.equals(alertType)) {
path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.EXECUTION_PLAN_TYPE_WITHIN + path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_WITHIN +
"/" + identifier.getId() + "/" + queryName; "/" + identifier.getId() + "/" + queryName;
} else if (GeoServices.EXECUTION_PLAN_TYPE_SPEED.equals(executionPlanType)) { } else if (GeoServices.ALERT_TYPE_EXIT.equals(alertType)) {
path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.EXECUTION_PLAN_TYPE_SPEED + 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(); "/" + identifier.getId();
} else if (GeoServices.EXECUTION_PLAN_TYPE_PROXIMITY.equals(executionPlanType)) { } else if (GeoServices.ALERT_TYPE_PROXIMITY.equals(alertType)) {
path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.EXECUTION_PLAN_TYPE_PROXIMITY + path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_PROXIMITY +
"/" + identifier.getId() + "/" + queryName; "/" + identifier.getId() + "/" + queryName;
} else if (GeoServices.EXECUTION_PLAN_TYPE_STATIONARY.equals(executionPlanType)) { } else if (GeoServices.ALERT_TYPE_STATIONARY.equals(alertType)) {
path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.EXECUTION_PLAN_TYPE_STATIONARY + path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_STATIONARY +
"/" + identifier.getId() + "/" + queryName; "/" + identifier.getId() + "/" + queryName;
} else if (GeoServices.EXECUTION_PLAN_TYPE_TRAFFIC.equals(executionPlanType)) { } else if (GeoServices.ALERT_TYPE_TRAFFIC.equals(alertType)) {
path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.EXECUTION_PLAN_TYPE_TRAFFIC + path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_TRAFFIC +
"/" + identifier.getId() + "/" + queryName; "/" + identifier.getId() + "/" + queryName;
} else { } else {
throw new GeoServiceException( throw new GeoServiceException(
"Unrecognized execution plan type: " + executionPlanType); "Unrecognized execution plan type: " + alertType);
} }
return path; return path;
} }
private String getExecutionPlanName(String executionPlanType, String queryName, String deviceId) { private String getExecutionPlanName(String alertType, String queryName, String deviceId) {
if ("Traffic".equals(executionPlanType)) { if ("Traffic".equals(alertType)) {
return "Geo-ExecutionPlan-Traffic_" + queryName + "_alert"; return "Geo-ExecutionPlan-Traffic_" + queryName + "_alert";
} else { } else {
return "Geo-ExecutionPlan-" + executionPlanType + "_" + queryName + "---_" + deviceId + "_alert"; return "Geo-ExecutionPlan-" + alertType + "_" + queryName + "---_" + deviceId + "_alert";
} }
} }
@Override @Override
public boolean removeGeoAlert(String executionPlanType, DeviceIdentifier identifier, String queryName) public boolean removeGeoAlert(String alertType, DeviceIdentifier identifier, String queryName)
throws GeoServiceException { throws GeoServiceException {
removeFromRegistry(executionPlanType, identifier, queryName); removeFromRegistry(alertType, identifier, queryName);
String executionPlanName = getExecutionPlanName(executionPlanType, queryName, identifier.getId()); String executionPlanName = getExecutionPlanName(alertType, queryName, identifier.getId());
EventProcessorAdminServiceStub eventprocessorStub = null; EventProcessorAdminServiceStub eventprocessorStub = null;
try { try {
eventprocessorStub = getEventProcessorAdminServiceStub(); eventprocessorStub = getEventProcessorAdminServiceStub();
@ -359,13 +362,13 @@ public class GeoServcieManagerImpl implements GeoService {
} catch (IOException e) { } catch (IOException e) {
throw new GeoServiceException( throw new GeoServiceException(
"Event processor admin service stub invocation failed while removing geo alert '" + "Event processor admin service stub invocation failed while removing geo alert '" +
executionPlanType + alertType +
"': " + executionPlanName + " for " + "': " + executionPlanName + " for " +
identifier.getType() + " device with id:" + identifier.getId(), e identifier.getType() + " device with id:" + identifier.getId(), e
); );
} catch (JWTClientException e) { } catch (JWTClientException e) {
throw new GeoServiceException( throw new GeoServiceException(
"JWT token creation failed while removing geo alert '" + executionPlanType + "': " + "JWT token creation failed while removing geo alert '" + alertType + "': " +
executionPlanName + " for " + executionPlanName + " for " +
identifier.getType() + " device with id:" + identifier.getId(), e 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 { throws GeoServiceException {
String path = "unknown"; String path = "unknown";
try { try {
path = getRegistryPath(executionPlanType, identifier, queryName); path = getRegistryPath(alertType, identifier, queryName);
getGovernanceRegistry().delete(path); getGovernanceRegistry().delete(path);
} catch (RegistryException e) { } catch (RegistryException e) {
throw new GeoServiceException( 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); " device with id:" + identifier.getId() + " from the path: " + path);
} }
} }
@ -438,7 +441,7 @@ public class GeoServcieManagerImpl implements GeoService {
try { try {
Registry registry = getGovernanceRegistry(); Registry registry = getGovernanceRegistry();
Resource resource = registry.get(GeoServices.REGISTRY_PATH_FOR_ALERTS + 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) { if (resource == null) {
return "{'content': false}"; return "{'content': false}";
} }
@ -456,7 +459,7 @@ public class GeoServcieManagerImpl implements GeoService {
try { try {
Registry registry = getGovernanceRegistry(); Registry registry = getGovernanceRegistry();
Resource resource = registry.get(GeoServices.REGISTRY_PATH_FOR_ALERTS + Resource resource = registry.get(GeoServices.REGISTRY_PATH_FOR_ALERTS +
GeoServices.EXECUTION_PLAN_TYPE_PROXIMITY GeoServices.ALERT_TYPE_PROXIMITY
+ "/" + identifier.getId()); + "/" + identifier.getId());
if (resource != null) { if (resource != null) {
Properties props = resource.getProperties(); Properties props = resource.getProperties();
@ -480,7 +483,7 @@ public class GeoServcieManagerImpl implements GeoService {
Registry registry = getGovernanceRegistry(); Registry registry = getGovernanceRegistry();
String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS + String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS +
GeoServices.EXECUTION_PLAN_TYPE_STATIONARY + "/" + identifier.getId() + "/"; GeoServices.ALERT_TYPE_STATIONARY + "/" + identifier.getId() + "/";
Resource resource; Resource resource;
try { try {
resource = registry.get(registryPath); resource = registry.get(registryPath);
@ -531,7 +534,7 @@ public class GeoServcieManagerImpl implements GeoService {
public List<GeoFence> getTrafficAlerts(DeviceIdentifier identifier) throws GeoServiceException { public List<GeoFence> getTrafficAlerts(DeviceIdentifier identifier) throws GeoServiceException {
Registry registry = getGovernanceRegistry(); Registry registry = getGovernanceRegistry();
String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS + String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS +
GeoServices.EXECUTION_PLAN_TYPE_STATIONARY + "/" + identifier.getId() + "/"; GeoServices.ALERT_TYPE_STATIONARY + "/" + identifier.getId() + "/";
Resource resource; Resource resource;
try { try {
resource = registry.get(registryPath); resource = registry.get(registryPath);
@ -587,8 +590,8 @@ public class GeoServcieManagerImpl implements GeoService {
} }
} }
private String parseTemplate(String executionPlan, Map<String, String> parseMap) throws GeoServiceException { private String parseTemplate(String alertType, Map<String, String> parseMap) throws GeoServiceException {
String templatePath = "alerts/Geo-ExecutionPlan-" + executionPlan + "_alert.siddhiql"; String templatePath = "alerts/Geo-ExecutionPlan-" + alertType + "_alert.siddhiql";
InputStream resource = getClass().getClassLoader().getResourceAsStream(templatePath); InputStream resource = getClass().getClassLoader().getResourceAsStream(templatePath);
if (resource == null) { if (resource == null) {
throw new GeoServiceException("Could not find template in path : " + templatePath); throw new GeoServiceException("Could not find template in path : " + templatePath);

Loading…
Cancel
Save