diff --git a/catalogue-binding-plugin/src/test/java/geoportal_to_catalogue/GeoportalToCatalogue.java b/catalogue-binding-plugin/src/test/java/geoportal_to_catalogue/GeoportalToCatalogue.java index 68d3500..c8c6922 100644 --- a/catalogue-binding-plugin/src/test/java/geoportal_to_catalogue/GeoportalToCatalogue.java +++ b/catalogue-binding-plugin/src/test/java/geoportal_to_catalogue/GeoportalToCatalogue.java @@ -37,7 +37,7 @@ import test.TestContextConfig; public class GeoportalToCatalogue { public final static String profileID = "profiledConcessioni"; - public final static String projectID = "66714cdea08b3011b506e089"; + public final static String projectID = "66697afda08b3011b506ddb6"; public static void main(String[] args) { @@ -52,7 +52,8 @@ public class GeoportalToCatalogue { Project theProject = clientProjects.getProjectByID(profileID, projectID); Document asDocument = Serialization.asDocument(theProject); - //System.out.println(prettyPrintUsingGson(asDocument.toJson())); + System.out.println("Source JSON:"); + System.out.println(prettyPrintUsingGson(asDocument.toJson())); applyMappingToCatalogue(asDocument.toJson()); } catch (Exception e) { @@ -105,32 +106,36 @@ public class GeoportalToCatalogue { String toCatalogueJSON = stringWriter.toString(); System.out.println("\n\ntoCatalogueString:" + toCatalogueJSON); - - //System.out.println(prettyPrintUsingGson(toCatalogueJSON)); + System.out.println("\nPretty printing 1"); + System.out.println(prettyPrintUsingGson(toCatalogueJSON)); com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() .jsonProvider(new JsonOrgJsonProvider()).build(); + //GIS LINK + JSONObject theRootDocument = JSONObjectOrdered.instance(); - theRootDocument.put("key", "Gis Link"); - theRootDocument.put("value", "https://data.dev.d4science.org"); - - System.out.println("gis link: "+theRootDocument); - - DocumentContext theDoc = JsonPath.parse(toCatalogueJSON,configuration); + theRootDocument.put("key", "Gis Link"); + theRootDocument.put("value", "https://data.dev.d4science.org/test/my_gis_link"); + + System.out.println("gis link: " + theRootDocument); + + DocumentContext theDoc = JsonPath.parse(toCatalogueJSON, configuration); theDoc.add("$.extras", theRootDocument); - + System.out.println("\n\nTo pretty print JSON:"); - //System.out.println("gis link: "+theDoc.jsonString()); + // System.out.println("gis link: "+theDoc.jsonString()); System.out.println(prettyPrintUsingGson(theDoc.jsonString())); + } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TemplateException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (JSONException e) { + } + catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } diff --git a/catalogue-binding-plugin/src/test/java/geoportal_to_catalogue/d4gna_to_catalogue_template.ftl b/catalogue-binding-plugin/src/test/java/geoportal_to_catalogue/d4gna_to_catalogue_template.ftl index 9ce045f..d84b96c 100644 --- a/catalogue-binding-plugin/src/test/java/geoportal_to_catalogue/d4gna_to_catalogue_template.ftl +++ b/catalogue-binding-plugin/src/test/java/geoportal_to_catalogue/d4gna_to_catalogue_template.ftl @@ -151,6 +151,16 @@ Starting document mapping to Catalogue +<#-- Mapping first "Immagine Rappresentativa" as resource --> +<#if theDocument.immaginiRappresentative?? && theDocument.immaginiRappresentative[0]?? && theDocument.immaginiRappresentative[0].fileset?? && theDocument.immaginiRappresentative[0].fileset._payloads??> +<#assign payloads = theDocument.immaginiRappresentative[0].fileset._payloads> +<#if payloads?size!=0> +<#-- Getting the first payload --> +<#assign payload = payloads[0]> +<@assignResource name=payload._name url=payload._link description=theDocument.immaginiRappresentative[0].didascalia format=payload._mimetype> + + + <#-- Building Resources --> <@buildResources the_resources=resources> @@ -182,8 +192,8 @@ Starting document mapping to Catalogue <#-- Mapping the year of the "dataInizioProgetto" as group --> <#assign dateString = theDocument.dataInizioProgetto?trim> -<#assign year = dateString?split("-")[0]> -<@assignGroup in_groups=year> +<#assign dataInizioYear = dateString?split("-")[0]> +<#-- <@assignGroup in_groups=dataInizioYear> --> <#-- Building groups --> <@buildGroups the_groups=groups> @@ -230,16 +240,31 @@ Starting document mapping to Catalogue <#if theDocument.cronologiaMacrofase??> -<@assignExtraField key="Cronologia (Macrofase)" value=theDocument.cronologiaMacrofase asObject=false> +<#if theDocument.cronologiaMacrofase?is_sequence> + <#list theDocument.cronologiaMacrofase as my_extra> + <@assignExtraField key="Cronologia (Macrofase)" value=my_extra asObject=false> + + <#else> + <@assignExtraField key="Cronologia (Macrofase)" value=theDocument.cronologiaMacrofase asObject=false> + <#-- spatial field --> <#if jsonProj._identificationReferences?? && jsonProj._identificationReferences?size!=0 && jsonProj._identificationReferences[0].geoJSON??> <#assign geoJSON = jsonProj._identificationReferences[0].geoJSON> -<#assign spatialField = '{\\"type\\": \\"${geoJSON.type}\\", \\"coordinates\\": [${geoJSON.coordinates?join(", ")}]}'> +<#if geoJSON.coordinates?? && geoJSON.coordinates?is_sequence && geoJSON.coordinates?size gt 2> +<#assign point_Coordinates = [geoJSON.coordinates[0], geoJSON.coordinates[1]]> +<#assign spatialField = '{\\"type\\": \\"${geoJSON.type}\\", \\"coordinates\\": [${point_Coordinates?join(", ")}]}'> <@assignExtraField key="spatial" value=spatialField asObject=false> + + + +<#-- Adding extra field "Anno" to add it as group --> +<@assignExtraField key="Anno" value=dataInizioYear asObject=false> + + <#-- system:type --> <@assignExtraField key="system:type" value="D4GNA" asObject=true> <@buildExtrasFields the_extras=extras>