Skip to content

Commit

Permalink
Allow search location properties by empty parentId (#465)
Browse files Browse the repository at this point in the history
* Allow search location properties by empty parentId

* Test LocalDate serializer and deserializer
  • Loading branch information
ellykits authored May 21, 2021
1 parent 0145688 commit 9b9b4d8
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<artifactId>opensrp-server-core</artifactId>
<packaging>jar</packaging>
<version>2.11.1-SNAPSHOT</version>
<version>2.11.2-SNAPSHOT</version>
<name>opensrp-server-core</name>
<description>OpenSRP Server Core module</description>
<url>https://github.com/OpenSRP/opensrp-server-core</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface LocationRepository extends BaseRepository<PhysicalLocation>, 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public Collection<StructureDetails> findStructureAndFamilyDetails(double latitud
public List<PhysicalLocation> findLocationsByProperties(boolean returnGeometry, String parentId,
Map<String, String> properties) {
LocationMetadataExample locationMetadataExample = new LocationMetadataExample();
if (StringUtils.isNotBlank(parentId)) {
if (parentId != null) {
locationMetadataExample.createCriteria().andParentIdEqualTo(parentId);
}
List<Location> locations = locationMetadataMapper.selectManyByProperties(locationMetadataExample, properties,
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/opensrp/util/LocalDateDeserializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/opensrp/util/LocalDateDeserializerTest.java
Original file line number Diff line number Diff line change
@@ -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));

}
}
24 changes: 24 additions & 0 deletions src/test/java/org/opensrp/util/LocalDateSerializerTest.java
Original file line number Diff line number Diff line change
@@ -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<String> 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());
}
}

0 comments on commit 9b9b4d8

Please sign in to comment.