diff --git a/pom.xml b/pom.xml index 3ea14a3c3..532e846d1 100755 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ opensrp-server-core jar - 2.11.1-SNAPSHOT + 2.11.2-SNAPSHOT opensrp-server-core OpenSRP Server Core module https://github.com/OpenSRP/opensrp-server-core diff --git a/src/main/java/org/opensrp/repository/LocationRepository.java b/src/main/java/org/opensrp/repository/LocationRepository.java index 628764081..3e3bf6a5b 100644 --- a/src/main/java/org/opensrp/repository/LocationRepository.java +++ b/src/main/java/org/opensrp/repository/LocationRepository.java @@ -38,7 +38,7 @@ public interface LocationRepository extends BaseRepository, Lo * This methods searches for jurisdictions using the parentId and location properties * It returns the Geometry optionally if @param returnGeometry is set to true. * @param returnGeometry boolean which controls if geometry is returned - * @param parentId string the parent id of the jurisdiction being searched + * @param parentId string the parent id of the jurisdiction being searched. If empty search for ROOT location. * @param properties map of location properties to filter with, each entry in map has property name and value * @return jurisdictions matching the params */ diff --git a/src/main/java/org/opensrp/repository/postgres/LocationRepositoryImpl.java b/src/main/java/org/opensrp/repository/postgres/LocationRepositoryImpl.java index fb0a01068..7e9ee0ea1 100644 --- a/src/main/java/org/opensrp/repository/postgres/LocationRepositoryImpl.java +++ b/src/main/java/org/opensrp/repository/postgres/LocationRepositoryImpl.java @@ -356,7 +356,7 @@ public Collection findStructureAndFamilyDetails(double latitud public List findLocationsByProperties(boolean returnGeometry, String parentId, Map properties) { LocationMetadataExample locationMetadataExample = new LocationMetadataExample(); - if (StringUtils.isNotBlank(parentId)) { + if (parentId != null) { locationMetadataExample.createCriteria().andParentIdEqualTo(parentId); } List locations = locationMetadataMapper.selectManyByProperties(locationMetadataExample, properties, diff --git a/src/main/java/org/opensrp/util/LocalDateDeserializer.java b/src/main/java/org/opensrp/util/LocalDateDeserializer.java index 991a4b410..ed1b92c61 100644 --- a/src/main/java/org/opensrp/util/LocalDateDeserializer.java +++ b/src/main/java/org/opensrp/util/LocalDateDeserializer.java @@ -5,7 +5,6 @@ import org.joda.time.LocalDate; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; @@ -19,8 +18,7 @@ public LocalDateDeserializer() { } @Override - public LocalDate deserialize(JsonParser jsonParser, DeserializationContext ctxt) - throws IOException, JsonProcessingException { + public LocalDate deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException { JsonToken currentToken = jsonParser.getCurrentToken(); if (currentToken == JsonToken.VALUE_STRING) { String dateTimeAsString = jsonParser.getText().trim(); diff --git a/src/test/java/org/opensrp/util/LocalDateDeserializerTest.java b/src/test/java/org/opensrp/util/LocalDateDeserializerTest.java new file mode 100644 index 000000000..aa8ea1f33 --- /dev/null +++ b/src/test/java/org/opensrp/util/LocalDateDeserializerTest.java @@ -0,0 +1,26 @@ +package org.opensrp.util; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import java.io.IOException; + +public class LocalDateDeserializerTest { + + @Test + public void testDeserializer() throws IOException { + LocalDateDeserializer localDateDeserializer = new LocalDateDeserializer(); + DeserializationContext context = Mockito.mock(DeserializationContext.class); + JsonParser jsonParser = Mockito.mock(JsonParser.class); + Mockito.doReturn(JsonToken.VALUE_STRING).when(jsonParser).getCurrentToken(); + Mockito.doReturn("2021-05-21").when(jsonParser).getText(); + Assert.assertNotNull(localDateDeserializer.deserialize(jsonParser, context)); + Mockito.doReturn(null).when(jsonParser).getCurrentToken(); + Assert.assertNull(localDateDeserializer.deserialize(jsonParser, context)); + + } +} diff --git a/src/test/java/org/opensrp/util/LocalDateSerializerTest.java b/src/test/java/org/opensrp/util/LocalDateSerializerTest.java new file mode 100644 index 000000000..718b07fb2 --- /dev/null +++ b/src/test/java/org/opensrp/util/LocalDateSerializerTest.java @@ -0,0 +1,24 @@ +package org.opensrp.util; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import org.joda.time.LocalDate; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; + +import java.io.IOException; + +public class LocalDateSerializerTest { + + @Test + public void testSerializer() throws IOException { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(String.class); + LocalDate localDate = new LocalDate(); + LocalDateSerializer localDateSerializer = new LocalDateSerializer(); + SerializerProvider provider = Mockito.mock(SerializerProvider.class); + JsonGenerator jsonGen = Mockito.mock(JsonGenerator.class); + localDateSerializer.serialize(localDate, jsonGen, provider); + Mockito.verify(jsonGen, Mockito.atLeastOnce()).writeString(argumentCaptor.capture()); + } +}