Ejemplo n.º 1
0
def get_datasets(request, graph):
    response_content = []
    for neo_dataset in DatasetModel.nodes.filter(graph__exact=graph):
        dataset_object = ObjectFactory.objectDataset(neo_dataset)
        response_content.append(dataset_object.to_json())
    response = HttpResponse(json.dumps(response_content),
                            content_type='application/json')
    response['Access-Control-Allow-Origin'] = '*'
    return response
Ejemplo n.º 2
0
def get_dataset_by_hash(request, hashed_uri):
    try:
        neo_dataset = DatasetModel.nodes.get(hashed_uri=hashed_uri)
        dataset_object = ObjectFactory.objectDataset(neo_dataset)
        response = HttpResponse(json.dumps(dataset_object.to_json()),
                                content_type='application/json')
    except DoesNotExist:
        response = HttpResponse(
            "{}",
            content_type='application/json',
            status=404,
        )
    response['Access-Control-Allow-Origin'] = '*'
    return response
Ejemplo n.º 3
0
def get_datasets_of_licenses(request, hashed_sets):
    try:
        neo_license = LicenseModel.nodes.get(hashed_sets=hashed_sets)
        license_datasets = []
        for dataset in neo_license.datasets.all():
            dataset_object = ObjectFactory.objectDataset(dataset)
            license_datasets.append(dataset_object.to_json())
        response = HttpResponse(json.dumps(license_datasets),
                                content_type='application/json')
    except DoesNotExist:
        response = HttpResponse(
            "[]",
            content_type='application/json',
            status=404,
        )
    response['Access-Control-Allow-Origin'] = '*'
    return response
Ejemplo n.º 4
0
def get_graph(request):
    nodes = []
    links = []
    for neo_license in LicenseModel.nodes:
        license_object = ObjectFactory.objectLicense(neo_license)
        nodes.append(D3jsData.license_node(license_object))
        for neo_dataset in neo_license.datasets.all():
            dataset_object = ObjectFactory.objectDataset(neo_dataset)
            nodes.append(D3jsData.dataset_node(dataset_object))
            links.append(D3jsData.dataset_link(license_object, dataset_object))
        for compatible_neo_license in neo_license.followings.all():
            compatible_license_object = ObjectFactory.objectLicense(
                compatible_neo_license)
            links.append(
                D3jsData.compatible_link(license_object,
                                         compatible_license_object))
    response = HttpResponse(json.dumps(D3jsData.graph(nodes, links)),
                            content_type='application/json')
    response['Access-Control-Allow-Origin'] = '*'
    return response
Ejemplo n.º 5
0
def add_dataset(request, graph):
    json_dataset = json.loads(request.body)
    object_dataset = Dataset()
    object_dataset.from_json(json_dataset)
    neo_dataset = NeoFactory.NeoDataset(object_dataset, graph)
    object_dataset = ObjectFactory.objectDataset(neo_dataset)
    try:
        neo_dataset.save()
        response = HttpResponse(
            json.dumps(object_dataset.to_json()),
            content_type='application/json',
            status=201,
        )
    except UniqueProperty:
        response = HttpResponse(
            json.dumps(object_dataset.to_json()),
            content_type='application/json',
            status=409,
        )
    response['Access-Control-Allow-Origin'] = '*'
    return response
Ejemplo n.º 6
0
def get_dataset_search(request, graph):
    query = request.GET.get('query', None)
    label = request.GET.get('label', None)
    descr = request.GET.get('descr', None)
    uri = request.GET.get('uri', None)
    neo_datasets = DatasetModel.nodes.filter(graph__exact=graph)
    if query:
        neo_datasets = dataset_filter_search(query, graph)
    else:
        if label:
            neo_datasets = neo_datasets.filter(label__icontains=label)
        if uri:
            neo_datasets = neo_datasets.filter(uri__icontains=uri)
        if descr:
            neo_datasets = neo_datasets.filter(description__icontains=descr)
    response_content = []
    for neo_dataset in neo_datasets:
        dataset_object = ObjectFactory.objectDataset(neo_dataset)
        response_content.append(dataset_object.to_json())
    response = HttpResponse(json.dumps(response_content),
                            content_type='application/json')
    response['Access-Control-Allow-Origin'] = '*'
    return response