Implementing FreeMarker solution
This commit is contained in:
parent
cf89cb3fc1
commit
07ce42c4bf
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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}"
|
||||
},
|
||||
</#list>
|
||||
|
||||
{
|
||||
"name": "${similarities_indicator}"
|
||||
}
|
||||
],
|
||||
"extras": [
|
||||
<#list assessment_area as aa>
|
||||
{
|
||||
"key": "stock_identity:Assessment Area",
|
||||
"value": "${aa}"
|
||||
},
|
||||
</#list>
|
||||
|
||||
<#if connected??>
|
||||
<#list connected as connected_record>
|
||||
{
|
||||
"key": "stock_identity:Connected Record",
|
||||
"value": "${connected_record}"
|
||||
},
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
<#list database_sources as database_source>
|
||||
{
|
||||
"key": "stock_identity:Database Source",
|
||||
"value": "${database_source.name}"
|
||||
},
|
||||
</#list>
|
||||
|
||||
{
|
||||
"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}"
|
||||
}
|
||||
|
||||
]
|
||||
}
|
|
@ -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}"
|
||||
},
|
||||
</#list>
|
||||
|
||||
{
|
||||
"name": "${similarities_indicator}"
|
||||
}
|
||||
],
|
||||
"extras": [
|
||||
<#list assessment_area as aa>
|
||||
{
|
||||
"key": "stock_identity:Assessment Area",
|
||||
"value": "${aa}"
|
||||
},
|
||||
</#list>
|
||||
|
||||
<#if connected??>
|
||||
<#list connected as connected_record>
|
||||
{
|
||||
"key": "stock_identity:Connected Record",
|
||||
"value": "${connected_record}"
|
||||
},
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
<#list database_sources as database_source>
|
||||
{
|
||||
"key": "stock_identity:Database Source",
|
||||
"value": "${database_source.name}"
|
||||
},
|
||||
</#list>
|
||||
|
||||
{
|
||||
"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}"
|
||||
}
|
||||
|
||||
]
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"globals" : {
|
||||
"vars": [
|
||||
{
|
||||
"name": "uri_resolver_base_url",
|
||||
"value": "https://data.d4science.org/ctlg/GRSF_Admin"
|
||||
}
|
||||
]
|
||||
},
|
||||
"fields": [
|
||||
|
||||
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue