From ea50d8ae32ffc4f974886a064738cb65569579d8 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 12 Apr 2023 19:05:24 +0200 Subject: [PATCH] Tested all stocks --- .../publisher/freemarker/FreeMarkerTest.java | 13 +++++++++--- src/test/resources/examples/.gitignore | 1 + .../resources/freemarker/AssessmentUnit.ftl | 20 +++++++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 src/test/resources/examples/.gitignore diff --git a/src/test/java/org/gcube/grsf/publisher/freemarker/FreeMarkerTest.java b/src/test/java/org/gcube/grsf/publisher/freemarker/FreeMarkerTest.java index 38ddf09..e8135d9 100644 --- a/src/test/java/org/gcube/grsf/publisher/freemarker/FreeMarkerTest.java +++ b/src/test/java/org/gcube/grsf/publisher/freemarker/FreeMarkerTest.java @@ -24,13 +24,18 @@ public class FreeMarkerTest { return new File(resourcesDirectory, "examples/AssessmentUnit"); } + public File getStockExampleDirectory() throws Exception { + File resourcesDirectory = FreeMarker.getResourcesDirectory(); + return new File(resourcesDirectory, "examples/Stock"); + } + @Test public void testIt() throws Exception { FreeMarker freeMarker = new FreeMarker(); Template template = freeMarker.getTemplate("AssessmentUnit.ftl"); - File assessmentUnitExamplesDir = getAssessmentUnitExampleDirectory(); + File assessmentUnitExamplesDir = getStockExampleDirectory(); for(File json : assessmentUnitExamplesDir.listFiles()) { ObjectMapper mapper = new ObjectMapper(); Map map = mapper.readValue(json, Map.class); @@ -42,8 +47,10 @@ public class FreeMarkerTest { * <#assign uri_resolver_base_url="https://data.d4science.org/ctlg/GRSF_Admin"> * <#assign include_sensitive=true> */ - - File out = new File(FreeMarker.getResourcesDirectory(), json.getName()); + File outDir = new File(FreeMarker.getResourcesDirectory(), "out"); + outDir.delete(); + outDir.mkdir(); + File out = new File(outDir, json.getName()); out.delete(); Writer writer = new FileWriter(out); diff --git a/src/test/resources/examples/.gitignore b/src/test/resources/examples/.gitignore new file mode 100644 index 0000000..873dbfe --- /dev/null +++ b/src/test/resources/examples/.gitignore @@ -0,0 +1 @@ +/Stock/ diff --git a/src/test/resources/freemarker/AssessmentUnit.ftl b/src/test/resources/freemarker/AssessmentUnit.ftl index 15891c9..3406520 100644 --- a/src/test/resources/freemarker/AssessmentUnit.ftl +++ b/src/test/resources/freemarker/AssessmentUnit.ftl @@ -70,7 +70,7 @@ { "title" : "${stock_name}", "license_id": "${license_id}", - "description": "Short Name: ${short_name}\nGRSF Semantic Identifier: ${grsf_semantic_identifier}\nRecord URL: ${record_url}", + "description": "Short Name: ${short_name}\n<#if grsf_semantic_identifier??>GRSF Semantic Identifier: ${grsf_semantic_identifier}\nRecord URL: ${record_url}", "groups": [ <@group groupname="abundance-level-group" var=abundance_level /> <@group groupname="abundance-level-firms-standard-group" var=firms_standard_abundance_level /> @@ -83,7 +83,9 @@ <@group groupname="landing-group" var=landings /> <@group groupname="scientific-advice-group" var=scientific_advice /> <@group groupname="state-and-trend-group" var=state_and_trend_of_marine_resources /> + <#if sdg_flag??> <@group groupname="grsf-sdg-flag-group" var=sdg_flag?c include=sdg_flag /> + <@group groupname="stock-group" var="OK" sep=""/> ], "tags" : [ @@ -129,9 +131,11 @@ <@metadata key="GRSF Semantic Identifier" namespace="stock_identity" var=grsf_semantic_identifier /> <@metadatalist key="Assessment Area" namespace="stock_identity" list=assessment_area /> <@metadatalist key="Connected Record" namespace="stock_identity" list=connected /> + <#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 /> <@metadatalist key="Species" namespace="stock_identity" list=species /> @@ -178,13 +182,25 @@ <#-- END of Stock Data Section--> <#-- Record Info Section --> - <@metadata key="Annotation" var=annotations include=include_sensitive /> + + <#-- TODO + <#if annotations?? && include_sensitive > + <#list annotations as an> + <@metadata key="Annotation" var=an /> + + + --> + <@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="Record URL" var=record_url /> + <#if sdg_flag??> <@metadata key="SDG Flag" var=sdg_flag?c /> + <@metadata key="Status of the Record" var=status_grsf_record /> <@metadata key="system:type" var=grsf_type?capitalize sep=""/> <#-- END of Record Info Section -->