Exemplo n.º 1
0
def field_classify(request, source_id):
    """ Classifies one or more fields with posted data """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        if request.method == 'POST':
            ip = ImportProfile(source_id)
            if ip.project_uuid is not False:
                ifd = ImportFieldDescribe(source_id)
                if 'field_type' in request.POST and 'field_num' in request.POST:
                    ifd.update_field_type(request.POST['field_type'],
                                          request.POST['field_num'])
                elif 'field_data_type' in request.POST and 'field_num' in request.POST:
                    ifd.update_field_data_type(request.POST['field_data_type'],
                                               request.POST['field_num'])
                ip.get_fields(ifd.field_num_list)
                json_output = json.dumps(ip.jsonify_fields(),
                                         indent=4,
                                         ensure_ascii=False)
                return HttpResponse(json_output,
                                    content_type='application/json; charset=utf8')
            else:
                raise Http404
        else:
            return HttpResponseForbidden
Exemplo n.º 2
0
def field_classify(request, source_id):
    """ Classifies one or more fields with posted data """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        if request.method == 'POST':
            ip = ImportProfile(source_id)
            if ip.project_uuid is not False:
                ifd = ImportFieldDescribe(source_id)
                ifd.project_uuid = ip.project_uuid
                if 'field_type' in request.POST and 'field_num' in request.POST:
                    ifd.update_field_type(request.POST['field_type'],
                                          request.POST['field_num'])
                elif 'field_data_type' in request.POST and 'field_num' in request.POST:
                    ifd.update_field_data_type(request.POST['field_data_type'],
                                               request.POST['field_num'])
                elif 'match_all_unclasified' in request.POST:
                    ifd.match_all_unclassified()
                ip.get_fields(ifd.field_num_list)
                json_output = json.dumps(ip.jsonify_fields(),
                                         indent=4,
                                         ensure_ascii=False)
                return HttpResponse(json_output,
                                    content_type='application/json; charset=utf8')
            else:
                raise Http404
        else:
            return HttpResponseForbidden
Exemplo n.º 3
0
def field_meta_update(request, source_id):
    """ Classifies one or more fields with posted data """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        if request.method == 'POST':
            ip = ImportProfile(source_id)
            if ip.project_uuid is not False:
                ifd = ImportFieldDescribe(source_id)
                if 'label' in request.POST and 'field_num' in request.POST:
                    ifd.update_field_label(request.POST['label'],
                                           request.POST['field_num'])
                elif 'value_prefix' in request.POST and 'field_num' in request.POST:
                    ifd.update_field_value_prefix(request.POST['value_prefix'],
                                                  request.POST['field_num'])
                elif 'field_value_cat' in request.POST and 'field_num' in request.POST:
                    ifd.update_field_value_cat(request.POST['field_value_cat'],
                                               request.POST['field_num'])
                ip.get_subject_type_fields()
                json_output = json.dumps(ip.jsonify_fields(),
                                         indent=4,
                                         ensure_ascii=False)
                return HttpResponse(
                    json_output, content_type='application/json; charset=utf8')
            else:
                raise Http404
        else:
            return HttpResponseForbidden
Exemplo n.º 4
0
def delete(request, source_id, annotation_id):
    """ Returns JSON data for an identifier in its hierarchy """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        if request.method == 'POST':
            ip = ImportProfile(source_id)
            if ip.project_uuid is not False:
                ifd = ImportFieldDescribe(source_id)
                ifd.delete_field_annotation(annotation_id)
                ip.get_field_annotations()
                anno_list = ip.jsonify_field_annotations()
                json_output = json.dumps(anno_list,
                                         indent=4,
                                         ensure_ascii=False)
                return HttpResponse(json_output,
                                    content_type='application/json; charset=utf8')
            else:
                raise Http404
        else:
            return HttpResponseForbidden
Exemplo n.º 5
0
def delete(request, source_id, annotation_id):
    """ Returns JSON data for an identifier in its hierarchy """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        if request.method == 'POST':
            ip = ImportProfile(source_id)
            if ip.project_uuid is not False:
                ifd = ImportFieldDescribe(source_id)
                ifd.delete_field_annotation(annotation_id)
                ip.get_field_annotations()
                anno_list = ip.jsonify_field_annotations()
                json_output = json.dumps(anno_list,
                                         indent=4,
                                         ensure_ascii=False)
                return HttpResponse(
                    json_output, content_type='application/json; charset=utf8')
            else:
                raise Http404
        else:
            return HttpResponseForbidden
