Geofencing refactoring

revert-70aa11f8
Rasika Perera 7 years ago
parent 09607fc4c2
commit 575d06f513

@ -68,15 +68,21 @@ import javax.ws.rs.core.Response;
@Scope( @Scope(
name = "View Analytics", name = "View Analytics",
description = "", description = "",
key = "perm:geo-service:analytics", key = "perm:geo-service:analytics-view",
permissions = {"/device-mgt/devices/owning-device/analytics"} permissions = {"/device-mgt/devices/owning-device/view-analytics"}
),
@Scope(
name = "Manage Alerts",
description = "",
key = "perm:geo-service:alerts-manage",
permissions = {"/device-mgt/devices/owning-device/manage-alerts"}
) )
} }
) )
@Path("/geo-services") @Path("/geo-services")
@Api(value = "Geo Service", @Api(value = "Geo Service",
description = "This carries all the resources related to the geo service functionalities.") description = "This carries all the resources related to the geo service functionalities.")
public interface GeoService { public interface GeoLocationBasedService {
/** /**
* Retrieve Analytics for the device type * Retrieve Analytics for the device type
*/ */
@ -92,7 +98,7 @@ public interface GeoService {
tags = "Geo Service Management", tags = "Geo Service Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:analytics") @ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:analytics-view")
}) })
} }
) )
@ -161,7 +167,7 @@ public interface GeoService {
tags = "Geo Service Management", tags = "Geo Service Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:analytics") @ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:alerts-manage")
}) })
} }
) )
@ -226,7 +232,7 @@ public interface GeoService {
tags = "Geo Service Management", tags = "Geo Service Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:analytics") @ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:alerts-manage")
}) })
} }
) )
@ -291,7 +297,7 @@ public interface GeoService {
tags = "Geo Service Management", tags = "Geo Service Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:analytics") @ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:alerts-manage")
}) })
} }
) )
@ -355,7 +361,7 @@ public interface GeoService {
tags = "Geo Service Management", tags = "Geo Service Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:analytics") @ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:alerts-manage")
}) })
} }
) )
@ -400,8 +406,8 @@ public interface GeoService {
String deviceType, String deviceType,
@ApiParam( @ApiParam(
name = "from", name = "from",
value = "Get stats from what time", value = "Get stats from what time",
required = true) required = true)
@QueryParam("from") long from, @QueryParam("from") long from,
@ApiParam( @ApiParam(
name = "to", name = "to",
@ -415,13 +421,13 @@ public interface GeoService {
consumes = "application/json", consumes = "application/json",
produces = "application/json", produces = "application/json",
httpMethod = "DELETE", httpMethod = "DELETE",
value = "Create Geo alerts for the device", value = "Deletes Geo alerts for the device",
notes = "", notes = "",
response = Response.class, response = Response.class,
tags = "Geo Service Management", tags = "Geo Service Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:analytics") @ExtensionProperty(name = Constants.SCOPE, value = "perm:geo-service:alerts-manage")
}) })
} }
) )

