Skip to content

Commit

Permalink
Merge pull request #27 from aodn/data-origin
Browse files Browse the repository at this point in the history
Ingest provider data
  • Loading branch information
vietnguyengit authored Nov 15, 2023
2 parents fd75a91 + ff46ee3 commit 7e41f97
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 39 deletions.
15 changes: 15 additions & 0 deletions src/main/java/au/org/aodn/esindexer/model/ProviderModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package au.org.aodn.esindexer.model;

import lombok.Builder;
import lombok.Data;

import java.util.List;

@Data
@Builder
public class ProviderModel {
protected String name;
protected String description;
protected List<String> roles;
protected String url;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class StacCollectionModel {
protected List<LanguageModel> languages;
protected List<LinkModel> links;
protected String license;
protected ProviderModel provider;

@JsonProperty("stac_version")
public String getStacVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public abstract class StacCollectionMapperServiceImpl implements StacCollectionM
@Mapping(target="languages", source = "source", qualifiedByName = "mapLanguages")
@Mapping(target="links", source = "source", qualifiedByName = "mapLinks")
@Mapping(target="license", source = "source", qualifiedByName = "mapLicense")
@Mapping(target="provider", source = "source", qualifiedByName = "mapProvider")
public abstract StacCollectionModel mapToSTACCollection(MDMetadataType source);

private static final Logger logger = LoggerFactory.getLogger(StacCollectionMapperServiceImpl.class);
Expand Down Expand Up @@ -382,6 +383,34 @@ List<LinkModel> mapLinks(MDMetadataType source) {
return results;
}

// TODO: need to handle exception
@Named("mapProvider")
ProviderModel mapProvider(MDMetadataType source) {
ProviderModel providerModel = ProviderModel.builder().build();

source.getContact().forEach(item -> {
if (item.getAbstractResponsibility().getValue() instanceof CIResponsibilityType2 ciResponsibility) {
providerModel.setRoles(Collections.singletonList(ciResponsibility.getRole().getCIRoleCode().getCodeListValue()));
ciResponsibility.getParty().forEach(party -> {
try {
CIOrganisationType2 organisationType2 = (CIOrganisationType2) party.getAbstractCIParty().getValue();
providerModel.setName(organisationType2.getName().getCharacterString().getValue().toString());
organisationType2.getIndividual().forEach(individual -> {
individual.getCIIndividual().getContactInfo().forEach(contactInfo -> {
contactInfo.getCIContact().getOnlineResource().forEach(onlineResource -> {
providerModel.setUrl(onlineResource.getCIOnlineResource().getLinkage().getCharacterString().getValue().toString());
});
});
});
} catch (ClassCastException e) {
logger.error("Unable to cast getAbstractCIParty().getValue() to CIOrganisationType2 for metadata record: " + this.mapUUID(source));
}
});
}
});
return providerModel;
}

@Named("mapLicense")
String mapLicense(MDMetadataType source) {
List<MDDataIdentificationType> items = findMDDataIdentificationType(source);
Expand Down
82 changes: 43 additions & 39 deletions src/main/java/au/org/aodn/esindexer/utils/GeometryBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,53 +60,57 @@ public static List<Polygon> findPolygonsFromEXBoundingPolygonType(String rawCRS,

for (List<GMObjectPropertyType> i : input) {
for (GMObjectPropertyType t : i) {
AbstractGeometryType type = t.getAbstractGeometry().getValue();

// TODO: fix here more cases
if (type instanceof MultiSurfaceType mst) {
for (SurfacePropertyType j : mst.getSurfaceMember()) {
// TODO: Only process Polygon for now.
if (j.getAbstractSurface().getValue() instanceof PolygonType polygonType) {
// TODO: Only process LinearRingType for now
if (polygonType.getExterior() != null && polygonType.getExterior().getAbstractRing().getValue() instanceof LinearRingType linearRingType) {
// TODO: Handle 2D now, can be 3D
if (linearRingType.getPosList().getSrsDimension().doubleValue() == 2.0) {
List<Double> v = linearRingType.getPosList().getValue();
List<Coordinate> items = new ArrayList<>();

for (int z = 0; z < v.size(); z += 2) {
items.add(new Coordinate(v.get(z), v.get(z + 1)));
}

// We need to store it so that we can create the multi-array as told by spec
Polygon polygon = geoJsonFactory.createPolygon(items.toArray(new Coordinate[items.size()]));
polygons.add(polygon);
logger.debug("2D Polygon added {}", polygon);
if (t.getAbstractGeometry() != null) {
AbstractGeometryType type = t.getAbstractGeometry().getValue();

// TODO: fix here more cases
if (type instanceof MultiSurfaceType mst) {
for (SurfacePropertyType j : mst.getSurfaceMember()) {
// TODO: Only process Polygon for now.
if (j.getAbstractSurface().getValue() instanceof PolygonType polygonType) {
// TODO: Only process LinearRingType for now
if (polygonType.getExterior() != null && polygonType.getExterior().getAbstractRing().getValue() instanceof LinearRingType linearRingType) {
// TODO: Handle 2D now, can be 3D
if (linearRingType.getPosList().getSrsDimension().doubleValue() == 2.0) {
List<Double> v = linearRingType.getPosList().getValue();
List<Coordinate> items = new ArrayList<>();

for (int z = 0; z < v.size(); z += 2) {
items.add(new Coordinate(v.get(z), v.get(z + 1)));
}

// We need to store it so that we can create the multi-array as told by spec
Polygon polygon = geoJsonFactory.createPolygon(items.toArray(new Coordinate[items.size()]));
polygons.add(polygon);
logger.debug("2D Polygon added {}", polygon);
}
}
}
}
}
} else if (type instanceof PolygonType plt) {
// TODO: Only process LinearRingType for now
// Set the coor system for the factory
// CoordinateReferenceSystem system = CRS.decode(mst.getSrsName().trim(), true);
if (plt.getExterior() != null && plt.getExterior().getAbstractRing().getValue() instanceof LinearRingType linearRingType) {
// TODO: Handle 2D now, can be 3D
if (linearRingType.getPosList().getSrsDimension().doubleValue() == 2.0) {
List<Double> v = linearRingType.getPosList().getValue();
List<Coordinate> items = new ArrayList<>();

for (int z = 0; z < v.size(); z += 2) {
items.add(new Coordinate(v.get(z), v.get(z + 1)));
}
} else if (type instanceof PolygonType plt) {
// TODO: Only process LinearRingType for now
// Set the coor system for the factory
// CoordinateReferenceSystem system = CRS.decode(mst.getSrsName().trim(), true);
if (plt.getExterior() != null && plt.getExterior().getAbstractRing().getValue() instanceof LinearRingType linearRingType) {
// TODO: Handle 2D now, can be 3D
if (linearRingType.getPosList().getSrsDimension().doubleValue() == 2.0) {
List<Double> v = linearRingType.getPosList().getValue();
List<Coordinate> items = new ArrayList<>();

for (int z = 0; z < v.size(); z += 2) {
items.add(new Coordinate(v.get(z), v.get(z + 1)));
}

// We need to store it so that we can create the multi-array as told by spec
Polygon polygon = geoJsonFactory.createPolygon(items.toArray(new Coordinate[items.size()]));
polygons.add(polygon);
// We need to store it so that we can create the multi-array as told by spec
Polygon polygon = geoJsonFactory.createPolygon(items.toArray(new Coordinate[items.size()]));
polygons.add(polygon);

logger.debug("2D Polygon added {}", polygon);
logger.debug("2D Polygon added {}", polygon);
}
}
}

}
}
}
Expand Down

0 comments on commit 7e41f97

Please sign in to comment.