Exemplo n.º 6
0
def create(request, source_id):
    """ Classifies one or more fields with posted data """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        if request.method == 'POST':
            ip = ImportProfile(source_id)
            if ip.project_uuid is not False:
                ifd = ImportFieldDescribe(source_id)
                ifd.project_uuid = ip.project_uuid
                if request.POST['predicate'] == Assertion.PREDICATES_CONTAINS:
                    ifd.update_field_contains(request.POST['field_num'],
                                              request.POST['object_field_num'])
                elif request.POST['predicate'] == ImportFieldAnnotation.PRED_CONTAINED_IN:
                    ifd.update_field_containedin_entity(request.POST['field_num'],
                                                        request.POST['object_uuid'])
                elif request.POST['predicate'] == ImportFieldAnnotation.PRED_MEDIA_PART_OF:
                    ifd.update_field_media_part_of_entity(request.POST['field_num'],
                                                          request.POST['object_field_num'])
                elif request.POST['predicate'] == Assertion.PREDICATES_LINK:
                    if 'object_field_num' in request.POST:
                        ifd.update_field_links(request.POST['field_num'],
                                               request.POST['object_field_num'])
                elif request.POST['predicate'] == ImportFieldAnnotation.PRED_DESCRIBES:
                    if 'object_field_num' in request.POST:
                        ifd.update_desciption(request.POST['field_num'],
                                              request.POST['object_field_num'])
                elif request.POST['predicate'] == ImportFieldAnnotation.PRED_VALUE_OF:
                    if 'object_field_num' in request.POST:
                        ifd.update_variable_value(request.POST['field_num'],
                                                  request.POST['object_field_num'])
                else:
                    if request.POST['predicate'] == '-1':
                        # the predicate is not yet reconciled
                        predicate_id = ifd.make_or_reconcile_link_predicate(request.POST['predicate_label'],
                                                                            ifd.project_uuid)
                    else:
                        predicate_id = request.POST['predicate']
                    ifd.update_field_custom_predicate(request.POST['field_num'],
                                                      request.POST['object_field_num'],
                                                      predicate_id,
                                                      request.POST['predicate_type'])
                ip.get_field_annotations()
                anno_list = ip.jsonify_field_annotations()
                json_output = json.dumps(anno_list,
                                         indent=4,
                                         ensure_ascii=False)
                return HttpResponse(json_output,
                                    content_type='application/json; charset=utf8')
            else:
                raise Http404
        else:
            return HttpResponseForbidden
Exemplo n.º 7
0
def create(request, source_id):
    """ Classifies one or more fields with posted data """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        if request.method == 'POST':
            ip = ImportProfile(source_id)
            if ip.project_uuid is not False:
                predicate_field_num = None
                ifd = ImportFieldDescribe(source_id)
                ifd.project_uuid = ip.project_uuid
                if 'predicate_field_num' in request.POST:
                    try:
                        predicate_field_num = int(
                            float(request.POST['predicate_field_num']))
                    except:
                        predicate_field_num = None
                if request.POST['predicate'] == Assertion.PREDICATES_CONTAINS:
                    ifd.update_field_contains(request.POST['field_num'],
                                              request.POST['object_field_num'])
                elif request.POST[
                        'predicate'] == ImportFieldAnnotation.PRED_CONTAINED_IN:
                    ifd.update_field_containedin_entity(
                        request.POST['field_num'], request.POST['object_uuid'])
                elif request.POST[
                        'predicate'] == ImportFieldAnnotation.PRED_DRAFT_CONTAINS:
                    ifd.update_field_contains(
                        request.POST['field_num'],
                        request.POST['object_field_num'],
                        ImportFieldAnnotation.PRED_DRAFT_CONTAINS)
                elif request.POST[
                        'predicate'] == ImportFieldAnnotation.PRED_MEDIA_PART_OF:
                    ifd.update_field_media_part_of_entity(
                        request.POST['field_num'],
                        request.POST['object_field_num'])
                elif request.POST[
                        'predicate'] == ImportFieldAnnotation.PRED_DOC_Text:
                    ifd.update_field_document_text_entity(
                        request.POST['field_num'],
                        request.POST['object_field_num'])
                elif request.POST['predicate'] == Assertion.PREDICATES_LINK:
                    if 'object_field_num' in request.POST:
                        ifd.update_field_links(
                            request.POST['field_num'],
                            request.POST['object_field_num'])
                elif request.POST[
                        'predicate'] == ImportFieldAnnotation.PRED_DESCRIBES:
                    if 'object_field_num' in request.POST:
                        ifd.update_description(
                            request.POST['field_num'],
                            request.POST['object_field_num'])
                elif request.POST[
                        'predicate'] == ImportFieldAnnotation.PRED_VALUE_OF:
                    if 'object_field_num' in request.POST:
                        ifd.update_variable_value(
                            request.POST['field_num'],
                            request.POST['object_field_num'])
                elif request.POST[
                        'predicate'] == ImportFieldAnnotation.PRED_OBS_NUM:
                    if 'object_field_num' in request.POST:
                        ifd.update_obs_num(request.POST['field_num'],
                                           request.POST['object_field_num'])
                else:
                    if predicate_field_num is None:
                        # we don't have a field chosen for a predicate relationship
                        if request.POST['predicate'] == '-1':
                            # the predicate is not yet reconciled
                            predicate_id = ifd.make_or_reconcile_link_predicate(
                                request.POST['predicate_label'],
                                ifd.project_uuid)
                        else:
                            predicate_id = request.POST['predicate']
                        ifd.update_field_custom_predicate(
                            request.POST['field_num'],
                            request.POST['object_field_num'], predicate_id,
                            request.POST['predicate_type'])
                    else:
                        # we do have a field chosen where its values determine the predicate relationship
                        ifd.update_field_predicate_infield(
                            request.POST['field_num'],
                            request.POST['object_field_num'],
                            predicate_field_num)
                ip.get_field_annotations()
                anno_list = ip.jsonify_field_annotations()
                json_output = json.dumps(anno_list,
                                         indent=4,
                                         ensure_ascii=False)
                return HttpResponse(
                    json_output, content_type='application/json; charset=utf8')
            else:
                raise Http404
        else:
            return HttpResponseForbidden