Exemplo n.º 1
0
def get_metadata_from_uuid(request, metadata_uuid):
    # FIXME: we should only query using admin user if the user is admin or staff
    geonetwork_instance = geonetwork_service.get_instance()
    if geonetwork_instance != None and request.method == 'GET':
        try:
            parameters = request.GET
            if 'sharing' in parameters:
                sharing = True
            else:
                sharing = False
            
            if not sharing:
                metadataJsonSummary = geonetwork_instance.get_metadata(metadata_uuid)
                response = {
                    'html': get_metadata_as_html(metadataJsonSummary, core_utils.get_iso_language(request).part2b)
                }
                return  HttpResponse(json.dumps(response, indent=4), content_type='application/json')
            else:
                # FIXME
                #http://localhost/gvsigonline/catalog/get_metadata/<metadata_id>/
                return render(request, 'catalog_details.html', response)
            
        except Exception as e:
            logger.exception(e)
            return HttpResponse(status=500, content=e.message)
        
    return HttpResponse(status=500)
Exemplo n.º 2
0
def get_metadata_id(request, layer_ws, layer_name):
    logger.debug('get_metadata_id: ' + layer_ws + ":" + layer_name)
    response = {}
    response['success'] = False

    try:
        if request.method == 'GET':
            layers = Layer.objects.filter(name=layer_name)
            for layer in layers:
                if layer.datastore.workspace.name == layer_ws:
                    layerMetadata = LayerMetadata.objects.filter(layer=layer)
                    if layerMetadata and layerMetadata[
                            0].metadata_uuid != None and layerMetadata[
                                0].metadata_uuid != '':
                        md_response = geonetwork_service.get_instance(
                        ).get_metadata(layerMetadata[0].metadata_uuid)
                        if isinstance(md_response, dict):
                            response = md_response
                            response['success'] = True
                            response['html'] = get_metadata_as_html(
                                response,
                                core_utils.get_iso_language(request).part2b)
                        else:
                            logger.debug(type(response))
    except Exception as e:
        logger.exception(e)
    return HttpResponse(json.dumps(response), content_type='application/json')
Exemplo n.º 3
0
def create_metadata(request, layer_id):
    if request.method == 'POST':
        try:
            layer = Layer.objects.get(id=int(layer_id))
            uuid, the_id = geonetwork_service.get_instance().metadata_insert(layer)
            lm = LayerMetadata()
            lm.layer = layer
            lm.metadata_id = the_id
            lm.metadata_uuid = uuid
            lm.save()
            return JsonResponse({'status': 'ok', 'uuid': uuid, 'id': the_id})
        except Exception as e:
            logger.exception(e)
            return HttpResponse(status=500, content=e.message)
Exemplo n.º 4
0
def get_query(request):
    geonetwork_instance = geonetwork_service.get_instance()
    if geonetwork_instance!=None and request.method == 'GET':
        try:
            parameters = request.GET
            
            query = ''
            for key in parameters:
                query += key+'='
                for item in parameters.get(key):
                    query+=item
                query += '&'
            
            response = geonetwork_instance.get_query(query)
            aux_response = json.loads(response)
            return HttpResponse(response, content_type='text/plain')
        except Exception as e:
            return HttpResponse(status=500, content=e.message)
        
    return HttpResponse(status=500)
