Ejemplo n.º 1
0
def transfer_backlog(request, ui):
    """
    AJAX endpoint to query for and return transfer backlog items.
    """
    es_client = elasticSearchFunctions.get_client()
    results = None

    # Return files which are in the backlog
    backlog_filter = {
        'bool': {
            'must': {
                'term': {
                    'status': 'backlog',
                }
            }
        }
    }
    # Omit files without UUIDs (metadata and logs directories):
    # - When the `hidemetadatalogs` param is sent from SIP arrange.
    # - Always from the appraisal tab.
    if ui == 'appraisal' or request.GET.get('hidemetadatalogs'):
        backlog_filter['bool']['must_not'] = {
            'term': {
                'fileuuid': '',
            }
        }

    # Get search parameters from request
    if 'query' not in request.GET:
        # Use backlog boolean filter as boolean query
        query = {'query': backlog_filter}
    else:
        queries, ops, fields, types = advanced_search.search_parameter_prep(
            request)

        try:
            query = advanced_search.assemble_query(
                queries,
                ops,
                fields,
                types,
                filters=[backlog_filter],
            )
        except:
            logger.exception('Error accessing index.')
            return HttpResponse('Error accessing index.')

    # perform search
    try:
        results = elasticSearchFunctions.search_all_results(
            es_client,
            body=query,
            index='transferfiles',
        )
    except:
        logger.exception('Error accessing index.')
        return HttpResponse('Error accessing index.')

    # Convert results into a more workable form
    results = elasticSearchFunctions.augment_raw_search_results(results)

    # Convert to a form JS can use:
    # [{'name': <filename>,
    #   'properties': {'not_draggable': False}},
    #  {'name': <directory name>,
    #   'properties': {'not_draggable': True, 'object count': 3, 'display_string': '3 objects'},
    #   'children': [
    #    {'name': <filename>,
    #     'properties': {'not_draggable': True}},
    #    {'name': <directory name>,
    #     'children': [...]
    #    }
    #   ]
    #  },
    # ]
    return_list = []
    directory_map = {}
    # _es_results_to_directory_tree requires that paths MUST be sorted
    results.sort(key=lambda x: x['relative_path'])
    for path in results:
        # If a path is in SIPArrange.original_path, then it shouldn't be draggable
        not_draggable = False
        if models.SIPArrange.objects.filter(
                original_path__endswith=path['relative_path']).exists():
            not_draggable = True
        if ui == 'legacy':
            _es_results_to_directory_tree(path['relative_path'],
                                          return_list,
                                          not_draggable=not_draggable)
        else:
            _es_results_to_appraisal_tab_format(path,
                                                directory_map,
                                                return_list,
                                                not_draggable=not_draggable)

    if ui == 'legacy':
        response = return_list
    else:
        response = {
            'formats': [],  # TODO populate this
            'transfers': return_list,
        }

    # return JSON response
    return helpers.json_response(response)
Ejemplo n.º 2
0
def transfer_backlog(request):
    """
    AJAX endpoint to query for and return transfer backlog items.
    """
    # Get search parameters from request
    results = None
    conn = elasticSearchFunctions.connect_and_create_index('transfers')

    if not 'query' in request.GET:
        query = elasticSearchFunctions.MATCH_ALL_QUERY
    else:
        queries, ops, fields, types = advanced_search.search_parameter_prep(request)

        try:
            query = advanced_search.assemble_query(
                queries,
                ops,
                fields,
                types,
                # Specify this as a filter, not a must_have, for performance,
                # and so that it doesn't cause the "should" queries in a
                # should-only query to be ignored.
                filters={'term': {'status': 'backlog'}},
            )
        except:
            logger.exception('Error accessing index.')
            return HttpResponse('Error accessing index.')

    # perform search
    try:
        results = elasticSearchFunctions.search_all_results(
            conn,
            body=query,
            index='transfers',
            doc_type='transferfile',
        )
    except:
        logger.exception('Error accessing index.')
        return HttpResponse('Error accessing index.')


    # Convert results into a more workable form
    results = _transfer_backlog_augment_search_results(results)

    # Convert to a form JS can use:
    # [{'name': <filename>,
    #   'properties': {'not_draggable': False}},
    #  {'name': <directory name>,
    #   'properties': {'not_draggable': True, 'object count': 3, 'display_string': '3 objects'},
    #   'children': [
    #    {'name': <filename>,
    #     'properties': {'not_draggable': True}},
    #    {'name': <directory name>,
    #     'children': [...]
    #    }
    #   ]
    #  },
    # ]
    return_list = []
    # _es_results_to_directory_tree requires that paths MUST be sorted
    results.sort(key=lambda x: x['relative_path'])
    for path in results:
        # If a path is in SIPArrange.original_path, then it shouldn't be draggable
        not_draggable = False
        if models.SIPArrange.objects.filter(
            original_path__endswith=path['relative_path']).exists():
            not_draggable = True
        _es_results_to_directory_tree(path['relative_path'], return_list, not_draggable=not_draggable)

    # retun JSON response
    return helpers.json_response(return_list)
