Skip to content

Commit

Permalink
Merge pull request #127 from aodn/bugs/5768-cache-result-on-flooding-…
Browse files Browse the repository at this point in the history
…call

Fix one more null pointer
  • Loading branch information
HavierD authored Sep 2, 2024
2 parents eb3bddc + b1f3869 commit 1294de4
Show file tree
Hide file tree
Showing 4 changed files with 2,040 additions and 16 deletions.
39 changes: 23 additions & 16 deletions indexer/src/main/java/au/org/aodn/esindexer/utils/GeometryBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import static au.org.aodn.esindexer.utils.CommonUtils.safeGet;

public class GeometryBase {

protected static Logger logger = LogManager.getLogger(GeometryBase.class);
Expand Down Expand Up @@ -106,7 +108,7 @@ protected static List<Geometry> findPolygonsFromEXBoundingPolygonType(String raw
// 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[0]));
polygons.add(polygon);
logger.debug("2D Polygon added {}", polygon);
logger.debug("MultiSurfaceType 2D Polygon added {}", polygon);
}
}
}
Expand All @@ -116,21 +118,26 @@ protected static List<Geometry> findPolygonsFromEXBoundingPolygonType(String raw
// 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() != null && 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[0]));
polygons.add(polygon);

logger.debug("2D Polygon added {}", polygon);
}
safeGet(linearRingType::getPosList)
.ifPresent(pos -> {
// Assume 2D if not present
Double dimension = safeGet(() -> pos.getSrsDimension().doubleValue()).orElse(2.0);
// TODO: Handle 2D now, can be 3D
if (dimension == 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[0]));
polygons.add(polygon);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,24 @@ public void verifyTitleFreeThemes() throws IOException {
"Stac not equals for sample14"
);
}
/**
* During polygon construction, there are times that the XML do not provide the proper dimension, 2D or 3D.
* We assume it is 2D by default and here is the test case for that.
*
* @throws IOException - Do not expect to throw
*/
@Test
public void verifyPolygonMissingDimensionAttributeWorks() throws IOException {
String xml = readResourceFile("classpath:canned/sample15.xml");
String expected = readResourceFile("classpath:canned/sample15_stac.json");
indexerService.indexMetadata(xml);

Map<?,?> content = objectMapper.readValue(lastRequest.get().document().toString(), Map.class);
String out = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(content);
Assertions.assertEquals(
objectMapper.readTree(expected),
objectMapper.readTree(out.strip()),
"Stac not equals for sample15"
);
}
}
Loading

0 comments on commit 1294de4

Please sign in to comment.