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

Fix one more null pointer #127

Merged
merged 2 commits into from
Sep 2, 2024
Merged
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
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,19 @@ public void verifyTitleFreeThemes() throws IOException {
"Stac not equals for sample14"
);
}

@Test
public void verifyWorks() throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you make the test method name more meaningful? such as verifyFindPolygonWorks so that others know easily what this test case is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done please check

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
Loading