Example #1
0
def index(request, graph = 'stable'):
    '''
        Returns a tabular view of the stored annotations.
        - HTTPRequest **request** the client request
        - string **graph**  the required named graph
        TDB - In a future implemenation this actions should be supported by an OpenSearch implementation
    '''
    tmp_g = None
    try:
        tmp_g = _collect_annotations(graph)
    except StoreConnectionError as e:
        messages.add_message(request, messages.ERROR, e)
        return mm_render_to_response_error(request, '503.html', 503)
        
                
    req_format = _validateFormat(request)
    
    if req_format != 'html':
        LOGGING.debug("Annotations %s" % __serialize(tmp_g, req_format = req_format))
        return HttpResponse(__serialize(tmp_g, req_format = req_format))

    states = {}            
    LOGGING.debug("Annotations %s" % tmp_g.serialize())
    for s, p, o in tmp_g.triples((None, None, OA['Annotation'])):
        states[s] = find_annotation_graph(s)   
        
    context = {'results': tmp_g.serialize(), 'states': json.dumps(states)}
    return mm_render_to_response(request, context, 'viewer.html')
 def process_request(self, request):
     if request.method == 'OPTIONS':
         return HttpResponse(status=200)             
      
     if CharmeMiddleware.get_store() is None:
         try:
             self.__initStore()
         except AttributeError, e:
             messages.add_message(request, messages.ERROR, e)
             messages.add_message(request, messages.INFO, 'Missing configuration')
             return mm_render_to_response_error(request, '503.html', 503)
Example #3
0
def advance_status(request):
    '''
        Advance the status of an annotation
    '''            
    if isPOST(request) and 'application/json' in content_type(request):
        params = json.loads(request.body) 
        if not params.has_key('annotation') or not params.has_key('state'):
            messages.add_message(request, messages.ERROR, "Missing annotation/state parameters")
            return mm_render_to_response_error(request, '400.html', 400)
        LOGGING.info("advancing %s to state:%s" % (params.get('annotation'), params.get('toState')))
        tmp_g = change_annotation_state(params.get('annotation'), params.get('toState'))
        
        return HttpResponse(tmp_g.serialize())
Example #4
0
def insert(request):
    '''
        Inserts in the triplestore a new annotation under the "ANNO_SUBMITTED" graph
    '''
    try:
        req_format = _validateFormat(request)
        
    except SerializeError as e:
        messages.add_message(request, messages.ERROR, e)
        return mm_render_to_response_error(request, '400.html', 400)
    
    if isPOST(request) or isOPTIONS(request):
        triples = request.body
        tmp_g = insert_rdf(triples, req_format, graph=ANNO_SUBMITTED) 
        ret_format = validateMimeFormat(request)
        if ret_format is None:
            ret_format = req_format
        return HttpResponse(__serialize(tmp_g, req_format = ret_format), content_type=FORMAT_MAP.get(ret_format))