From 6265e62f1fefdb2dde1c9b17392771069b2ff60d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Garc=C3=ADa?= Date: Thu, 27 Apr 2023 16:13:48 +0200 Subject: [PATCH 1/2] GeoJSON output updates to specification --- .../index/converter/GeoJsonConverter.java | 45 +++++++++++++++---- .../geonet/index/model/geojson/Address.java | 24 ++++++++++ .../geonet/index/model/geojson/Contact.java | 33 ++++++++++++++ .../fao/geonet/index/model/geojson/Role.java | 20 +++++++++ 4 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Address.java create mode 100644 modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Contact.java create mode 100644 modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Role.java diff --git a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/GeoJsonConverter.java b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/GeoJsonConverter.java index 9f2c1ea6..d50b8cb5 100644 --- a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/GeoJsonConverter.java +++ b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/GeoJsonConverter.java @@ -12,13 +12,16 @@ import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; +import org.apache.commons.lang.StringUtils; import org.fao.geonet.index.JsonUtils; +import org.fao.geonet.index.model.geojson.Address; +import org.fao.geonet.index.model.geojson.Contact; import org.fao.geonet.index.model.geojson.Geometry; import org.fao.geonet.index.model.geojson.Link; import org.fao.geonet.index.model.geojson.Link.LinkBuilder; import org.fao.geonet.index.model.geojson.Record; import org.fao.geonet.index.model.geojson.Record.RecordBuilder; -import org.fao.geonet.index.model.gn.Contact; +import org.fao.geonet.index.model.geojson.Role; import org.fao.geonet.index.model.gn.IndexRecord; import org.fao.geonet.index.model.gn.IndexRecordFieldNames.CommonField; import org.fao.geonet.index.model.gn.ResourceDate; @@ -77,12 +80,12 @@ public Record convert(IndexRecord record) { // record updated if (record.getChangeDate() != null) { - geojsonRecord.getProperties().put("recordUpdated", record.getChangeDate()); + geojsonRecord.getProperties().put("updated", record.getChangeDate()); } // record created if (record.getCreateDate() != null) { - geojsonRecord.getProperties().put("recordCreated", record.getCreateDate()); + geojsonRecord.getProperties().put("created", record.getCreateDate()); } // title @@ -118,13 +121,37 @@ public Record convert(IndexRecord record) { } // providers - List providers = new ArrayList<>(); - for (Contact contact : record.getContact()) { - providers.add(String.format("%s, %s, %s", contact.getIndividual(), contact.getEmail(), - contact.getOrganisation())); - } + List recordContacts = new ArrayList<>(); + + record.getContact().stream().forEach(contact -> { + + Contact geojsonContact = Contact.builder() + .email(contact.getEmail()) + .phone(contact.getPhone()) + .address(Address.builder().deliveryPoint(List.of(contact.getAddress())).build()) + .build(); + + if (StringUtils.isNotEmpty(contact.getRole())) { + org.fao.geonet.index.model.geojson.Role.RoleBuilder roleBuilder = Role.builder().name(contact.getRole()); + + geojsonContact.setRoles(List.of(roleBuilder.build())); + } + + if (StringUtils.isNotEmpty(contact.getIndividual())) { + geojsonContact.setName(contact.getIndividual()); + if (StringUtils.isNotEmpty((contact.getOrganisation().get("default")))) { + geojsonContact.setOrganization(contact.getOrganisation().get("default")); + } + } else if (StringUtils.isNotEmpty((contact.getOrganisation().get("default")))) { + geojsonContact.setName(contact.getOrganisation().get("default")); + } + + recordContacts.add(geojsonContact); + + }); - geojsonRecord.getProperties().put("providers", providers); + // contacts + geojsonRecord.getProperties().put("contacts", recordContacts); // type geojsonRecord.getProperties() diff --git a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Address.java b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Address.java new file mode 100644 index 00000000..a9722be5 --- /dev/null +++ b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Address.java @@ -0,0 +1,24 @@ +package org.fao.geonet.index.model.geojson; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import java.util.List; + +@JsonInclude(Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +public class Address { + private List deliveryPoint; + private String city; + private String administrativeArea; + private String postalCode; + private String country; +} diff --git a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Contact.java b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Contact.java new file mode 100644 index 00000000..e203e7ef --- /dev/null +++ b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Contact.java @@ -0,0 +1,33 @@ +package org.fao.geonet.index.model.geojson; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import java.util.List; + +@JsonInclude(Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +public class Contact { + private String name; + private String positionName; + private String organization; + private Link logo; + private String phone; + private String email; + private Address address; + private List links; + // TODO: hoursOfService + private String contactInstructions; + private List roles; + + + +} diff --git a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Role.java b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Role.java new file mode 100644 index 00000000..3d0a2feb --- /dev/null +++ b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Role.java @@ -0,0 +1,20 @@ +package org.fao.geonet.index.model.geojson; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@JsonInclude(Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +public class Role { + private String name; + private String authority; +} From 082798a297e6afae09a49f31bc6c2cd75bbdd3e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Garc=C3=ADa?= Date: Wed, 16 Oct 2024 11:04:28 +0200 Subject: [PATCH 2/2] GeoJSON output updates to specification - Checkstyle fixes --- .../org/fao/geonet/index/converter/GeoJsonConverter.java | 5 +++-- .../java/org/fao/geonet/index/model/geojson/Address.java | 2 +- .../java/org/fao/geonet/index/model/geojson/Contact.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/GeoJsonConverter.java b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/GeoJsonConverter.java index d50b8cb5..bde6bdd0 100644 --- a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/GeoJsonConverter.java +++ b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/converter/GeoJsonConverter.java @@ -132,7 +132,8 @@ public Record convert(IndexRecord record) { .build(); if (StringUtils.isNotEmpty(contact.getRole())) { - org.fao.geonet.index.model.geojson.Role.RoleBuilder roleBuilder = Role.builder().name(contact.getRole()); + org.fao.geonet.index.model.geojson.Role.RoleBuilder roleBuilder = Role.builder() + .name(contact.getRole()); geojsonContact.setRoles(List.of(roleBuilder.build())); } @@ -143,7 +144,7 @@ public Record convert(IndexRecord record) { geojsonContact.setOrganization(contact.getOrganisation().get("default")); } } else if (StringUtils.isNotEmpty((contact.getOrganisation().get("default")))) { - geojsonContact.setName(contact.getOrganisation().get("default")); + geojsonContact.setName(contact.getOrganisation().get("default")); } recordContacts.add(geojsonContact); diff --git a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Address.java b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Address.java index a9722be5..7208e7b9 100644 --- a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Address.java +++ b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Address.java @@ -3,11 +3,11 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -import java.util.List; @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Contact.java b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Contact.java index e203e7ef..0e6be8df 100644 --- a/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Contact.java +++ b/modules/library/common-index-model/src/main/java/org/fao/geonet/index/model/geojson/Contact.java @@ -3,11 +3,11 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -import java.util.List; @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true)