SPW-DIG / metawal-core-geonetwork

Metawal - Catalogue pour l'information géographique de Wallonie
http://metawal.wallonie.be
GNU General Public License v2.0
3 stars 1 forks source link

Adaptation url accès WalOnMap (aciennement ADU) #876

Open marceaulouis opened 2 months ago

marceaulouis commented 2 months ago

Le géoportail va changer sa manière de gérer l'ouverture d'une carte depuis une fiche descriptive. Apparemment cela a été discuté avec Vincent en son temps.

A l'heure actuelle, on ajoute un lien ADU faisant référence au service, avec une suggestion (#740)

le GP voudrait qu'on modifie cet URL ADU par l'url suivant 👍 ex : [https://geoportail.wallonie.be/walonmap#panier=[{"serviceId":"","visible":](https://geoportail.wallonie.be/walonmap#panier=[%7B%22serviceId%22:%22%22,%22visible%22:) true,"url":" https://geoservices.wallonie.be/arcgis/rest/services/MOBILITE/BDOA/MapServer","label":"Ouvrages d'art régionaux gérés par le SPW","type":"AGS_DYNAMIC","metadataUrl":" [https://geoportail.wallonie.be/catalogue/c34743fa-7c50-4bfe-b587-e1253ff68eae.html"}]](https://geoportail.wallonie.be/catalogue/c34743fa-7c50-4bfe-b587-e1253ff68eae.html%22%7D])

Les param de la requête #panier sont les suivants : serviceId -> MDUUID (identifiant unique pour le catalogue WOM) visible -> true (afficher le service la carte url -> url du service REST label -> titre de la MD type -> AGS_DYNAMIC (service dynamique REST. Dans MW dispose de l'info si le service est tuilé ou non ?, si oui, on peut mettre AGS_TILED). Je dois vérifier pour les services WMS metadataUrl -> URL de la métadonnée (lien walonmap)

TO DO :

Merci !

GeryNi commented 2 months ago

Petit détail technique, les URL passées comme paramètres devront être encodées (URL Encoded) afin de remplacer les charactères problématiques ("/", les espaces,...)

fxprunayre commented 2 months ago

@marceaulouis ce sera effectif à partir de quand ?

fxprunayre commented 2 months ago

On va donc ajouter des URL de ce style:

<mrd:onLine>
 <cit:CI_OnlineResource>
  <cit:linkage>
    <gco:CharacterString>https://geoportail.wallonie.be/walonmap#panier={"serviceId":"","visible":true,"url":"https%3A%2F%2Fgeoservices.wallonie.be%2Farcgis%2Frest%2Fservices%2FAMENAGEMENT_TERRITOIRE%2FPAT_MND_UNESCO%2FMapServer","label":"Biens%20patrimoine%20mondial%20UNESCO%20-%20S%5Cu00E9rie","type":"AGS_DYNAMIC","metadataUrl":"https://geoportail.wallonie.be/catalogue/abe74a37-3c88-452b-94fd-5922d97d2e60.html"}</gco:CharacterString>

Je propose d'ajouter un paramètre pour choisir le type d'URL:

image

fxprunayre commented 2 months ago

A déployer pour test.

fxprunayre commented 2 months ago

Pour le SQL, il faut traiter les fiches :

WITH ns AS (
    select ARRAY[ARRAY['xlink', 'http://www.w3.org/1999/xlink'],
               ARRAY['mdb', 'http://standards.iso.org/iso/19115/-3/mdb/2.0'],
               ARRAY['cit', 'http://standards.iso.org/iso/19115/-3/cit/2.0'],
               ARRAY['mri', 'http://standards.iso.org/iso/19115/-3/mri/1.0'],
               ARRAY['mco', 'http://standards.iso.org/iso/19115/-3/mco/1.0'],
               ARRAY['mrd', 'http://standards.iso.org/iso/19115/-3/mrd/1.0'],
               ARRAY['xsi', 'http://www.w3.org/2001/XMLSchema-instance'],
               ARRAY['gco', 'http://standards.iso.org/iso/19115/-3/gco/1.0']] AS n
)

SELECT uuid, data AS currentXml, REPLACE(data, aduLink, 'https://geoportail.wallonie.be/walonmap#panier={"serviceId":"","visible":true,"url":"' || esriRest || '","label":' || to_json(title)::text || ',"type":"AGS_DYNAMIC","metadataUrl":"https://geoportail.wallonie.be/catalogue/' || uuid || '.html"}') AS newXml FROM (
    SELECT distinct(unnest(xpath('//mdb:identificationInfo/*/mri:citation/*/cit:title/*/text()',
                                 XMLPARSE(DOCUMENT data), n)))::text AS title,
                   uuid,
                   data,
                   unnest(xpath('//mrd:onLine/*[cit:protocol/*/text() = ''ESRI:REST'']/cit:linkage/*/text()',
                                XMLPARSE(DOCUMENT data), n))::text  AS esriRest,
                   unnest(xpath('//mrd:onLine/*/cit:linkage/*/text()[contains(., ''https://geoportail.wallonie.be/walonmap/#ADU'')]',
                                XMLPARSE(DOCUMENT data), n))::text  AS aduLink,
                   unnest(xpath('//mdb:metadataScope/*/mdb:resourceScope/*/@codeListValue',
                                XMLPARSE(DOCUMENT data), n))::text  AS resourceScope
    FROM metadata, ns
    WHERE data LIKE '%https://geoportail.wallonie.be/walonmap/#ADU%'
    ORDER BY uuid) AS records WHERE resourceScope != 'service' AND esriRest != '';

= 398 fiches sur db local

image

fxprunayre commented 2 months ago

Est-ce que ça s'applique aux liens qui ne sont pas WalOnMap ? eg. http://geoapps.wallonie.be/Cigale/Public/#ADU=https://geoservices.wallonie.be/arcgis/rest/services/EAU/MESU/MapServer

marceaulouis commented 1 month ago

Est-ce que ça s'applique aux liens qui ne sont pas WalOnMap ? eg. http://geoapps.wallonie.be/Cigale/Public/#ADU=https://geoservices.wallonie.be/arcgis/rest/services/EAU/MESU/MapServer

théoriquement ça doit passer mais mes tests tentent à montrer le contraire. Je propose de les exclure (si c'est pas trop galère). Il n'y en a pas beaucoup, au pire je corrigerai individuellement

marceaulouis commented 1 month ago

Attention, il y avait déjà une coquille dans l'url modèle, il manque un crochet [ au début

exemple fonctionnel :

https://geoportail.wallonie.be/walonmap#panier=**[**{"serviceId":"","visible":true,"url":"https://geoservices.wallonie.be/arcgis/rest/services/AMENAGEMENT_TERRITOIRE/PAT_MND_UNESCO/MapServer","label":"Biens patrimoine mondial UNESCO - Série","type":"AGS_DYNAMIC","metadataUrl":"https://geoportail.wallonie.be/catalogue/abe74a37-3c88-452b-94fd-5922d97d2e60.html"}]

fxprunayre commented 1 month ago

Corrigé. A déployer pour test.

GeryNi commented 1 month ago

Voici un exemple de fonction pour encoder les URL via posgresql.

Resource Wikipédia concerntant l'encodage pourcent utilisé dans les URLs: https://fr.wikipedia.org/wiki/Encodage-pourcent

Logique:

CREATE OR REPLACE FUNCTION urlencode(input_text TEXT)
    RETURNS TEXT AS
$$
DECLARE
    output_text TEXT := '';
    char_value CHAR(1);
BEGIN
    FOREACH char_value IN ARRAY string_to_array(input_text, NULL) LOOP
            IF char_value ~ '[a-zA-Z0-9\-_.~]' THEN
                output_text := output_text || char_value;
            ELSIF char_value = '' THEN
                output_text := output_text || '%20';
            ELSE
                output_text := output_text || '%' || TO_HEX(ascii(char_value));
            END IF;
        END LOOP;
    RETURN output_text;
END;
$$
    LANGUAGE plpgsql;

Exemple d'utilisation:

SELECT * FROM urlencode('https://example.com/path with spaces/index.html?query=1&param=test'::text);

Exemple de réponse:

https%3a%2f%2fexample.com%2fpath%20with%20spaces%2findex.html%3fquery%3d1%26param%3dtest%5b%5d
GeryNi commented 1 month ago

Tester le script SQL sur la base de données TEST (ancienne) changer la clause WHERE: WHERE data LIKE '%#ADU%'

GeryNi commented 1 month ago

Test en local avec:

SELECT * FROM metadata WHERE data LIKE '%https://geoportail.wallonie.be/walonmap/#ADU%' AND uuid = '04401a23-2510-4ea1-a521-eed0778e17f8';

CREATE OR REPLACE FUNCTION urlencode(input_text TEXT)
    RETURNS TEXT AS
$$
DECLARE
    output_text TEXT := '';
    char_value CHAR(1);
BEGIN
    FOREACH char_value IN ARRAY string_to_array(input_text, NULL) LOOP
            IF char_value ~ '[a-zA-Z0-9\-_.~]' THEN
                output_text := output_text || char_value;
            ELSIF char_value = '' THEN
                output_text := output_text || '%20';
            ELSE
                output_text := output_text || '%' || TO_HEX(ascii(char_value));
            END IF;
        END LOOP;
    RETURN output_text;
END;
$$
    LANGUAGE plpgsql;

WITH ns AS (
    select ARRAY[ARRAY['xlink', 'http://www.w3.org/1999/xlink'],
               ARRAY['mdb', 'http://standards.iso.org/iso/19115/-3/mdb/2.0'],
               ARRAY['cit', 'http://standards.iso.org/iso/19115/-3/cit/2.0'],
               ARRAY['mri', 'http://standards.iso.org/iso/19115/-3/mri/1.0'],
               ARRAY['mco', 'http://standards.iso.org/iso/19115/-3/mco/1.0'],
               ARRAY['mrd', 'http://standards.iso.org/iso/19115/-3/mrd/1.0'],
               ARRAY['xsi', 'http://www.w3.org/2001/XMLSchema-instance'],
               ARRAY['gco', 'http://standards.iso.org/iso/19115/-3/gco/1.0']] AS n
)
UPDATE metadata SET data = REPLACE(data, aduLink, 'https://geoportail.wallonie.be/walonmap#panier=' || urlencode('{"serviceId":"","visible":true,"url":"' || esriRest || '","label":' || to_json(currentTitle)::text || ',"type":"AGS_DYNAMIC","metadataUrl":"https://geoportail.wallonie.be/catalogue/' || currentId || '.html"}'::text)) FROM (
                                                                                                                                                                                                                                                                                                                                        SELECT distinct(
                                                                                                                                                                                                                                                                                                                                                        unnest(xpath('//mdb:identificationInfo/*/mri:citation/*/cit:title/*/text()',
                                                                                                                                                                                                                                                                                                                                                                     XMLPARSE(DOCUMENT data), n)))::text AS currentTitle,
                                                                                                                                                                                                                                                                                                                                                    data as currentXml,
                                                                                                                                                                                                                                                                                                                                                       uuid as currentId,
                                                                                                                                                                                                                                                                                                                                                       unnest(xpath('//mrd:onLine/*[cit:protocol/*/text() = ''ESRI:REST'']/cit:linkage/*/text()',
                                                                                                                                                                                                                                                                                                                                                                    XMLPARSE(DOCUMENT data), n))::text  AS esriRest,
                                                                                                                                                                                                                                                                                                                                                       unnest(xpath('//mrd:onLine/*/cit:linkage/*/text()[contains(., ''https://geoportail.wallonie.be/walonmap/#ADU'')]',
                                                                                                                                                                                                                                                                                                                                                                    XMLPARSE(DOCUMENT data), n))::text  AS aduLink,
                                                                                                                                                                                                                                                                                                                                                       unnest(xpath('//mdb:metadataScope/*/mdb:resourceScope/*/@codeListValue',
                                                                                                                                                                                                                                                                                                                                                                    XMLPARSE(DOCUMENT data), n))::text  AS resourceScope
                                                                                                                                                                                                                                                                                                                                        FROM metadata, ns
                                                                                                                                                                                                                                                                                                                                        WHERE data LIKE '%https://geoportail.wallonie.be/walonmap/#ADU%' AND uuid = '04401a23-2510-4ea1-a521-eed0778e17f8'
                                                                                                                                                                                                                                                                                                                                        ORDER BY uuid) AS records WHERE resourceScope != 'service' AND esriRest != '';

Donne le xml suivant:

              <cit:linkage>
                <gco:CharacterString>https://geoportail.wallonie.be/walonmap#panier=%7b%22serviceId%22%3a%22%22%2c%22visible%22%3atrue%2c%22url%22%3a%22https%3a%2f%2fgeoservices.wallonie.be%2farcgis%2frest%2fservices%2fINDUSTRIES_SERVICES%2fSITE_HOSP%2fMapServer%22%2c%22label%22%3a%22Sites%20hospitaliers%20%28hors%20territoire%20de%20la%20Communaut%e9%20germanophone%29%22%2c%22type%22%3a%22AGS_DYNAMIC%22%2c%22metadataUrl%22%3a%22https%3a%2f%2fgeoportail.wallonie.be%2fcatalogue%2f04401a23-2510-4ea1-a521-eed0778e17f8.html%22%7d</gco:CharacterString>
              </cit:linkage>
GeryNi commented 3 weeks ago

Selection d'une fiche sur Metawal TEST (OLD): 0466f660-9859-4e5d-934f-437074e0d607

Lien vers la fiche modifiée: https://metawal4.test.wallonie.be/geonetwork/srv/api/records/0466f660-9859-4e5d-934f-437074e0d607/formatters/xml?approved=true