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..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 @@ -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,38 @@ 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..7208e7b9 --- /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 java.util.List; +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 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..0e6be8df --- /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 java.util.List; +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 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; +}