mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Adding Exit Alerts feature
This commit is contained in:
parent
4f447305c9
commit
05b11a5099
@ -244,6 +244,9 @@ public class GeoServiceImpl implements GeoService {
|
||||
if (GeoServices.EXECUTION_PLAN_TYPE_WITHIN.equals(executionPlanType)) {
|
||||
List<GeoFence> alerts = geoService.getWithinAlerts(identifier);
|
||||
return Response.ok().entity(alerts).build();
|
||||
} else if (GeoServices.EXECUTION_PLAN_TYPE_EXIT.equals(executionPlanType)) {
|
||||
List<GeoFence> alerts = geoService.getExitAlerts(identifier);
|
||||
return Response.ok().entity(alerts).build();
|
||||
} else if (GeoServices.EXECUTION_PLAN_TYPE_SPEED.equals(executionPlanType)) {
|
||||
String result = geoService.getSpeedAlerts(identifier);
|
||||
return Response.ok().entity(result).build();
|
||||
|
||||
@ -101,6 +101,7 @@ public final class DeviceManagementConstants {
|
||||
|
||||
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";
|
||||
|
||||
@ -30,6 +30,8 @@ public interface GeoService {
|
||||
|
||||
List<GeoFence> getWithinAlerts(DeviceIdentifier identifier) throws GeoServiceException;
|
||||
|
||||
List<GeoFence> getExitAlerts(DeviceIdentifier identifier) throws GeoServiceException;
|
||||
|
||||
boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String executionPlanType)
|
||||
throws GeoServiceException;
|
||||
|
||||
|
||||
@ -157,6 +157,54 @@ public class GeoServcieManagerImpl implements GeoService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GeoFence> getExitAlerts(DeviceIdentifier identifier) throws GeoServiceException {
|
||||
|
||||
Registry registry = getGovernanceRegistry();
|
||||
String registryPath = GeoServices.REGISTRY_PATH_FOR_ALERTS +
|
||||
GeoServices.EXECUTION_PLAN_TYPE_EXIT + "/" + identifier.getId() + "/";
|
||||
Resource resource;
|
||||
try {
|
||||
resource = registry.get(registryPath);
|
||||
} catch (RegistryException e) {
|
||||
log.error("Error while reading the registry path: " + registryPath);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
List<GeoFence> fences = new ArrayList<>();
|
||||
if (resource != null) {
|
||||
Object contentObj = resource.getContent();
|
||||
if (contentObj instanceof String[]) {
|
||||
String[] content = (String[]) contentObj;
|
||||
for (String res : content) {
|
||||
Resource childRes = registry.get(res);
|
||||
Properties props = childRes.getProperties();
|
||||
|
||||
GeoFence geoFence = new GeoFence();
|
||||
|
||||
InputStream inputStream = childRes.getContentStream();
|
||||
StringWriter writer = new StringWriter();
|
||||
IOUtils.copy(inputStream, writer, "UTF-8");
|
||||
geoFence.setGeoJson(writer.toString());
|
||||
|
||||
List queryNameObj = (List) props.get(GeoServices.QUERY_NAME);
|
||||
geoFence.setQueryName(queryNameObj != null ? queryNameObj.get(0).toString() : null);
|
||||
List areaNameObj = (List) props.get(GeoServices.AREA_NAME);
|
||||
geoFence.setAreaName(areaNameObj != null ? areaNameObj.get(0).toString() : null);
|
||||
geoFence.setCreatedTime(childRes.getCreatedTime().getTime());
|
||||
fences.add(geoFence);
|
||||
}
|
||||
}
|
||||
}
|
||||
return fences;
|
||||
} catch (RegistryException | IOException e) {
|
||||
throw new GeoServiceException(
|
||||
"Error occurred while getting the geo alerts for " + identifier.getType() + " with id: " +
|
||||
identifier.getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String executionPlanType)
|
||||
throws GeoServiceException {
|
||||
@ -185,6 +233,11 @@ public class GeoServcieManagerImpl implements GeoService {
|
||||
options.put(GeoServices.AREA_NAME, alert.getCustomName());
|
||||
content = parseMap.get(GeoServices.GEO_FENCE_GEO_JSON);
|
||||
|
||||
} else if (GeoServices.EXECUTION_PLAN_TYPE_EXIT.equals(executionPlanType)) {
|
||||
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)) {
|
||||
content = parseMap.get(GeoServices.SPEED_ALERT_VALUE);
|
||||
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
/* Enter a unique ExecutionPlan */
|
||||
@Plan:name('$executionPlanName')
|
||||
|
||||
/* Enter a unique description for ExecutionPlan */
|
||||
-- @Plan:description('ExecutionPlan')
|
||||
|
||||
/* define streams/tables and write queries here ... */
|
||||
|
||||
@Import('org.wso2.geo.StandardSpatialEvents:1.0.0')
|
||||
define stream dataIn (id string, latitude double, longitude double, timeStamp long, type string ,speed float, heading float, eventId string);
|
||||
|
||||
@Export('org.wso2.geo.ProcessedSpatialEvents:1.0.0')
|
||||
define stream dataOut (id string, latitude double, longitude double, timeStamp long, type string ,speed float, heading float, eventId string, state string, information string);
|
||||
|
||||
from dataIn[geo:within(longitude,latitude,"$geoFenceGeoJSON")==false and id == "$deviceId"]#geodashboard:subscribe()
|
||||
select id , latitude, longitude,timeStamp, type, speed, heading ,eventId , "ALERTED" as state, "This device is outside $areaName area!!!" as information
|
||||
insert into dataOut;
|
||||
from dataIn[geo:within(longitude,latitude,"$geoFenceGeoJSON")!=false and id == "$deviceId"]
|
||||
select id , latitude, longitude,timeStamp, type, speed, heading ,eventId , "NORMAL" as state, "" as information
|
||||
insert into dataOut;
|
||||
Loading…
Reference in New Issue
Block a user