@ -35,11 +35,12 @@ import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorization
import org.wso2.carbon.device.mgt.common.geo.service.Alert; import org.wso2.carbon.device.mgt.common.geo.service.Alert;
import org.wso2.carbon.device.mgt.common.geo.service.Event; 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.GeoFence;
import org.wso2.carbon.device.mgt.common.geo.service.GeoServiceException; import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationBasedServiceException;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; 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.service.api.GeoLocationBasedService;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
@ -64,9 +65,9 @@ import java.util.Map;
/** /**
* The api for * The api for
*/ */
public class GeoServiceImpl implements GeoService { public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
private static Log log = LogFactory.getLog(GeoServiceImpl.class); private static Log log = LogFactory.getLog(GeoLocationBasedServiceImpl.class);
@Path("stats/{deviceType}/{deviceId}") @Path("stats/{deviceType}/{deviceId}")
@GET @GET
@ -149,10 +150,10 @@ public class GeoServiceImpl implements GeoService {
identifier.setId(deviceId); identifier.setId(deviceId);
identifier.setType(deviceType); identifier.setType(deviceType);
org.wso2.carbon.device.mgt.common.geo.service.GeoService geoService = DeviceMgtAPIUtils.getGeoService(); GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
geoService.createGeoAlert(alert, identifier, alertType); geoService.createGeoAlert(alert, identifier, alertType);
return Response.ok().build(); return Response.ok().build();
} catch (DeviceAccessAuthorizationException | GeoServiceException e) { } catch (DeviceAccessAuthorizationException | GeoLocationBasedServiceException 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;
log.error(error, e); log.error(error, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
@ -182,10 +183,10 @@ public class GeoServiceImpl implements GeoService {
identifier.setId(deviceId); identifier.setId(deviceId);
identifier.setType(deviceType); identifier.setType(deviceType);
org.wso2.carbon.device.mgt.common.geo.service.GeoService geoService = DeviceMgtAPIUtils.getGeoService(); GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
geoService.updateGeoAlert(alert, identifier, alertType); geoService.updateGeoAlert(alert, identifier, alertType);
return Response.ok().build(); return Response.ok().build();
} catch (DeviceAccessAuthorizationException | GeoServiceException e) { } catch (DeviceAccessAuthorizationException | GeoLocationBasedServiceException 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;
log.error(error, e); log.error(error, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
@ -216,10 +217,10 @@ public class GeoServiceImpl implements GeoService {
identifier.setId(deviceId); identifier.setId(deviceId);
identifier.setType(deviceType); identifier.setType(deviceType);
org.wso2.carbon.device.mgt.common.geo.service.GeoService geoService = DeviceMgtAPIUtils.getGeoService(); GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
geoService.removeGeoAlert(alertType, identifier, queryName); geoService.removeGeoAlert(alertType, identifier, queryName);
return Response.ok().build(); return Response.ok().build();
} catch (DeviceAccessAuthorizationException | GeoServiceException e) { } catch (DeviceAccessAuthorizationException | GeoLocationBasedServiceException 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;
log.error(error, e); log.error(error, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
@ -249,7 +250,7 @@ public class GeoServiceImpl implements GeoService {
identifier.setId(deviceId); identifier.setId(deviceId);
identifier.setType(deviceType); identifier.setType(deviceType);
org.wso2.carbon.device.mgt.common.geo.service.GeoService geoService = DeviceMgtAPIUtils.getGeoService(); GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
if (GeoServices.ALERT_TYPE_WITHIN.equals(alertType)) { if (GeoServices.ALERT_TYPE_WITHIN.equals(alertType)) {
List<GeoFence> alerts = geoService.getWithinAlerts(identifier); List<GeoFence> alerts = geoService.getWithinAlerts(identifier);
@ -271,7 +272,7 @@ public class GeoServiceImpl implements GeoService {
return Response.ok().entity(alerts).build(); return Response.ok().entity(alerts).build();
} }
return null; return null;
} catch (DeviceAccessAuthorizationException | GeoServiceException e) { } catch (DeviceAccessAuthorizationException | GeoLocationBasedServiceException e) {
String error = "Error occurred while getting the geo alerts for " + deviceType + " with id: " + deviceId; String error = "Error occurred while getting the geo alerts for " + deviceType + " with id: " + deviceId;
log.error(error, e); log.error(error, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();

@ -44,7 +44,7 @@ import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorization
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
import org.wso2.carbon.device.mgt.common.geo.service.GeoService; import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService; import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
@ -427,9 +427,10 @@ public class DeviceMgtAPIUtils {
return gadgetDataService; return gadgetDataService;
} }
public static GeoService getGeoService() { public static GeoLocationProviderService getGeoService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
GeoService geoService = (GeoService) ctx.getOSGiService(GeoService.class, null); GeoLocationProviderService
geoService = (GeoLocationProviderService) ctx.getOSGiService(GeoLocationProviderService.class, null);
if (geoService == null) { if (geoService == null) {
throw new IllegalStateException("Geo Service has not been initialized."); throw new IllegalStateException("Geo Service has not been initialized.");
} }

@ -80,7 +80,7 @@
<bean id="roleManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.RoleManagementServiceImpl"/> <bean id="roleManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.RoleManagementServiceImpl"/>
<bean id="userManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.UserManagementServiceImpl"/> <bean id="userManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.UserManagementServiceImpl"/>
<bean id="groupManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.GroupManagementServiceImpl"/> <bean id="groupManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.GroupManagementServiceImpl"/>
<bean id="geoService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.GeoServiceImpl"/> <bean id="geoService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.GeoLocationBasedServiceImpl"/>
<bean id="deviceManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.DeviceManagementAdminServiceImpl"/> <bean id="deviceManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.DeviceManagementAdminServiceImpl"/>
<bean id="applicationManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.ApplicationManagementAdminServiceImpl"/> <bean id="applicationManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.ApplicationManagementAdminServiceImpl"/>
<bean id="groupManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.GroupManagementAdminServiceImpl"/> <bean id="groupManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.GroupManagementAdminServiceImpl"/>

@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.common.geo.service;
/** /**
* Custom exception class of Geo Service related operations. * Custom exception class of Geo Service related operations.
*/ */
public class GeoServiceException extends Exception { public class GeoLocationBasedServiceException extends Exception {
private static final long serialVersionUID = -7151990041029070298L; private static final long serialVersionUID = -7151990041029070298L;
@ -34,26 +34,26 @@ public class GeoServiceException extends Exception {
this.errorMessage = errorMessage; this.errorMessage = errorMessage;
} }
public GeoServiceException(String msg, Exception nestedEx) { public GeoLocationBasedServiceException(String msg, Exception nestedEx) {
super(msg, nestedEx); super(msg, nestedEx);
setErrorMessage(msg); setErrorMessage(msg);
} }
public GeoServiceException(String message, Throwable cause) { public GeoLocationBasedServiceException(String message, Throwable cause) {
super(message, cause); super(message, cause);
setErrorMessage(message); setErrorMessage(message);
} }
public GeoServiceException(String msg) { public GeoLocationBasedServiceException(String msg) {
super(msg); super(msg);
setErrorMessage(msg); setErrorMessage(msg);
} }
public GeoServiceException() { public GeoLocationBasedServiceException() {
super(); super();
} }
public GeoServiceException(Throwable cause) { public GeoLocationBasedServiceException(Throwable cause) {
super(cause); super(cause);
} }

@ -26,26 +26,26 @@ import java.util.List;
* This represents the Geo service functionality which should be implemented by * This represents the Geo service functionality which should be implemented by
* required GeoServiceManagers. * required GeoServiceManagers.
*/ */
public interface GeoService { public interface GeoLocationProviderService {
List<GeoFence> getWithinAlerts(DeviceIdentifier identifier) throws GeoServiceException; List<GeoFence> getWithinAlerts(DeviceIdentifier identifier) throws GeoLocationBasedServiceException;
List<GeoFence> getExitAlerts(DeviceIdentifier identifier) throws GeoServiceException; List<GeoFence> getExitAlerts(DeviceIdentifier identifier) throws GeoLocationBasedServiceException;
boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType) boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
throws GeoServiceException; throws GeoLocationBasedServiceException;
boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType) boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
throws GeoServiceException; throws GeoLocationBasedServiceException;
boolean removeGeoAlert(String alertType, DeviceIdentifier identifier, String queryName) boolean removeGeoAlert(String alertType, DeviceIdentifier identifier, String queryName)
throws GeoServiceException; throws GeoLocationBasedServiceException;
String getSpeedAlerts(DeviceIdentifier identifier) throws GeoServiceException; String getSpeedAlerts(DeviceIdentifier identifier) throws GeoLocationBasedServiceException;
String getProximityAlerts(DeviceIdentifier identifier) throws GeoServiceException; String getProximityAlerts(DeviceIdentifier identifier) throws GeoLocationBasedServiceException;
List<GeoFence> getStationaryAlerts(DeviceIdentifier identifier) throws GeoServiceException; List<GeoFence> getStationaryAlerts(DeviceIdentifier identifier) throws GeoLocationBasedServiceException;
List<GeoFence> getTrafficAlerts(DeviceIdentifier identifier) throws GeoServiceException; List<GeoFence> getTrafficAlerts(DeviceIdentifier identifier) throws GeoLocationBasedServiceException;
} }

@ -39,8 +39,8 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoServices; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoServices;
import org.wso2.carbon.device.mgt.common.geo.service.Alert; import org.wso2.carbon.device.mgt.common.geo.service.Alert;
import org.wso2.carbon.device.mgt.common.geo.service.GeoFence; import org.wso2.carbon.device.mgt.common.geo.service.GeoFence;
import org.wso2.carbon.device.mgt.common.geo.service.GeoService; import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
import org.wso2.carbon.device.mgt.common.geo.service.GeoServiceException; import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationBasedServiceException;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub; import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub;
import org.wso2.carbon.identity.jwt.client.extension.JWTClient; import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
@ -78,9 +78,9 @@ import static org.wso2.carbon.device.mgt.common.DeviceManagementConstants.GeoSer
* This class will read events, set alerts, read alerts related to geo-fencing and it will * This class will read events, set alerts, read alerts related to geo-fencing and it will
* use Registry as the persistence storage. * use Registry as the persistence storage.
*/ */
public class GeoServcieManagerImpl implements GeoService { public class GeoLocationProviderServiceImpl implements GeoLocationProviderService {
private static Log log = LogFactory.getLog(GeoServcieManagerImpl.class); private static Log log = LogFactory.getLog(GeoLocationProviderServiceImpl.class);
/** /**
* required soap header for authorization * required soap header for authorization
@ -110,7 +110,7 @@ public class GeoServcieManagerImpl implements GeoService {
private static final String SSLV3 = "SSLv3"; private static final String SSLV3 = "SSLv3";
@Override @Override
public List<GeoFence> getWithinAlerts(DeviceIdentifier identifier) throws GeoServiceException { public List<GeoFence> getWithinAlerts(DeviceIdentifier identifier) throws GeoLocationBasedServiceException {
Registry registry = getGovernanceRegistry(); Registry registry = getGovernanceRegistry();
String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS + String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS +
@ -151,14 +151,14 @@ public class GeoServcieManagerImpl implements GeoService {
} }
return fences; return fences;
} catch (RegistryException | IOException e) { } catch (RegistryException | IOException e) {
throw new GeoServiceException( throw new GeoLocationBasedServiceException(
"Error occurred while getting the geo alerts for " + identifier.getType() + " with id: " + "Error occurred while getting the geo alerts for " + identifier.getType() + " with id: " +
identifier.getId(), e); identifier.getId(), e);
} }
} }
@Override @Override
public List<GeoFence> getExitAlerts(DeviceIdentifier identifier) throws GeoServiceException { public List<GeoFence> getExitAlerts(DeviceIdentifier identifier) throws GeoLocationBasedServiceException {
Registry registry = getGovernanceRegistry(); Registry registry = getGovernanceRegistry();
String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS + String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS +
@ -199,7 +199,7 @@ public class GeoServcieManagerImpl implements GeoService {
} }
return fences; return fences;
} catch (RegistryException | IOException e) { } catch (RegistryException | IOException e) {
throw new GeoServiceException( throw new GeoLocationBasedServiceException(
"Error occurred while getting the geo alerts for " + identifier.getType() + " with id: " + "Error occurred while getting the geo alerts for " + identifier.getType() + " with id: " +
identifier.getId(), e); identifier.getId(), e);
} }
@ -207,18 +207,18 @@ public class GeoServcieManagerImpl implements GeoService {
@Override @Override
public boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType) public boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
throws GeoServiceException { throws GeoLocationBasedServiceException {
return saveGeoAlert(alert, identifier, alertType, false); return saveGeoAlert(alert, identifier, alertType, false);
} }
@Override @Override
public boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType) public boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
throws GeoServiceException { throws GeoLocationBasedServiceException {
return saveGeoAlert(alert, identifier, alertType, true); return saveGeoAlert(alert, identifier, alertType, true);
} }
public boolean saveGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType, boolean isUpdate) public boolean saveGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType, boolean isUpdate)
throws GeoServiceException { throws GeoLocationBasedServiceException {
Type type = new TypeToken<Map<String, String>>() { Type type = new TypeToken<Map<String, String>>() {
}.getType(); }.getType();
@ -256,7 +256,7 @@ public class GeoServcieManagerImpl implements GeoService {
} else if (GeoServices.ALERT_TYPE_TRAFFIC.equals(alertType)) { } 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 GeoLocationBasedServiceException(
"Unrecognized execution plan type: " + alertType + " while creating geo alert"); "Unrecognized execution plan type: " + alertType + " while creating geo alert");
} }
@ -288,24 +288,24 @@ public class GeoServcieManagerImpl implements GeoService {
} else { } else {
log.error("Execution plan validation failed: " + validationResponse); log.error("Execution plan validation failed: " + validationResponse);
} }
throw new GeoServiceException( throw new GeoLocationBasedServiceException(
"Error occurred while " + action + " geo " + alertType + " 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 GeoLocationBasedServiceException(
"Event processor admin service initialization failed while " + action + " geo alert '" + "Event processor admin service initialization failed while " + action + " geo alert '" +
alertType + "' 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 GeoLocationBasedServiceException(
"Event processor admin service failed while " + action + " geo alert '" + "Event processor admin service failed while " + action + " geo alert '" +
alertType + "' 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 GeoLocationBasedServiceException(
"JWT token creation failed while " + action + " geo alert '" + alertType + "' 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 {
@ -314,7 +314,7 @@ public class GeoServcieManagerImpl implements GeoService {
} }
private String getRegistryPath(String alertType, DeviceIdentifier identifier, String queryName) private String getRegistryPath(String alertType, DeviceIdentifier identifier, String queryName)
throws GeoServiceException { throws GeoLocationBasedServiceException {
String path = ""; String path = "";
if (GeoServices.ALERT_TYPE_WITHIN.equals(alertType)) { if (GeoServices.ALERT_TYPE_WITHIN.equals(alertType)) {
path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_WITHIN + path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_TYPE_WITHIN +
@ -335,7 +335,7 @@ public class GeoServcieManagerImpl implements GeoService {
path = GeoServices.REGISTRY_PATH_FOR_ALERTS + GeoServices.ALERT_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 GeoLocationBasedServiceException(
"Unrecognized execution plan type: " + alertType); "Unrecognized execution plan type: " + alertType);
} }
return path; return path;
@ -351,7 +351,7 @@ public class GeoServcieManagerImpl implements GeoService {
@Override @Override
public boolean removeGeoAlert(String alertType, DeviceIdentifier identifier, String queryName) public boolean removeGeoAlert(String alertType, DeviceIdentifier identifier, String queryName)
throws GeoServiceException { throws GeoLocationBasedServiceException {
removeFromRegistry(alertType, identifier, queryName); removeFromRegistry(alertType, identifier, queryName);
String executionPlanName = getExecutionPlanName(alertType, queryName, identifier.getId()); String executionPlanName = getExecutionPlanName(alertType, queryName, identifier.getId());
EventProcessorAdminServiceStub eventprocessorStub = null; EventProcessorAdminServiceStub eventprocessorStub = null;
@ -360,14 +360,14 @@ public class GeoServcieManagerImpl implements GeoService {
eventprocessorStub.undeployActiveExecutionPlan(executionPlanName); eventprocessorStub.undeployActiveExecutionPlan(executionPlanName);
return true; return true;
} catch (IOException e) { } catch (IOException e) {
throw new GeoServiceException( throw new GeoLocationBasedServiceException(
"Event processor admin service stub invocation failed while removing geo alert '" + "Event processor admin service stub invocation failed while removing geo alert '" +
alertType + 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 GeoLocationBasedServiceException(
"JWT token creation failed while removing geo alert '" + alertType + "': " + "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
@ -378,13 +378,13 @@ public class GeoServcieManagerImpl implements GeoService {
} }
private void removeFromRegistry(String alertType, DeviceIdentifier identifier, String queryName) private void removeFromRegistry(String alertType, DeviceIdentifier identifier, String queryName)
throws GeoServiceException { throws GeoLocationBasedServiceException {
String path = "unknown"; String path = "unknown";
try { try {
path = getRegistryPath(alertType, identifier, queryName); path = getRegistryPath(alertType, identifier, queryName);
getGovernanceRegistry().delete(path); getGovernanceRegistry().delete(path);
} catch (RegistryException e) { } catch (RegistryException e) {
throw new GeoServiceException( throw new GeoLocationBasedServiceException(
"Error occurred while removing " + alertType + " 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);
} }
@ -437,7 +437,7 @@ public class GeoServcieManagerImpl implements GeoService {
} }
@Override @Override
public String getSpeedAlerts(DeviceIdentifier identifier) throws GeoServiceException { public String getSpeedAlerts(DeviceIdentifier identifier) throws GeoLocationBasedServiceException {
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 +
@ -455,7 +455,7 @@ public class GeoServcieManagerImpl implements GeoService {
} }
@Override @Override
public String getProximityAlerts(DeviceIdentifier identifier) throws GeoServiceException { public String getProximityAlerts(DeviceIdentifier identifier) throws GeoLocationBasedServiceException {
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 +
@ -479,7 +479,7 @@ public class GeoServcieManagerImpl implements GeoService {
} }
@Override @Override
public List<GeoFence> getStationaryAlerts(DeviceIdentifier identifier) throws GeoServiceException { public List<GeoFence> getStationaryAlerts(DeviceIdentifier identifier) throws GeoLocationBasedServiceException {
Registry registry = getGovernanceRegistry(); Registry registry = getGovernanceRegistry();
String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS + String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS +
@ -524,14 +524,14 @@ public class GeoServcieManagerImpl implements GeoService {
} }
return fences; return fences;
} catch (RegistryException | IOException e) { } catch (RegistryException | IOException e) {
throw new GeoServiceException( throw new GeoLocationBasedServiceException(
"Error occurred while getting the geo alerts for " + identifier.getType() + " with id: " + "Error occurred while getting the geo alerts for " + identifier.getType() + " with id: " +
identifier.getId(), e); identifier.getId(), e);
} }
} }
@Override @Override
public List<GeoFence> getTrafficAlerts(DeviceIdentifier identifier) throws GeoServiceException { public List<GeoFence> getTrafficAlerts(DeviceIdentifier identifier) throws GeoLocationBasedServiceException {
Registry registry = getGovernanceRegistry(); Registry registry = getGovernanceRegistry();
String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS + String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS +
GeoServices.ALERT_TYPE_STATIONARY + "/" + identifier.getId() + "/"; GeoServices.ALERT_TYPE_STATIONARY + "/" + identifier.getId() + "/";
@ -571,30 +571,31 @@ public class GeoServcieManagerImpl implements GeoService {
} }
return fences; return fences;
} catch (RegistryException | IOException e) { } catch (RegistryException | IOException e) {
throw new GeoServiceException( throw new GeoLocationBasedServiceException(
"Error occurred while getting the geo alerts for " + identifier.getType() + " with id: " + "Error occurred while getting the geo alerts for " + identifier.getType() + " with id: " +
identifier.getId(), e); identifier.getId(), e);
} }
} }
private Registry getGovernanceRegistry() throws GeoServiceException { private Registry getGovernanceRegistry() throws GeoLocationBasedServiceException {
try { try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
return DeviceManagementDataHolder.getInstance().getRegistryService() return DeviceManagementDataHolder.getInstance().getRegistryService()
.getGovernanceSystemRegistry( .getGovernanceSystemRegistry(
tenantId); tenantId);
} catch (RegistryException e) { } catch (RegistryException e) {
throw new GeoServiceException( throw new GeoLocationBasedServiceException(
"Error in retrieving governance registry instance: " + "Error in retrieving governance registry instance: " +
e.getMessage(), e); e.getMessage(), e);
} }
} }
private String parseTemplate(String alertType, Map<String, String> parseMap) throws GeoServiceException { private String parseTemplate(String alertType, Map<String, String> parseMap) throws
GeoLocationBasedServiceException {
String templatePath = "alerts/Geo-ExecutionPlan-" + alertType + "_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 GeoLocationBasedServiceException("Could not find template in path : " + templatePath);
} }
try { try {
//Read template //Read template
@ -606,13 +607,13 @@ public class GeoServcieManagerImpl implements GeoService {
} }
return template; return template;
} catch (IOException e) { } catch (IOException e) {
throw new GeoServiceException( throw new GeoLocationBasedServiceException(
"Error occurred while populating the template for the Within Alert", e); "Error occurred while populating the template for the Within Alert", e);
} }
} }
private void updateRegistry(String path, DeviceIdentifier identifier, Object content, Map<String, String> options) private void updateRegistry(String path, DeviceIdentifier identifier, Object content, Map<String, String> options)
throws GeoServiceException { throws GeoLocationBasedServiceException {
try { try {
Registry registry = getGovernanceRegistry(); Registry registry = getGovernanceRegistry();
@ -624,7 +625,7 @@ public class GeoServcieManagerImpl implements GeoService {
} }
registry.put(path, newResource); registry.put(path, newResource);
} catch (RegistryException e) { } catch (RegistryException e) {
throw new GeoServiceException( throw new GeoLocationBasedServiceException(
"Error occurred while setting the Within Alert for " + identifier.getType() + " with id: " + "Error occurred while setting the Within Alert for " + identifier.getType() + " with id: " +
identifier.getId(), e); identifier.getId(), e);
} }

@ -25,7 +25,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
import org.wso2.carbon.device.mgt.common.geo.service.GeoService; import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
@ -45,7 +45,7 @@ import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.tenant.PlatformConfigurationManagementServiceImpl; import org.wso2.carbon.device.mgt.core.config.tenant.PlatformConfigurationManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.geo.service.GeoServcieManagerImpl; import org.wso2.carbon.device.mgt.core.geo.service.GeoLocationProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImpl; import org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
@ -289,8 +289,8 @@ public class DeviceManagementServiceComponent {
deviceAccessAuthorizationService, null); deviceAccessAuthorizationService, null);
/* Registering Geo Service */ /* Registering Geo Service */
GeoService geoService = new GeoServcieManagerImpl(); GeoLocationProviderService geoService = new GeoLocationProviderServiceImpl();
bundleContext.registerService(GeoService.class.getName(), geoService, null); bundleContext.registerService(GeoLocationProviderService.class.getName(), geoService, null);
/* Registering App Management service */ /* Registering App Management service */
try { try {

@ -149,7 +149,8 @@
"perm:device-types:events:view", "perm:device-types:events:view",
"perm:admin:device-type", "perm:admin:device-type",
"perm:device:enroll", "perm:device:enroll",
"perm:geo-service:analytics" "perm:geo-service:analytics-view",
"perm:geo-service:alerts-manage"
], ],
"isOAuthEnabled": true, "isOAuthEnabled": true,
"backendRestEndpoints": { "backendRestEndpoints": {

Loading…
Cancel
Save