Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeoJSON output updates to specification #77

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}