From 66453c7e9e531e59320ad3db7c1b8fd3cb135953 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 13 Apr 2023 14:04:20 +0200 Subject: [PATCH] Fixed templates --- src/test/resources/freemarker/Fishery.ftl | 32 ++++---- src/test/resources/freemarker/Stock.ftl | 91 +++++++++++------------ 2 files changed, 61 insertions(+), 62 deletions(-) diff --git a/src/test/resources/freemarker/Fishery.ftl b/src/test/resources/freemarker/Fishery.ftl index 2342773..a05650d 100644 --- a/src/test/resources/freemarker/Fishery.ftl +++ b/src/test/resources/freemarker/Fishery.ftl @@ -13,16 +13,16 @@ <#macro tag tagname="" include=true sep=","> <#if tagname?has_content && include> { - "name": "${tagname}" + "name": "${tagname?json_string}" }${sep} <#macro tags list include=true sep=","> <#if list?? && include> - <#list list as elem> + <#list list as tagname> { - "name": "${elem}" + "name": "${tagname?json_string}" }${sep} @@ -32,7 +32,7 @@ <#if var?has_content && include> { "key": "<#if namespace?has_content>${namespace}:${key}", - "value": "${var}" + "value": "${var?json_string}" }${sep} @@ -41,7 +41,7 @@ <#if list?has_content && include> <#list list as elem> <#if tagValues> - <#assign tagList += ["${elem}"]> + <#assign tagList += ["${elem?json_string}"]> { "key": "<#if namespace?has_content>${namespace}:${key}", @@ -73,7 +73,7 @@ <#list list[0..*5] as ts> { "key": "<#if namespace?has_content>${namespace}:${key}", - "value": "${ts.value?json_string} [<#if ts.unit?has_content>Unit: ${ts.unit} - <#if ts.reporting_year_or_assessment_id?has_content>Rep. Year or Assessment ID: ${ts.reporting_year_or_assessment_id} - <#if ts.reference_year?has_content>Ref. Year: ${ts.reference_year} - <#if ts.data_owner?has_content>Data Owner: ${ts.data_owner} - <#if ts.db_source?has_content>DB Source: ${ts.db_source}]" + "value": "${ts.value?json_string} [<#if ts.unit?has_content>Unit: ${ts.unit?json_string} - <#if ts.reporting_year_or_assessment_id?has_content>Rep. Year or Assessment ID: ${ts.reporting_year_or_assessment_id?json_string} - <#if ts.reference_year?has_content>Ref. Year: ${ts.reference_year?json_string} - <#if ts.data_owner?has_content>Data Owner: ${ts.data_owner?json_string} - <#if ts.db_source?has_content>DB Source: ${ts.db_source?json_string}]" }${sep} @@ -97,6 +97,7 @@ "license_id": "${license_id}", "description": "Short Name: ${short_name}\n<#if grsf_semantic_identifier??>GRSF Semantic Identifier: ${grsf_semantic_identifier}\nRecord URL: ${record_url}", "extras": [ + <#-- START of Common Metadata --> <@metadata key="GRSF Type" namespace="fishery_identity" var=grsf_type?capitalize /> <@metadatalist key="Data Owner" namespace="fishery_data" list=data_owner include=include_sensitive /> <#if database_sources??> @@ -118,13 +119,13 @@ <@metadatalist key="Similar GRSF Record" namespace="fishery_identity" list=similar_grsf_record /> <@metadata key="Domain" var="Fishery" /> <@metadata key="GRSF UUID" var=grsf_uuid /> - <#if spatial??> - <@metadata key="spatial" var=spatial?json_string /> - + <@metadata key="spatial" var=spatial /> <@metadatalist key="Connected Record" namespace="fishery_identity" list=connected /> <@metadatalistJson key="Annotation" list=annotations /> <@metadata key="Citation" var=citation /> - + <#-- END of Common Metadata --> + + <#-- START of Fishery Metadata --> <@metadata key="GRSF Fishery Name" namespace="fishery_identity" var=fishery_name /> <@metadata key="GRSF Semantic Identifier" namespace="fishery_identity" var=grsf_semantic_identifier /> <#if traceability_flag??> @@ -139,6 +140,7 @@ <@metadatalist key="Flag State" namespace="fishery_identity" list=flag_state tagValues=true /> <@metadatalist key="Fishing Gear" namespace="fishery_identity" list=fishing_gear tagValues=true /> <@metadatalist key="Management Body/Authority" namespace="fishery_identity" list=management_body_authorities /> + <#-- END of Fishery Metadata --> <@metadata key="Record URL" var=record_url /> <@metadata key="system:type" var=grsf_type?capitalize sep=""/> @@ -164,7 +166,9 @@ <@tag tagname=similarities_indicator sep=""/> ], "resources": [ - <#-- + <@resources var=source_of_information /><#if refers_to?? && source_of_information??>, + <@resources var=refers_to name="id" /> + <#-- "refers_to": [ { "id": "eb7ddeb0-ecc3-393b-b98a-fdb90be2c706", @@ -187,10 +191,8 @@ When changed use the following macro in place of the one using id which is also wrong but it avoid code on server side for the moment - <@resources var=refers_to /><#if source_of_information??>, + <@resources var=refers_to /> --> - <@resources var=refers_to name="id" /><#if refers_to?? && source_of_information??>, - <@resources var=source_of_information /> ], "timeseries" : [ <#list timeseriesList as elem> @@ -201,4 +203,4 @@ }<#sep>, ] -} \ No newline at end of file +} diff --git a/src/test/resources/freemarker/Stock.ftl b/src/test/resources/freemarker/Stock.ftl index 3e85c3f..a40f4c0 100644 --- a/src/test/resources/freemarker/Stock.ftl +++ b/src/test/resources/freemarker/Stock.ftl @@ -13,16 +13,16 @@ <#macro tag tagname="" include=true sep=","> <#if tagname?has_content && include> { - "name": "${tagname}" + "name": "${tagname?json_string}" }${sep} <#macro tags list include=true sep=","> <#if list?? && include> - <#list list as elem> + <#list list as tagname> { - "name": "${elem}" + "name": "${tagname?json_string}" }${sep} @@ -32,7 +32,7 @@ <#if var?has_content && include> { "key": "<#if namespace?has_content>${namespace}:${key}", - "value": "${var}" + "value": "${var?json_string}" }${sep} @@ -41,7 +41,7 @@ <#if list?has_content && include> <#list list as elem> <#if tagValues> - <#assign tagList += ["${elem}"]> + <#assign tagList += ["${elem?json_string}"]> { "key": "<#if namespace?has_content>${namespace}:${key}", @@ -73,7 +73,7 @@ <#list list[0..*5] as ts> { "key": "<#if namespace?has_content>${namespace}:${key}", - "value": "${ts.value?json_string} [<#if ts.unit?has_content>Unit: ${ts.unit} - <#if ts.reporting_year_or_assessment_id?has_content>Rep. Year or Assessment ID: ${ts.reporting_year_or_assessment_id} - <#if ts.reference_year?has_content>Ref. Year: ${ts.reference_year} - <#if ts.data_owner?has_content>Data Owner: ${ts.data_owner} - <#if ts.db_source?has_content>DB Source: ${ts.db_source}]" + "value": "${ts.value?json_string} [<#if ts.unit?has_content>Unit: ${ts.unit?json_string} - <#if ts.reporting_year_or_assessment_id?has_content>Rep. Year or Assessment ID: ${ts.reporting_year_or_assessment_id?json_string} - <#if ts.reference_year?has_content>Ref. Year: ${ts.reference_year?json_string} - <#if ts.data_owner?has_content>Data Owner: ${ts.data_owner?json_string} - <#if ts.db_source?has_content>DB Source: ${ts.db_source?json_string}]" }${sep} @@ -97,25 +97,39 @@ "license_id": "${license_id}", "description": "Short Name: ${short_name}\n<#if grsf_semantic_identifier??>GRSF Semantic Identifier: ${grsf_semantic_identifier}\nRecord URL: ${record_url}", "extras": [ - <#-- Stock Identity Section --> - <@metadata key="GRSF Stock Name" namespace="stock_identity" var=stock_name /> - <@metadata key="Short Name" namespace="stock_identity" var=short_name /> - <@metadata key="GRSF Semantic Identifier" namespace="stock_identity" var=grsf_semantic_identifier /> - <@metadatalist key="Assessment Area" namespace="stock_identity" list=assessment_area tagValues=true /> - <@metadatalist key="Connected Record" namespace="stock_identity" list=connected /> + <#-- START of Common Metadata --> + <@metadata key="GRSF Type" namespace="stock_identity" var=grsf_type?capitalize /> + <@metadatalist key="Data Owner" namespace="stock_data" list=data_owner include=include_sensitive /> <#if database_sources??> <@metadatalist key="Database Source" namespace="stock_identity" list=database_sources?map(database_source -> database_source.name) /> <#-- database_sources will change from list of objects to list of string. Use the line below in place of the line above--> <#-- <@metadatalist key="Database Source" namespace="stock_identity" list=database_sources /> --> - <@metadata key="GRSF Type" namespace="stock_identity" var=grsf_type?capitalize /> - <@metadatalist key="Similar GRSF Record" namespace="stock_identity" list=similar_grsf_record /> + <@metadata key="Short Name" namespace="stock_identity" var=short_name /> + <#if sdg_flag??> + <@metadata key="SDG Flag" var=sdg_flag?c /> + <#if sdg_flag> + <#assign groupList += ["grsf-sdg-flag-group"]> + + + <@metadata key="Status of the Record" var=status_grsf_record /> + <@timeseries key="Catch" namespace="stock_data" timeseries="catches" groupname="catch-group" /> + <@timeseries key="Landing" namespace="stock_data" timeseries="landings" groupname="landing-group" /> <@metadatalist key="Species" namespace="stock_identity" list=species tagValues=true/> - <#-- END of Stock Identity Section --> + <@metadatalist key="Similar GRSF Record" namespace="stock_identity" list=similar_grsf_record /> + <@metadata key="Domain" var="Stock" /> + <@metadata key="GRSF UUID" var=grsf_uuid /> + <@metadata key="spatial" var=spatial /> + <@metadatalist key="Connected Record" namespace="stock_identity" list=connected /> + <@metadatalistJson key="Annotation" list=annotations /> + <@metadata key="Citation" var=citation /> + <#-- END of Common Metadata --> - <#-- Stock Data Section --> - <@timeseries key="Abundance Level" namespace="stock_data" timeseries="abundance_level" groupname="abundance-level-group" /> - <@timeseries key="Abundance Level (FIRMS Standard)" namespace="stock_data" timeseries="firms_standard_abundance_level" groupname="abundance-level-firms-standard-group" /> + + <#-- START of Stock Metadata --> + <@metadata key="GRSF Stock Name" namespace="stock_identity" var=stock_name /> + <@metadata key="GRSF Semantic Identifier" namespace="stock_identity" var=grsf_semantic_identifier /> + <@metadatalist key="Assessment Area" namespace="stock_identity" list=assessment_area tagValues=true /> <@metadatalist key="Assessment Method" namespace="stock_data" list=assessment_methods include=include_sensitive /> <#-- assessment_methods will change from list of string to timeseries. @@ -129,14 +143,13 @@ Use the line below in place of the line above --> <#-- <@timeseries key="Assessment Method" namespace="stock_data" timeseries="assessment_methods" groupname="assessment-method-group" /> --> - <@metadata key="Assessor" namespace="stock_data" var=assessor include=include_sensitive /> + <@timeseries key="Abundance Level (FIRMS Standard)" namespace="stock_data" timeseries="firms_standard_abundance_level" groupname="abundance-level-firms-standard-group" /> + <@timeseries key="Abundance Level" namespace="stock_data" timeseries="abundance_level" groupname="abundance-level-group" /> <@timeseries key="Biomass" namespace="stock_data" timeseries="biomass" groupname="biomass-group" /> - <@timeseries key="Catch" namespace="stock_data" timeseries="catches" groupname="catch-group" /> - <@metadatalist key="Data Owner" namespace="stock_data" list=data_owner include=include_sensitive /> - <@timeseries key="FAO Stock Status Category" namespace="stock_data" timeseries="fao_categories" groupname="fao-stock-status-category-group" /> - <@timeseries key="Fishing Pressure" namespace="stock_data" timeseries="fishing_pressure" groupname="fishing-pressure-group" /> <@timeseries key="Fishing Pressure (FIRMS Standard)" namespace="stock_data" timeseries="firms_standard_fishing_pressure" groupname="fishing-pressure-firms-standard-group" /> - <@timeseries key="Landing" namespace="stock_data" timeseries="landings" groupname="landing-group" /> + <@timeseries key="Fishing Pressure" namespace="stock_data" timeseries="fishing_pressure" groupname="fishing-pressure-group" /> + <@timeseries key="State and Trend" namespace="stock_data" timeseries="state_and_trend_of_marine_resources" groupname="state-and-trend-group" /> + <@timeseries key="FAO Stock Status Category" namespace="stock_data" timeseries="fao_categories" groupname="fao-stock-status-category-group" /> <@metadatalist key="Scientific Advice" namespace="stock_data" list=scientific_advice include=include_sensitive /> <#-- scientific_advice will change from list of string to timeseries. @@ -150,27 +163,11 @@ Use the line below in place of the line above --> <#-- <@timeseries key="Scientific Advice" namespace="stock_data" timeseries="scientific_advice" groupname="scientific-advice-group" /> --> - <@timeseries key="State and Trend" namespace="stock_data" timeseries="state_and_trend_of_marine_resources" groupname="state-and-trend-group" /> - <#-- END of Stock Data Section--> - - <#-- Record Info Section --> - <@metadatalistJson key="Annotation" list=annotations /> - <@metadata key="Citation" var=citation /> - <@metadata key="Domain" var="Stock" /> - <#if spatial??> - <@metadata key="spatial" var=spatial?json_string /> - - <@metadata key="GRSF UUID" var=grsf_uuid /> + <@metadata key="Assessor" namespace="stock_data" var=assessor include=include_sensitive /> + <#-- END of Stock Metadata --> + <@metadata key="Record URL" var=record_url /> - <#if sdg_flag??> - <@metadata key="SDG Flag" var=sdg_flag?c /> - <#if sdg_flag> - <#assign groupList += ["grsf-sdg-flag-group"]> - - - <@metadata key="Status of the Record" var=status_grsf_record /> <@metadata key="system:type" var=grsf_type?capitalize sep=""/> - <#-- END of Record Info Section --> ], "groups": [ <#list groupList as groupname> @@ -193,7 +190,9 @@ <@tag tagname=similarities_indicator sep=""/> ], "resources": [ - <#-- + <@resources var=source_of_information /><#if refers_to?? && source_of_information??>, + <@resources var=refers_to name="id" /> + <#-- "refers_to": [ { "id": "eb7ddeb0-ecc3-393b-b98a-fdb90be2c706", @@ -216,10 +215,8 @@ When changed use the following macro in place of the one using id which is also wrong but it avoid code on server side for the moment - <@resources var=refers_to /><#if source_of_information??>, + <@resources var=refers_to /> --> - <@resources var=refers_to name="id" /><#if refers_to?? && source_of_information??>, - <@resources var=source_of_information /> ], "timeseries" : [ <#list timeseriesList as elem>