implementing test code for mapping d4gna project to catalogue item
This commit is contained in:
parent
0ae2c3895d
commit
fca972e68c
|
@ -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");
|
||||
theRootDocument.put("key", "Gis Link");
|
||||
theRootDocument.put("value", "https://data.dev.d4science.org/test/my_gis_link");
|
||||
|
||||
System.out.println("gis link: "+theRootDocument);
|
||||
System.out.println("gis link: " + theRootDocument);
|
||||
|
||||
DocumentContext theDoc = JsonPath.parse(toCatalogueJSON,configuration);
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -151,6 +151,16 @@ Starting document mapping to Catalogue
|
|||
</#if>
|
||||
</#if>
|
||||
|
||||
<#-- 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></@assignResource>
|
||||
</#if>
|
||||
</#if>
|
||||
|
||||
<#-- Building Resources -->
|
||||
<@buildResources the_resources=resources></@buildResources>
|
||||
|
||||
|
@ -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></@assignGroup>
|
||||
<#assign dataInizioYear = dateString?split("-")[0]>
|
||||
<#-- <@assignGroup in_groups=dataInizioYear></@assignGroup> -->
|
||||
<#-- Building groups -->
|
||||
<@buildGroups the_groups=groups></@buildGroups>
|
||||
|
||||
|
@ -230,16 +240,31 @@ Starting document mapping to Catalogue
|
|||
</#if>
|
||||
|
||||
<#if theDocument.cronologiaMacrofase??>
|
||||
<@assignExtraField key="Cronologia (Macrofase)" value=theDocument.cronologiaMacrofase asObject=false></@assignExtraField>
|
||||
<#if theDocument.cronologiaMacrofase?is_sequence>
|
||||
<#list theDocument.cronologiaMacrofase as my_extra>
|
||||
<@assignExtraField key="Cronologia (Macrofase)" value=my_extra asObject=false></@assignExtraField>
|
||||
</#list>
|
||||
<#else>
|
||||
<@assignExtraField key="Cronologia (Macrofase)" value=theDocument.cronologiaMacrofase asObject=false></@assignExtraField>
|
||||
</#if>
|
||||
</#if>
|
||||
|
||||
<#-- 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></@assignExtraField>
|
||||
</#if>
|
||||
|
||||
</#if>
|
||||
|
||||
|
||||
<#-- Adding extra field "Anno" to add it as group -->
|
||||
<@assignExtraField key="Anno" value=dataInizioYear asObject=false></@assignExtraField>
|
||||
|
||||
|
||||
<#-- system:type -->
|
||||
<@assignExtraField key="system:type" value="D4GNA" asObject=true></@assignExtraField>
|
||||
<@buildExtrasFields the_extras=extras></@buildExtrasFields>
|
||||
|
|
Loading…
Reference in New Issue