Ejemplo n.º 3
0
def transfer_backlog(request, ui):
    """
    AJAX endpoint to query for and return transfer backlog items.
    """
    es_client = elasticSearchFunctions.get_client()
    results = None

    # Return files which are in the backlog
    backlog_filter = {"bool": {"must": {"term": {"status": "backlog"}}}}
    # Omit files without UUIDs (metadata and logs directories):
    # - When the `hidemetadatalogs` param is sent from SIP arrange.
    if request.GET.get("hidemetadatalogs"):
        backlog_filter["bool"]["must_not"] = {"term": {"fileuuid": ""}}

    # Get search parameters from request
    if "query" not in request.GET:
        # Use backlog boolean filter as boolean query
        query = {"query": backlog_filter}
    else:
        queries, ops, fields, types = advanced_search.search_parameter_prep(
            request)

        try:
            query = advanced_search.assemble_query(queries,
                                                   ops,
                                                   fields,
                                                   types,
                                                   filters=[backlog_filter])
        except:
            logger.exception("Error accessing index.")
            return HttpResponse("Error accessing index.")

    # perform search
    try:
        results = elasticSearchFunctions.search_all_results(
            es_client, body=query, index="transferfiles")
    except:
        logger.exception("Error accessing index.")
        return HttpResponse("Error accessing index.")

    # Convert results into a more workable form
    results = elasticSearchFunctions.augment_raw_search_results(results)

    # Convert to a form JS can use:
    # [{'name': <filename>,
    #   'properties': {'not_draggable': False}},
    #  {'name': <directory name>,
    #   'properties': {'not_draggable': True, 'object count': 3, 'display_string': '3 objects'},
    #   'children': [
    #    {'name': <filename>,
    #     'properties': {'not_draggable': True}},
    #    {'name': <directory name>,
    #     'children': [...]
    #    }
    #   ]
    #  },
    # ]
    return_list = []
    directory_map = {}
    # _es_results_to_directory_tree requires that paths MUST be sorted
    results.sort(key=lambda x: x["relative_path"])
    for path in results:
        # If a path is in SIPArrange.original_path, then it shouldn't be draggable
        not_draggable = False
        if models.SIPArrange.objects.filter(
                original_path__endswith=path["relative_path"]).exists():
            not_draggable = True
        if ui == "legacy":
            _es_results_to_directory_tree(path["relative_path"],
                                          return_list,
                                          not_draggable=not_draggable)
        else:
            _es_results_to_appraisal_tab_format(path,
                                                directory_map,
                                                return_list,
                                                not_draggable=not_draggable)

    if ui == "legacy":
        response = return_list
    else:
        if not request.GET.get("hidemetadatalogs"):
            # if metadata and log file are shown in the appraisal tab
            # directories should not be draggable if they contain
            # non draggable children
            adjust_non_draggable_nodes(return_list)
        response = {
            "formats": [],
            "transfers": return_list
        }  # TODO populate this

    # return JSON response
    return helpers.json_response(response)
Ejemplo n.º 4
0
def transfer_backlog(request, ui):
    """
    AJAX endpoint to query for and return transfer backlog items.
    """
    es_client = elasticSearchFunctions.get_client()

    # Get search parameters from request
    results = None

    # GET params in SIP arrange can control whether files in metadata/ and
    # logs/ are returned. Appraisal tab always hides these dirs and their files
    # (for now).
    backlog_filter = elasticSearchFunctions.BACKLOG_FILTER
    if ui == 'appraisal' or request.GET.get('hidemetadatalogs'):
        backlog_filter = elasticSearchFunctions.BACKLOG_FILTER_NO_MD_LOGS

    if 'query' not in request.GET:
        query = elasticSearchFunctions.MATCH_ALL_QUERY.copy()
        query['filter'] = backlog_filter
    else:
        queries, ops, fields, types = advanced_search.search_parameter_prep(
            request)

        try:
            query = advanced_search.assemble_query(
                es_client,
                queries,
                ops,
                fields,
                types,
                filters=backlog_filter,
            )
        except:
            logger.exception('Error accessing index.')
            return HttpResponse('Error accessing index.')

    # perform search
    try:
        results = elasticSearchFunctions.search_all_results(
            es_client,
            body=query,
            index='transfers',
            doc_type='transferfile',
        )
    except:
        logger.exception('Error accessing index.')
        return HttpResponse('Error accessing index.')

    # Convert results into a more workable form
    results = elasticSearchFunctions.augment_raw_search_results(results)

    # Convert to a form JS can use:
    # [{'name': <filename>,
    #   'properties': {'not_draggable': False}},
    #  {'name': <directory name>,
    #   'properties': {'not_draggable': True, 'object count': 3, 'display_string': '3 objects'},
    #   'children': [
    #    {'name': <filename>,
    #     'properties': {'not_draggable': True}},
    #    {'name': <directory name>,
    #     'children': [...]
    #    }
    #   ]
    #  },
    # ]
    return_list = []
    directory_map = {}
    # _es_results_to_directory_tree requires that paths MUST be sorted
    results.sort(key=lambda x: x['relative_path'])
    for path in results:
        # If a path is in SIPArrange.original_path, then it shouldn't be draggable
        not_draggable = False
        if models.SIPArrange.objects.filter(
                original_path__endswith=path['relative_path']).exists():
            not_draggable = True
        if ui == 'legacy':
            _es_results_to_directory_tree(path['relative_path'],
                                          return_list,
                                          not_draggable=not_draggable)
        else:
            _es_results_to_appraisal_tab_format(path,
                                                directory_map,
                                                return_list,
                                                not_draggable=not_draggable)

    if ui == 'legacy':
        response = return_list
    else:
        response = {
            'formats': [],  # TODO populate this
            'transfers': return_list,
        }

    # return JSON response
    return helpers.json_response(response)