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 067a79e..02e95b3 100644 --- a/src/test/java/org/gcube/grsf/publisher/freemarker/FreeMarkerTest.java +++ b/src/test/java/org/gcube/grsf/publisher/freemarker/FreeMarkerTest.java @@ -13,6 +13,11 @@ import freemarker.template.Template; public class FreeMarkerTest { public File getTraceabilityUnitExampleDirectory() throws Exception { + File resourcesDirectory = FreeMarker.getResourcesDirectory(); + return new File(resourcesDirectory, "examples/TraceabilityUnit"); + } + + public File getAssessmentUnitExampleDirectory() throws Exception { File resourcesDirectory = FreeMarker.getResourcesDirectory(); return new File(resourcesDirectory, "examples/AssessmentUnit"); } @@ -21,19 +26,22 @@ public class FreeMarkerTest { public void testIt() throws Exception { FreeMarker freeMarker = new FreeMarker(); - Template template = freeMarker.getTemplate("example.ftl"); + Template template = freeMarker.getTemplate("AssessmentUnit.ftl"); - File json = new File(getTraceabilityUnitExampleDirectory(), "00a1f849-1b43-3fd1-9255-1d1134c969bb.json"); - ObjectMapper mapper = new ObjectMapper(); - Map map = mapper.readValue(json, Map.class); - - File out = new File(FreeMarker.getResourcesDirectory(), "output.json"); - out.delete(); - - Writer writer = new FileWriter(out); - template.process(map, writer); - writer.flush(); - writer.close(); + File assessmentUnitExamplesDir = getAssessmentUnitExampleDirectory(); + for(File json : assessmentUnitExamplesDir.listFiles()) { + ObjectMapper mapper = new ObjectMapper(); + Map map = mapper.readValue(json, Map.class); + map.put("uri_resolver_base_url", "https://data.d4science.org/ctlg/GRSF_Admin"); + + File out = new File(FreeMarker.getResourcesDirectory(), json.getName()); + out.delete(); + + Writer writer = new FileWriter(out); + template.process(map, writer); + writer.flush(); + writer.close(); + } } diff --git a/src/test/resources/freemarker/AssessmentUnit.ftl b/src/test/resources/freemarker/AssessmentUnit.ftl new file mode 100644 index 0000000..da7dcc1 --- /dev/null +++ b/src/test/resources/freemarker/AssessmentUnit.ftl @@ -0,0 +1,58 @@ +{ + "title" : "${stock_name}", + "license_id": "${license_id}", + "description": "Short Name: ${short_name}\nGRSF Semantic Identifier: ${grsf_semantic_identifier}\nRecord URL: ${uri_resolver_base_url}/${grsf_uuid}", + "tags" : [ + <#list assessment_area as aa> + { + "name": "${aa}" + }, + + + { + "name": "${similarities_indicator}" + } + ], + "extras": [ + <#list assessment_area as aa> + { + "key": "stock_identity:Assessment Area", + "value": "${aa}" + }, + + + <#if connected??> + <#list connected as connected_record> + { + "key": "stock_identity:Connected Record", + "value": "${connected_record}" + }, + + + + <#list database_sources as database_source> + { + "key": "stock_identity:Database Source", + "value": "${database_source.name}" + }, + + + { + "key": "stock_identity:GRSF Stock Name", + "value": "${stock_name}" + }, + { + "key": "stock_identity:Short Name", + "value": "${short_name}" + }, + { + "key": "stock_identity:GRSF Semantic Identifier", + "value": "${grsf_semantic_identifier}" + }, + { + "key": "Record URL", + "value": "${uri_resolver_base_url}/${grsf_uuid}" + } + + ] +} \ No newline at end of file diff --git a/src/test/resources/freemarker/example.ftl b/src/test/resources/freemarker/example.ftl index 635e768..da7dcc1 100644 --- a/src/test/resources/freemarker/example.ftl +++ b/src/test/resources/freemarker/example.ftl @@ -1,17 +1,58 @@ { "title" : "${stock_name}", "license_id": "${license_id}", - "description": - "Short Name: ${short_name}\nGRSF Semantic Identifier: ${grsf_semantic_identifier}\nRecord URL: https://data.d4science.org/ctlg/GRSF_Admin/${grsf_uuid}", + "description": "Short Name: ${short_name}\nGRSF Semantic Identifier: ${grsf_semantic_identifier}\nRecord URL: ${uri_resolver_base_url}/${grsf_uuid}", "tags" : [ + <#list assessment_area as aa> + { + "name": "${aa}" + }, + + { "name": "${similarities_indicator}" } ], "extras": [ + <#list assessment_area as aa> + { + "key": "stock_identity:Assessment Area", + "value": "${aa}" + }, + + + <#if connected??> + <#list connected as connected_record> + { + "key": "stock_identity:Connected Record", + "value": "${connected_record}" + }, + + + + <#list database_sources as database_source> + { + "key": "stock_identity:Database Source", + "value": "${database_source.name}" + }, + + + { + "key": "stock_identity:GRSF Stock Name", + "value": "${stock_name}" + }, + { + "key": "stock_identity:Short Name", + "value": "${short_name}" + }, + { + "key": "stock_identity:GRSF Semantic Identifier", + "value": "${grsf_semantic_identifier}" + }, { "key": "Record URL", - "value": "https://data.d4science.org/ctlg/GRSF_Admin/${grsf_uuid}" - } + "value": "${uri_resolver_base_url}/${grsf_uuid}" + } + ] } \ No newline at end of file diff --git a/src/test/resources/new_profile_version/AssessmenUnit.json b/src/test/resources/new_profile_version/AssessmenUnit.json new file mode 100644 index 0000000..770f3a0 --- /dev/null +++ b/src/test/resources/new_profile_version/AssessmenUnit.json @@ -0,0 +1,14 @@ +{ + "globals" : { + "vars": [ + { + "name": "uri_resolver_base_url", + "value": "https://data.d4science.org/ctlg/GRSF_Admin" + } + ] + }, + "fields": [ + + + ] +} \ No newline at end of file