Exemplo n.º 5
0
def doGetMetadataDownloadResources(metadata_uuid, layer=None, user=None):
    all_resources = []
    xml_md = None
    try:
        import gvsigol_plugin_catalog.service as geonetwork_service
        geonetwork_instance = geonetwork_service.get_instance()
        xml_md = geonetwork_instance.get_metadata_raw(metadata_uuid)
        from gvsigol_plugin_catalog.mdstandards import registry
        reader = registry.get_reader(xml_md)
        onlineResources = reader.get_transfer_options()
        nativeCrs = reader.get_crs()
        max_public_size = float(downman_models.get_max_public_download_size())

        if not layer:
            if xml_md:
                layer_title = reader.get_title()
                LayerTuple = namedtuple('LayerTuple', ['name', 'title'])
                layer = LayerTuple('', layer_title)
        #onlineResources = geonetwork_instance.get_online_resources(metadata_uuid)
        for onlineResource in onlineResources:
            resource = None
            if 'OGC:WFS' in onlineResource.protocol:
                resource = getOgcDownloadDescriptor(
                    metadata_uuid,
                    onlineResource,
                    layer,
                    _('Vector data'),
                    dataSourceType=downman_models.ResourceLocator.
                    GEONETWORK_CATALOG_DATA_SOURCE_TYPE,
                    resourceType=downman_models.ResourceLocator.
                    OGC_WFS_RESOURCE_TYPE,
                    dataFormats=[
                        'shape-zip', 'application/json', 'csv', 'gml2', 'gml3'
                    ],
                    size=onlineResource.transfer_size,
                    nativeCrs=nativeCrs)
            elif 'OGC:WCS' in onlineResource.protocol:
                if 'Mapserver' in onlineResource.app_profile:
                    # necesitamos ofrecer el formato adecuado para el tipo de imagen (ortofoto, ráster de temperaturas, ráster cualitativo, etc)
                    resource = getOgcDownloadDescriptor(
                        metadata_uuid,
                        onlineResource,
                        layer,
                        _('Raster data'),
                        dataSourceType=downman_models.ResourceLocator.
                        GEONETWORK_CATALOG_DATA_SOURCE_TYPE,
                        resourceType=downman_models.ResourceLocator.
                        OGC_WCS_RESOURCE_TYPE,
                        dataFormats=['GEOTIFF_16', 'GEOTIFF_32', 'GEOTIFF_8'],
                        size=onlineResource.transfer_size,
                        nativeCrs=nativeCrs)
                else:  # assume Geoserver
                    resource = getOgcDownloadDescriptor(
                        metadata_uuid,
                        onlineResource,
                        layer,
                        _('Raster data'),
                        dataSourceType=downman_models.ResourceLocator.
                        GEONETWORK_CATALOG_DATA_SOURCE_TYPE,
                        resourceType=downman_models.ResourceLocator.
                        OGC_WCS_RESOURCE_TYPE,
                        dataFormats=['image/geotiff', 'image/png'],
                        size=onlineResource.transfer_size,
                        nativeCrs=nativeCrs)
            elif (onlineResource.protocol.startswith('WWW:DOWNLOAD-') and onlineResource.protocol.endswith('-download')) or \
                onlineResource.protocol.startswith('FILE:'):
                # or (onlineResource.protocol.startswith('WWW:LINK-') and onlineResource.protocol.endswith('-link')) \
                #onlineResource.protocol.startswith('FILE:'):
                if onlineResource.name:
                    resource_name = onlineResource.name
                elif onlineResource.url and not onlineResource.url.endswith(
                        "/"):
                    resource_name = os.path.basename(onlineResource.url)
                elif onlineResource.desc:
                    resource_name = onlineResource.desc
                else:
                    resource_name = onlineResource.url
                if onlineResource.desc:
                    resource_title = onlineResource.desc
                else:
                    resource_title = resource_name
                if layer and layer.name:
                    layer_name = layer.name
                else:
                    layer_name = resource_name
                if layer and layer.title:
                    layer_title = layer.title
                else:
                    layer_title = resource_title

                directDownloadUrl = None
                if onlineResource.url:
                    if onlineResource.url.startswith(
                            "http://") or onlineResource.url.startswith(
                                "https://"):
                        directDownloadUrl = onlineResource.url
                    if onlineResource.url.startswith("file://"):
                        try:
                            directDownloadUrl = getDirectDownloadUrl(
                                onlineResource.url, resource_title)
                        except:
                            logger.exception(
                                "Error resolving file download resource for layer"
                            )
                resource = ResourceDownloadDescriptor(
                    metadata_uuid,
                    layer_name,
                    layer_title,
                    resource_name,
                    resource_title,
                    dataSourceType=downman_models.ResourceLocator.
                    GEONETWORK_CATALOG_DATA_SOURCE_TYPE,
                    resourceType=downman_models.ResourceLocator.
                    HTTP_LINK_RESOURCE_TYPE,
                    url=onlineResource.url,
                    directDownloadUrl=directDownloadUrl,
                    size=onlineResource.transfer_size,
                    nativeCrs=nativeCrs)
            #elif onlineResource.protocol.startswith('WWW:LINK-'):
            if resource:
                resource.restricted = isRestricted(onlineResource,
                                                   max_public_size)
                all_resources.append(resource)
        if onlineResources is None or len(onlineResources) == 0:
            logger.debug(xml_md)
    except:
        logger.exception("Error getting download resources for layer")
        logger.debug(xml_md)
    return all_resources