@ -192,11 +192,6 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
@Produces ( "application/json" )
@Produces ( "application/json" )
public Response createGeoAlertsForGeoClusters ( Alert alert , @PathParam ( "alertType" ) String alertType ) {
public Response createGeoAlertsForGeoClusters ( Alert alert , @PathParam ( "alertType" ) String alertType ) {
try {
try {
// this is the user who initiates the request
String authorizedUser = MultitenantUtils . getTenantAwareUsername (
CarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( )
) ;
GeoLocationProviderService geoService = DeviceMgtAPIUtils . getGeoService ( ) ;
GeoLocationProviderService geoService = DeviceMgtAPIUtils . getGeoService ( ) ;
geoService . createGeoAlert ( alert , alertType ) ;
geoService . createGeoAlert ( alert , alertType ) ;
return Response . ok ( ) . build ( ) ;
return Response . ok ( ) . build ( ) ;
@ -255,11 +250,6 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
@Produces ( "application/json" )
@Produces ( "application/json" )
public Response updateGeoAlertsForGeoClusters ( Alert alert , @PathParam ( "alertType" ) String alertType ) {
public Response updateGeoAlertsForGeoClusters ( Alert alert , @PathParam ( "alertType" ) String alertType ) {
try {
try {
// this is the user who initiates the request
String authorizedUser = MultitenantUtils . getTenantAwareUsername (
CarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( )
) ;
GeoLocationProviderService geoService = DeviceMgtAPIUtils . getGeoService ( ) ;
GeoLocationProviderService geoService = DeviceMgtAPIUtils . getGeoService ( ) ;
geoService . updateGeoAlert ( alert , alertType ) ;
geoService . updateGeoAlert ( alert , alertType ) ;
return Response . ok ( ) . build ( ) ;
return Response . ok ( ) . build ( ) ;
@ -314,11 +304,6 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
@Produces ( "application/json" )
@Produces ( "application/json" )
public Response removeGeoAlertsForGeoClusters ( @PathParam ( "alertType" ) String alertType , @QueryParam ( "queryName" ) String queryName ) {
public Response removeGeoAlertsForGeoClusters ( @PathParam ( "alertType" ) String alertType , @QueryParam ( "queryName" ) String queryName ) {
try {
try {
// this is the user who initiates the request
String authorizedUser = MultitenantUtils . getTenantAwareUsername (
CarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( )
) ;
GeoLocationProviderService geoService = DeviceMgtAPIUtils . getGeoService ( ) ;
GeoLocationProviderService geoService = DeviceMgtAPIUtils . getGeoService ( ) ;
geoService . removeGeoAlert ( alertType , queryName ) ;
geoService . removeGeoAlert ( alertType , queryName ) ;
return Response . ok ( ) . build ( ) ;
return Response . ok ( ) . build ( ) ;
@ -387,34 +372,34 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
@Produces ( "application/json" )
@Produces ( "application/json" )
public Response getGeoAlertsForGeoClusters ( @PathParam ( "alertType" ) String alertType ) {
public Response getGeoAlertsForGeoClusters ( @PathParam ( "alertType" ) String alertType ) {
try {
try {
// this is the user who initiates the request
String authorizedUser = MultitenantUtils . getTenantAwareUsername (
CarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( )
) ;
GeoLocationProviderService geoService = DeviceMgtAPIUtils . getGeoService ( ) ;
GeoLocationProviderService geoService = DeviceMgtAPIUtils . getGeoService ( ) ;
List < GeoFence > alerts = null ;
if ( GeoServices . ALERT_TYPE_WITHIN . equals ( alertType ) ) {
String result = null ;
List < GeoFence > alerts = geoService . getWithinAlerts ( ) ;
return Response . ok ( ) . entity ( alerts ) . build ( ) ;
switch ( alertType ) {
} else if ( GeoServices . ALERT_TYPE_EXIT . equals ( alertType ) ) {
case GeoServices . ALERT_TYPE_WITHIN :
List < GeoFence > alerts = geoService . getExitAlerts ( ) ;
alerts = geoService . getWithinAlerts ( ) ;
return Response . ok ( ) . entity ( alerts ) . build ( ) ;
break ;
} else if ( GeoServices . ALERT_TYPE_SPEED . equals ( alertType ) ) {
case GeoServices . ALERT_TYPE_EXIT :
String result = geoService . getSpeedAlerts ( ) ;
alerts = geoService . getExitAlerts ( ) ;
return Response . ok ( ) . entity ( result ) . build ( ) ;
break ;
} else if ( GeoServices . ALERT_TYPE_PROXIMITY . equals ( alertType ) ) {
case GeoServices . ALERT_TYPE_STATIONARY :
String result = geoService . getProximityAlerts ( ) ;
alerts = geoService . getStationaryAlerts ( ) ;
return Response . ok ( ) . entity ( result ) . build ( ) ;
break ;
} else if ( GeoServices . ALERT_TYPE_STATIONARY . equals ( alertType ) ) {
case GeoServices . ALERT_TYPE_TRAFFIC :
List < GeoFence > alerts = geoService . getStationaryAlerts ( ) ;
alerts = geoService . getTrafficAlerts ( ) ;
return Response . ok ( ) . entity ( alerts ) . build ( ) ;
break ;
} else if ( GeoServices . ALERT_TYPE_TRAFFIC . equals ( alertType ) ) {
case GeoServices . ALERT_TYPE_SPEED :
List < GeoFence > alerts = geoService . getTrafficAlerts ( ) ;
result = geoService . getSpeedAlerts ( ) ;
return Response . ok ( ) . entity ( alerts ) . build ( ) ;
return Response . ok ( ) . entity ( result ) . build ( ) ;
case GeoServices . ALERT_TYPE_PROXIMITY :
result = geoService . getProximityAlerts ( ) ;
return Response . ok ( ) . entity ( result ) . build ( ) ;
default :
throw new GeoLocationBasedServiceException ( "Invalid Alert Type" ) ;
}
}
return null ;
return Response . ok ( ) . entity ( alerts ) . build ( ) ;
} catch ( GeoLocationBasedServiceException e ) {
} catch ( GeoLocationBasedServiceException e ) {
String error = "Error occurred while getting the geo alerts for " + alertType + " alert" ;
String error = "Error occurred while getting the geo alerts for " + alertType + " alert" ;
log . error ( error , e ) ;
log . error ( error , e ) ;
@ -493,25 +478,21 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
String authorizedUser = MultitenantUtils . getTenantAwareUsername (
String authorizedUser = MultitenantUtils . getTenantAwareUsername (
CarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ) ;
CarbonContext . getThreadLocalCarbonContext ( ) . getUsername ( ) ) ;
try {
String tenantDomain = MultitenantUtils . getTenantDomain ( authorizedUser ) ;
String tenantDomain = MultitenantUtils . getTenantDomain ( authorizedUser ) ;
int tenantId = DeviceMgtAPIUtils . getRealmService ( ) . getTenantManager ( ) . getTenantId ( tenantDomain ) ;
int tenantId = DeviceMgtAPIUtils . getRealmService ( ) . getTenantManager ( ) . getTenantId ( tenantDomain ) ;
AnalyticsDataAPI analyticsDataAPI = DeviceMgtAPIUtils . getAnalyticsDataAPI ( ) ;
AnalyticsDataAPI analyticsDataAPI = DeviceMgtAPIUtils . getAnalyticsDataAPI ( ) ;
List < SearchResultEntry > searchResults = analyticsDataAPI . search ( tenantId , tableName , query ,
List < SearchResultEntry > searchResults = analyticsDataAPI . search ( tenantId , tableName , query ,
0 ,
0 ,
100 ,
100 ,
sortByFields ) ;
sortByFields ) ;
List < Event > events = getEventBeans ( analyticsDataAPI , tenantId , tableName , new ArrayList < String > ( ) ,
List < Event > events = getEventBeans ( analyticsDataAPI , tenantId , tableName , new ArrayList < String > ( ) ,
searchResults ) ;
searchResults ) ;
return Response . ok ( ) . entity ( events ) . build ( ) ;
return Response . ok ( ) . entity ( events ) . build ( ) ;
} catch ( AnalyticsException | UserStoreException e ) {
} catch ( AnalyticsException | UserStoreException e ) {
log . error ( "Failed to perform search on table: " + tableName + " : " + e . getMessage ( ) , e ) ;
log . error ( "Failed to perform search on table: " + tableName + " : " + e . getMessage ( ) , e ) ;
throw DeviceMgtUtil . buildBadRequestException (
throw DeviceMgtUtil . buildBadRequestException (
Constants . ErrorMessages . STATUS_BAD_REQUEST_MESSAGE_DEFAULT ) ;
Constants . ErrorMessages . STATUS_BAD_REQUEST_MESSAGE_DEFAULT ) ;
}
} catch ( Exception e ) {
log . error ( e . getMessage ( ) ) ;
return Response . status ( Response . Status . INTERNAL_SERVER_ERROR . getStatusCode ( ) ) . build ( ) ;
}
}
}
}