Skip to content

Commit

Permalink
GeoJSON output updates to specification
Browse files Browse the repository at this point in the history
  • Loading branch information
josegar74 committed Apr 27, 2023
1 parent be4c7da commit 6265e62
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -118,13 +121,37 @@ public Record convert(IndexRecord record) {
}

// providers
List<String> providers = new ArrayList<>();
for (Contact contact : record.getContact()) {
providers.add(String.format("%s, %s, %s", contact.getIndividual(), contact.getEmail(),
contact.getOrganisation()));
}
List<Contact> 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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> deliveryPoint;
private String city;
private String administrativeArea;
private String postalCode;
private String country;
}
Original file line number Diff line number Diff line change
@@ -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<Link> links;
// TODO: hoursOfService
private String contactInstructions;
private List<Role> roles;



}
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 6265e62

Please sign in to comment.