Skip to content
Snippets Groups Projects
Commit 256d5739 authored by Neelesh Thakur's avatar Neelesh Thakur
Browse files

Merge branch 'BUG_7154' into 'master'

Indexer skipped the entire record with malformed SpatialLocation

See merge request !332
parents c1313fb2 3e61e859
Branches
Tags
2 merge requests!378No more retry attempts for schema not found,!332Indexer skipped the entire record with malformed SpatialLocation
Pipeline #122331 failed
......@@ -18,9 +18,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.opengroup.osdu.indexer.model.geojson.jackson.PositionDeserializer;
import org.opengroup.osdu.indexer.model.geojson.jackson.PositionSerializer;
......
......@@ -14,6 +14,7 @@
package org.opengroup.osdu.indexer.model.geojson.jackson;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
......@@ -39,6 +40,11 @@ public class FeatureCollectionDeserializer extends JsonDeserializer<FeatureColle
ObjectCodec codec = jsonParser.getCodec();
JsonNode featureCollection = codec.readTree(jsonParser);
JsonNode features = featureCollection.get("features");
if(features == null){
throw new JsonParseException(jsonParser, "Missing feature field in the ");
}
final List<Feature> result = new ArrayList<>();
for (JsonNode node : features) {
result.add(codec.treeToValue(node, Feature.class));
......
......@@ -14,6 +14,7 @@
package org.opengroup.osdu.indexer.util.parser;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -42,6 +43,8 @@ public class GeoShapeParser {
});
} catch (InvalidTypeIdException e) {
throw new IllegalArgumentException("must be a valid FeatureCollection");
} catch (JsonParseException e){
throw new IllegalArgumentException(e.getMessage());
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("unable to parse FeatureCollection");
}
......
......@@ -34,6 +34,7 @@ import java.util.function.Function;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
@RunWith(SpringRunner.class)
public class GeoShapeParserTest {
......@@ -178,6 +179,16 @@ public class GeoShapeParserTest {
this.validateInput(this.sut::parseGeoJson, shapeJson, expectedParsedShape, Strings.EMPTY);
}
@Test
public void should_throwException_parseInvalidFeatureCollection() {
String shapeJson = getGeoShapeFromFile("input/invalid_feature_collection.json");
Type type = new TypeToken<Map<String, Object>>() {}.getType();
Map<String, Object> shapeObj = new Gson().fromJson(shapeJson, type);
assertThrows(IllegalArgumentException.class, () -> this.sut.parseGeoJson(shapeObj));
}
private void validateInput(Function<Map<String, Object>, Map<String, Object>> parser, String shapeJson, String expectedParsedShape, String errorMessage) {
try {
Type type = new TypeToken<Map<String, Object>>() {}.getType();
......
{
"type": "FeatureCollection",
"featur3es": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-105.01621,
39.57422
]
}
}
]
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment