Exemplo n.º 1
0
def item(index, item):
    "Get information for an item"
    try:
        document = get_item(index, item)
        if request.args.get('update', False):
            update_item(index, item, document)
            link_types = get_index(index).link_types()
            for (
                    link_type, links
            ) in document['_source']['_geordi']['links']['links'].iteritems():
                if link_type != 'version':
                    for link in links:
                        subitem = "{}-{}".format(
                            link_type, link[link_types[link_type]['key']])
                        get_subitem(index,
                                    subitem,
                                    create=True,
                                    seed=copy.deepcopy(link))
        response = Response(json.dumps({
            'code': 200,
            'document': document
        }),
                            200,
                            mimetype="application/json")
    except ElasticHttpNotFoundError:
        response = Response(json.dumps({
            'code':
            404,
            'error':
            'The provided item could not be found.'
        }),
                            404,
                            mimetype="application/json")
    response.headers.add('Access-Control-Allow-Origin', '*')
    return response
Exemplo n.º 2
0
def document(index_name, item):
    if request.args.get('import', False):
        template = 'import.html'
    else:
        template = 'document.html'
    try:
        data = get_item(index_name, item)
        index = get_index(index_name)
        mapoptions = get_mapoptions(data['_source']['_geordi']['mapping'])
        subitems = {}
        link_types = index.link_types()
        code_url = index.code_url()
        matching_enabled = index.matching_enabled()
        for (link_type, links
             ) in data['_source']['_geordi']['links']['links'].iteritems():
            if link_type != 'version':
                for link in links:
                    subitem = "{}-{}".format(
                        link_type, link[link_types[link_type]['key']])
                    subitems[subitem] = get_subitem(index_name,
                                                    subitem,
                                                    create=True,
                                                    seed=copy.deepcopy(link))
        return render_template(template,
                               item=item,
                               index=index_name,
                               data=data,
                               mapping=data['_source']['_geordi']['mapping'],
                               mapoptions=mapoptions,
                               subitems=subitems,
                               code_url=code_url,
                               matching_enabled=matching_enabled)
    except ElasticHttpNotFoundError:
        return render_template('notfound.html')
Exemplo n.º 3
0
def item(index, item):
    "Get information for an item"
    try:
        document = get_item(index, item)
        if request.args.get('update', False):
            update_item(index, item, document)
            link_types = get_index(index).link_types()
            for (link_type, links) in document['_source']['_geordi']['links']['links'].iteritems():
                if link_type != 'version':
                    for link in links:
                        subitem = "{}-{}".format(link_type, link[link_types[link_type]['key']])
                        get_subitem(index, subitem, create=True, seed=copy.deepcopy(link))
        response = Response(json.dumps({'code': 200, 'document': document}), 200, mimetype="application/json")
    except ElasticHttpNotFoundError:
        response = Response(json.dumps({'code': 404, 'error': 'The provided item could not be found.'}), 404, mimetype="application/json")
    response.headers.add('Access-Control-Allow-Origin', '*')
    return response
Exemplo n.º 4
0
def subitem(index, subitem_id):
    "Get information for a subitem's matching"
    subitem = get_subitem(index, subitem_id)
    if subitem:
        if request.args.get('update', False):
            update_subitem(index, subitem_id, subitem['_source'])
        response = Response(json.dumps({'code': 200, 'document': subitem}), 200, mimetype="application/json")
    else:
        response = Response(json.dumps({'code': 404, 'error': 'The provided item could not be found.'}), 404, mimetype="application/json")
    response.headers.add('Access-Control-Allow-Origin', '*')
    return response
Exemplo n.º 5
0
def document(index_name, item):
    if request.args.get('import', False):
        template = 'import.html'
    else:
        template = 'document.html'
    try:
        data = get_item(index_name, item)
        index = get_index(index_name)
        mapoptions = get_mapoptions(data['_source']['_geordi']['mapping'])
        subitems = {}
        link_types = index.link_types()
        code_url = index.code_url()
        matching_enabled = index.matching_enabled()
        for (link_type, links) in data['_source']['_geordi']['links']['links'].iteritems():
            if link_type != 'version':
                for link in links:
                    subitem = "{}-{}".format(link_type, link[link_types[link_type]['key']])
                    subitems[subitem] = get_subitem(index_name, subitem, create=True, seed=copy.deepcopy(link))
        return render_template(template, item=item, index=index_name, data=data, mapping=data['_source']['_geordi']['mapping'], mapoptions=mapoptions, subitems=subitems, code_url=code_url, matching_enabled=matching_enabled)
    except ElasticHttpNotFoundError:
        return render_template('notfound.html')
Exemplo n.º 6
0
def subitem(index, subitem_id):
    "Get information for a subitem's matching"
    subitem = get_subitem(index, subitem_id)
    if subitem:
        if request.args.get('update', False):
            update_subitem(index, subitem_id, subitem['_source'])
        response = Response(json.dumps({
            'code': 200,
            'document': subitem
        }),
                            200,
                            mimetype="application/json")
    else:
        response = Response(json.dumps({
            'code':
            404,
            'error':
            'The provided item could not be found.'
        }),
                            404,
                            mimetype="application/json")
    response.headers.add('Access-Control-Allow-Origin', '*')
    return response