From 987dc4f378d014e308664303fe5234e57bf5ab29 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 24 Jun 2024 14:16:03 +0200 Subject: [PATCH] new version of the template --- .../d4gna_to_catalogue.ftl | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/D4S_UCDs/DEV/devVRE/catalogue/binding/freemarker_templates/d4gna_to_catalogue.ftl b/D4S_UCDs/DEV/devVRE/catalogue/binding/freemarker_templates/d4gna_to_catalogue.ftl index 77a3d31..be32e32 100644 --- a/D4S_UCDs/DEV/devVRE/catalogue/binding/freemarker_templates/d4gna_to_catalogue.ftl +++ b/D4S_UCDs/DEV/devVRE/catalogue/binding/freemarker_templates/d4gna_to_catalogue.ftl @@ -6,15 +6,29 @@ <#assign tags=[]> <#assign extras=[]> +<#function sanitizeString(value)> +<#if value??> + <#return value?trim?replace('\n','')?replace('\"','')> + +<#return ""> + + +<#function onlyAlphanumericString(value)> +<#if value??> + <#return value?trim?replace('\n','')?replace('\"','')?replace("[^\\w]+", "-", "r")> + +<#return ""> + + <#-- Macro to assign Tags --> <#macro assignTag in_tags> <#if in_tags??> <#if in_tags?is_sequence> <#list in_tags as my_tag> - <#assign tags = tags + [my_tag] /> + <#assign tags = tags + [onlyAlphanumericString(my_tag)] /> <#else> - <#assign tags = tags + [in_tags] /> + <#assign tags = tags + [onlyAlphanumericString(in_tags)] /> @@ -26,7 +40,7 @@ <#assign description = ""/> <#if url??> - <#assign resource = {"name": name, "url": url, "description": description, "format": format}> + <#assign resource = {"name": name, "url": url, "description": sanitizeString(description), "format": format}> <#assign resources = resources + [resource]/> @@ -47,7 +61,11 @@ <#-- Macro to assign Extras field --> <#macro assignExtraField key value asObject> <#if key??> - <#assign extra = {"key": key, "value": value, "asObject": asObject}> +<#assign checkedValue = value/> +<#if key != "spatial"> +<#assign checkedValue = sanitizeString(value)/> + + <#assign extra = {"key": sanitizeString(key), "value": checkedValue, "asObject": asObject}> <#assign extras = extras + [extra]/> @@ -120,17 +138,17 @@ + <#-- Starting document mapping to Catalogue --> - +<#compress> { "name": "${jsonProj._id}", "title": "${theDocument.nome}", "license_id": "CC-BY-SA-4.0", "private": false, - <#assign description = theDocument.introduzione?trim /> - <#assign sanitizedNotes = description?replace("\\n", "")> + <#assign sanitizedNotes = sanitizeString(theDocument.introduzione) /> "notes": "${sanitizedNotes}", <#-- @@ -263,10 +281,10 @@ Starting document mapping to Catalogue <#if theDocument.contestoIndagine??> <#if theDocument.contestoIndagine?is_sequence> <#list theDocument.contestoIndagine as my_extra> - <@assignExtraField key="Definizione del contesto d'indagine" value=my_extra asObject=false> + <@assignExtraField key="Contesto Indagine" value=my_extra asObject=false> <#else> - <@assignExtraField key="Definizione del contesto d'indagine" value=theDocument.contestoIndagine asObject=false> + <@assignExtraField key="Contesto Indagine" value=theDocument.contestoIndagine asObject=false> @@ -281,10 +299,10 @@ Starting document mapping to Catalogue <#if theDocument.cronologiaMacrofase??> <#if theDocument.cronologiaMacrofase?is_sequence> <#list theDocument.cronologiaMacrofase as my_extra> - <@assignExtraField key="Cronologia (Macrofase)" value=my_extra asObject=false> + <@assignExtraField key="Cronologia Macrofase" value=my_extra asObject=false> <#else> - <@assignExtraField key="Cronologia (Macrofase)" value=theDocument.cronologiaMacrofase asObject=false> + <@assignExtraField key="Cronologia Macrofase" value=theDocument.cronologiaMacrofase asObject=false> @@ -304,4 +322,4 @@ Starting document mapping to Catalogue <@buildExtrasFields the_extras=extras> } - +