Пример #1
0
def get_map_info(workspace, mapname):
    uuid = get_map_uuid(workspace, mapname)
    try:
        csw = common_util.create_csw()
        if uuid is None or csw is None:
            return {}
        muuid = get_metadata_uuid(uuid)
        csw.getrecordbyid(id=[muuid], esn='brief')
    except (HTTPError, ConnectionError):
        current_app.logger.info(traceback.format_exc())
        return {}
    if muuid in csw.records:
        return {
            'metadata': {
                'identifier':
                muuid,
                'csw_url':
                settings.CSW_PROXY_URL,
                'record_url':
                settings.CSW_RECORD_URL.format(identifier=muuid),
                'comparison_url':
                url_for('rest_workspace_map_metadata_comparison.get',
                        workspace=workspace,
                        mapname=mapname),
            }
        }
    return {}
Пример #2
0
def get_metadata_comparison(workspace, mapname):
    uuid = get_map_uuid(workspace, mapname)
    csw = common_util.create_csw()
    if uuid is None or csw is None:
        return {}
    muuid = get_metadata_uuid(uuid)
    element = common_util.get_record_element_by_id(csw, muuid)
    if element is None:
        return {}

    # current_app.logger.info(f"xml\n{ET.tostring(el)}")

    props = common_util.parse_md_properties(element, [
        'abstract',
        'extent',
        'graphic_url',
        'identifier',
        'map_endpoint',
        'map_file_endpoint',
        'operates_on',
        'organisation_name',
        'publication_date',
        'reference_system',
        'revision_date',
        'title',
    ], METADATA_PROPERTIES)
    # current_app.logger.info(f"props:\n{json.dumps(props, indent=2)}")
    # current_app.logger.info(f"csw.request={csw.request}")
    url = csw.request.replace(settings.CSW_URL, settings.CSW_PROXY_URL)
    return {f"{url}": props}
Пример #3
0
def patch_map(workspace,
              mapname,
              metadata_properties_to_refresh=None,
              actor_name=None,
              create_if_not_exists=True,
              timeout=5):
    # current_app.logger.info(f"patch_map metadata_properties_to_refresh={metadata_properties_to_refresh}")
    metadata_properties_to_refresh = metadata_properties_to_refresh or []
    if len(metadata_properties_to_refresh) == 0:
        return {}
    uuid = get_map_uuid(workspace, mapname)
    csw = common_util.create_csw()
    if uuid is None or csw is None:
        return None
    muuid = get_metadata_uuid(uuid)
    element = common_util.get_record_element_by_id(csw, muuid)
    if element is None:
        if create_if_not_exists:
            return csw_insert(workspace, mapname, actor_name=actor_name)
        return None
    # current_app.logger.info(f"Current element=\n{ET.tostring(element, encoding='unicode', pretty_print=True)}")

    _, prop_values = get_template_path_and_values(
        workspace,
        mapname,
        http_method=common.REQUEST_METHOD_PATCH,
        actor_name=actor_name)
    prop_values = {
        k: v
        for k, v in prop_values.items()
        if k in metadata_properties_to_refresh + ['md_date_stamp']
    }
    # current_app.logger.info(f"update_map prop_values={prop_values}")
    basic_template_path = os.path.join(
        os.path.dirname(os.path.realpath(__file__)), './record-template.xml')
    element = common_util.fill_xml_template_obj(
        element,
        prop_values,
        METADATA_PROPERTIES,
        basic_template_path=basic_template_path)
    record = ET.tostring(element, encoding='unicode', pretty_print=True)
    # current_app.logger.info(f"update_map record=\n{record}")
    try:
        common_util.csw_update({
            'muuid': muuid,
            'record': record,
        },
                               timeout=timeout)
    except (HTTPError, ConnectionError) as exc:
        current_app.logger.info(traceback.format_exc())
        raise LaymanError(38) from exc
    return muuid
Пример #4
0
def test_num_records():
    publs_by_type = uuid.check_redis_consistency()
    num_publications = sum([len(publs) for publs in publs_by_type.values()])
    csw = common_util.create_csw()
    assert csw is not None, f"{settings.CSW_URL}, {settings.CSW_BASIC_AUTHN}"
    from owslib.fes import PropertyIsLike
    any_query = PropertyIsLike('apiso:Identifier', '*', wildCard='*')
    csw.getrecords2(constraints=[any_query], maxrecords=100, outputschema="http://www.isotc211.org/2005/gmd")
    assert csw.exceptionreport is None
    url_part = f"://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/"
    records = {
        k: r for k, r in csw.records.items()
        if any((url_part in u for u in [ol.url for ol in r.distribution.online]))
    }
    import json
    assert len(
        records) == num_publications, f"md_record_ids={json.dumps(list(records.keys()), indent=5)}\npubls={json.dumps(publs_by_type, indent=2)}"