Exemple #1
0
def set_geofence_alert(request):
    queryName = 'geo_within_' + request.POST[
        'queryName'] + '_alert'  # TODO: Use this name to store the query in Database or remove this completly and use the area name only
    areaName = request.POST['areaName']
    geoFenceGeoJSON = request.POST['geoFenceGeoJSON']

    alert_template = open(os.path.join(BASE_DIR, 'map_service/templates/map_service/xml/geo_within_alert.xml'))
    placeholder_pattern = re.compile(r'\$areaName')
    alert_query = placeholder_pattern.sub(areaName, alert_template.read())

    placeholder_pattern = re.compile(r'\$geoFenceGeoJSON')
    alert_query = placeholder_pattern.sub(geoFenceGeoJSON, alert_query)

    placeholder_pattern = re.compile(r'\$executionPlanName')
    alert_query = placeholder_pattern.sub(queryName, alert_query)

    evnt_proc = EventProcessor()
    evnt_proc.deployExecutionPlanConfigurationFromConfigXml(alert_query)

    return JsonResponse({'status': True})
Exemple #2
0
def set_speed_alert(request):
    speed_limit = request.POST['speedAlertValue']
    alert_template = open(os.path.join(BASE_DIR, 'map_service/templates/map_service/xml/geo_speed_alert.xml'))
    placeholder_pattern = re.compile(r'\$speedAlertValue')
    alert_query = placeholder_pattern.sub(speed_limit, alert_template.read())

    evnt_proc = EventProcessor()
    exe_plan_name = 'geo_speed_alert'
    exe_plan = evnt_proc.getActiveExecutionPlanConfiguration(exe_plan_name)
    if exe_plan:
        response = evnt_proc.editActiveExecutionPlanConfiguration(alert_query, exe_plan_name)
    else:
        response = evnt_proc.deployExecutionPlanConfigurationFromConfigXml(alert_query)

    return JsonResponse({'status': True})