def create_event():
    body = util.remove_non_usable_characters(
        util.remove_xml_header(request.data.decode("utf-8")))
    content_type = request.content_type

    validator_factory = factory_selector.get_factory(content_type)
    validator = validator_factory.create_event_request_validator()
    validator.validate(body)

    event = Event.deserialize(content_type, body)

    #validate the authorization to create it
    if log.isEnabledFor(logging.DEBUG):
        log.debug("create_event(): location - " + str(event.location))
    authorization(event.location)

    manager = CalendarSynchronizer()
    new_event = manager.register_event(event)

    response_body = new_event.serialize(request.accept_mimetypes)

    #Notify when a new event is created
    _contextbroker = ContextBrokerNotificator()
    _contextbroker.notify_event(new_event, _contextbroker.NEW_EVENT)

    return Response(response_body,
                    status=201,
                    mimetype=request.accept_mimetypes[0][0])
Example #2
0
def create_event():
    body = util.remove_non_usable_characters(
                        util.remove_xml_header(request.data.decode("utf-8")))
    content_type = request.content_type

    validator_factory = factory_selector.get_factory(content_type)
    validator = validator_factory.create_event_request_validator()
    validator.validate(body)


    event = Event.deserialize(content_type, body)

    #validate the authorization to create it 
    if log.isEnabledFor(logging.DEBUG):
        log.debug ("create_event(): location - " + str(event.location))
    authorization(event.location)

    manager = CalendarSynchronizer()
    new_event = manager.register_event(event)
    
    response_body = new_event.serialize(request.accept_mimetypes)

    #Notify when a new event is created
    _contextbroker = ContextBrokerNotificator()
    _contextbroker.notify_event(new_event, _contextbroker.NEW_EVENT)
    
    return Response(response_body, status=201, mimetype=request.accept_mimetypes[0][0])
Example #3
0
def get_event(event_id):

    manager = CalendarSynchronizer()
    event = manager.get_event(event_id)
    if event is None:
        return Response('Not Found Event', status=404)
    
    response_body = event.serialize(request.accept_mimetypes)
    return Response(response_body, status=200, mimetype=request.accept_mimetypes[0][0])
def get_event(event_id):

    manager = CalendarSynchronizer()
    event = manager.get_event(event_id)
    if event is None:
        return Response('Not Found Event', status=404)

    response_body = event.serialize(request.accept_mimetypes)
    return Response(response_body,
                    status=200,
                    mimetype=request.accept_mimetypes[0][0])
def get_events():

    location = request.args.get('location')
    start_date = request.args.get('start')
    end_date = request.args.get('end')
    
    if log.isEnabledFor(logging.DEBUG):
        log.debug ("get_events(): args - " + str(location) + str(start_date) + str(end_date))
    calendarSynchronizer = CalendarSynchronizer()
    calendar_collection = calendarSynchronizer.get_events(location, start_date, end_date)
    response_body = calendar_collection.serialize(request.accept_mimetypes)  
    return Response(response_body, mimetype=request.accept_mimetypes[0][0]) 
def get_events():

    location = request.args.get('location')
    start_date = request.args.get('start')
    end_date = request.args.get('end')

    if log.isEnabledFor(logging.DEBUG):
        log.debug("get_events(): args - " + str(location) + str(start_date) +
                  str(end_date))

    cached_events = cache.get('events')
    if cached_events is None:
        calendar_synchronizer = CalendarSynchronizer()
        cached_events = calendar_synchronizer.get_events(
            location, start_date, end_date)
        cache.set('events', cached_events, 5 * 60)

    response_body = cached_events.serialize(request.accept_mimetypes)
    return Response(response_body, mimetype=request.accept_mimetypes[0][0])
Example #7
0
def delete_event(event_id):

    manager = CalendarSynchronizer()
    #before to remoe it, we need to collect the event to know the location, we don't want to delegate this action to the CalendarSynchronizer
    #if we didn't want to create two calls to the calendar, we will need to translate this validation to the CalendarSynchronizer
    event = manager.get_event(event_id)
    if event is None:
        return Response('Not Found Event', status=404)
    #validate the authorization to delete it
    authorization(event.location)

    status = manager.remove_event(event_id)
    if status:
        #Notify when a new event is created
        _contextbroker = ContextBrokerNotificator()
        _contextbroker.notify_event(event, _contextbroker.DELETED_EVENT)

        return Response(status=204)
    else:
        return Response('Not Found Event', status=404)
def delete_event(event_id):

    manager = CalendarSynchronizer()
    #before to remoe it, we need to collect the event to know the location, we don't want to delegate this action to the CalendarSynchronizer
    #if we didn't want to create two calls to the calendar, we will need to translate this validation to the CalendarSynchronizer
    event = manager.get_event(event_id)
    if event is None:
        return Response('Not Found Event', status=404)
    #validate the authorization to delete it
    authorization(event.location)

    status = manager.remove_event(event_id)
    if status:
        #Notify when a new event is created
        _contextbroker = ContextBrokerNotificator()
        _contextbroker.notify_event(event, _contextbroker.DELETED_EVENT)

        return Response(status=204)
    else:
        return Response('Not Found Event', status=404)
Example #9
0
def get_nodes():
    manager = CalendarSynchronizer()
    node_collection = manager.get_available_nodes()
    response_body = node_collection.serialize(request.accept_mimetypes)  
    return Response(response_body, mimetype=request.accept_mimetypes[0][0]) 
def get_nodes():
    manager = CalendarSynchronizer()
    node_collection = manager.get_available_nodes()
    response_body = node_collection.serialize(request.accept_mimetypes)
    return Response(response_body, mimetype=request.accept_mimetypes[0][0])