Skip to content

Commit

Permalink
Merge pull request #838 from opensrp/830-add-limit-and-metadata-version
Browse files Browse the repository at this point in the history
830 : Add limit and metadata version params in v2 settings get end-point
  • Loading branch information
rehammuzzamil authored Jun 8, 2021
2 parents 2cc88fe + 2bc8d04 commit f36a158
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<artifactId>opensrp-server-web</artifactId>
<packaging>war</packaging>
<version>2.8.5-SNAPSHOT</version>
<version>2.8.6-SNAPSHOT</version>
<name>opensrp-server-web</name>
<description>OpenSRP Server Web Application</description>
<url>https://github.com/OpenSRP/opensrp-server-web</url>
Expand All @@ -26,7 +26,7 @@
<redis.lettuce.version>5.2.2.RELEASE</redis.lettuce.version>
<opensrp.updatePolicy>always</opensrp.updatePolicy>
<nexus-staging-maven-plugin.version>1.5.1</nexus-staging-maven-plugin.version>
<opensrp.core.version>2.11.4-SNAPSHOT</opensrp.core.version>
<opensrp.core.version>2.11.5-SNAPSHOT</opensrp.core.version>
<opensrp.connector.version>2.3.0-SNAPSHOT</opensrp.connector.version>
<opensrp.interface.version>2.0.1-SNAPSHOT</opensrp.interface.version>
<opensrp.common.version>2.0.3-SNAPSHOT</opensrp.common.version>
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/org/opensrp/web/rest/v2/SettingResource.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

import javax.servlet.http.HttpServletRequest;

import static org.opensrp.web.Constants.LIMIT;

@Controller("settingResourceV2")
@RequestMapping(value = Constants.RestEndpointUrls.SETTINGS_V2_URL)
public class SettingResource {
Expand All @@ -50,6 +52,8 @@ public class SettingResource {

public static final String SETTING_IDENTIFIER = "identifier";

public static final String METADATA_VERSION = "metadata_version";

public static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.registerTypeAdapter(DateTime.class, new DateTimeTypeConverter()).create();

Expand Down Expand Up @@ -110,25 +114,40 @@ public ResponseEntity<String> getAllSettings(HttpServletRequest request) {
String teamId = RestUtils.getStringFilter(AllConstants.Event.TEAM_ID, request);
String identifier = RestUtils.getStringFilter(SETTING_IDENTIFIER, request);
boolean resolveSettings = RestUtils.getBooleanFilter(AllConstants.Event.RESOLVE_SETTINGS, request);
String metadataVersion = RestUtils.getStringFilter(METADATA_VERSION, request);
String limit = RestUtils.getStringFilter(LIMIT, request);
Map<String, TreeNode<String, Location>> treeNodeHashMap = null;

if (StringUtils.isBlank(team) && StringUtils.isBlank(providerId) && StringUtils.isBlank(locationId)
&& StringUtils.isBlank(teamId) && StringUtils.isBlank(team) && StringUtils.isBlank(serverVersion)) {
&& StringUtils.isBlank(teamId) && StringUtils.isBlank(team) && StringUtils.isBlank(serverVersion)
&& StringUtils.isBlank(metadataVersion)) {
return new ResponseEntity<>("All parameters cannot be null for this endpoint",
RestUtils.getJSONUTF8Headers(), HttpStatus.BAD_REQUEST);
}

long lastSyncedServerVersion = 0L;
long lastMetadataVersion = 0L;
int pageLimit = 0;
if (StringUtils.isNotBlank(serverVersion)) {
lastSyncedServerVersion = Long.parseLong(serverVersion) + 1;
}

if (StringUtils.isNotBlank(metadataVersion)) {
lastMetadataVersion = Long.parseLong(metadataVersion);
}

if (StringUtils.isNotBlank(limit)) {
pageLimit = Integer.parseInt(limit);
}

SettingSearchBean settingQueryBean = new SettingSearchBean();
settingQueryBean.setTeam(team);
settingQueryBean.setTeamId(teamId);
settingQueryBean.setProviderId(providerId);
settingQueryBean.setLocationId(locationId);
settingQueryBean.setServerVersion(lastSyncedServerVersion);
settingQueryBean.setMetadataVersion(lastMetadataVersion);
settingQueryBean.setLimit(pageLimit);
if (StringUtils.isNotBlank(identifier)) {
settingQueryBean.setIdentifier(identifier);
}
Expand Down
10 changes: 9 additions & 1 deletion src/test/java/org/opensrp/web/rest/v2/SettingResourceTest.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import java.util.ArrayList;
import java.util.List;

import static org.opensrp.web.Constants.LIMIT;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = TestWebContextLoader.class, locations = { "classpath:test-webmvc-config.xml", })
@ActiveProfiles(profiles = { "jedis", "postgres", "basic_auth" })
Expand Down Expand Up @@ -69,6 +71,7 @@ public class SettingResourceTest {
private final String locationTreeString = "{\"locationsHierarchy\":{\"map\":{\"02ebbc84-5e29-4cd5-9b79-c594058923e9\":{\"id"
+ "\":\"02ebbc84-5e29-4cd5-9b79-c594058923e9\",\"label\":\"Uganda\",\"node\":{\"locationId\":\"02ebbc84-5e29-4cd5-9b79-c594058923e9\",\"name\":\"Uganda\",\"tags\":[\"Country\"],\"voided\":false},\"children\":{\"8340315f-48e4-4768-a1ce-414532b4c49b\":{\"id\":\"8340315f-48e4-4768-a1ce-414532b4c49b\",\"label\":\"Kampala\",\"node\":{\"locationId\":\"8340315f-48e4-4768-a1ce-414532b4c49b\",\"name\":\"Kampala\",\"parentLocation\":{\"locationId\":\"02ebbc84-5e29-4cd5-9b79-c594058923e9\",\"name\":\"Uganda\",\"voided\":false},\"tags\":[\"District\"],\"voided\":false},\"children\":{\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\":{\"id\":\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\",\"label\":\"KCCA\",\"node\":{\"locationId\":\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\",\"name\":\"KCCA\",\"parentLocation\":{\"locationId\":\"8340315f-48e4-4768-a1ce-414532b4c49b\",\"name\":\"Kampala\",\"parentLocation\":{\"locationId\":\"02ebbc84-5e29-4cd5-9b79-c594058923e9\",\"name\":\"Uganda\",\"voided\":false},\"voided\":false},\"tags\":[\"County\"],\"voided\":false},\"children\":{\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\":{\"id\":\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\",\"label\":\"Central Division\",\"node\":{\"locationId\":\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\",\"name\":\"Central Division\",\"parentLocation\":{\"locationId\":\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\",\"name\":\"KCCA\",\"parentLocation\":{\"locationId\":\"8340315f-48e4-4768-a1ce-414532b4c49b\",\"name\":\"Kampala\",\"voided\":false},\"voided\":false},\"tags\":[\"Sub-county\"],\"voided\":false},\"children\":{\"44de66fb-e6c6-4bae-92bb-386dfe626eba\":{\"id\":\"44de66fb-e6c6-4bae-92bb-386dfe626eba\",\"label\":\"Bukesa Urban Health Centre\",\"node\":{\"locationId\":\"44de66fb-e6c6-4bae-92bb-386dfe626eba\",\"name\":\"Bukesa Urban Health Centre\",\"parentLocation\":{\"locationId\":\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\",\"name\":\"Central Division\",\"parentLocation\":{\"locationId\":\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\",\"name\":\"KCCA\",\"voided\":false},\"voided\":false},\"tags\":[\"Health Facility\"],\"voided\":false},\"children\":{\"982eb3f3-b7e3-450f-a38e-d067f2345212\":{\"id\":\"982eb3f3-b7e3-450f-a38e-d067f2345212\",\"label\":\"Jambula Girls School\",\"node\":{\"locationId\":\"982eb3f3-b7e3-450f-a38e-d067f2345212\",\"name\":\"Jambula Girls School\",\"parentLocation\":{\"locationId\":\"44de66fb-e6c6-4bae-92bb-386dfe626eba\",\"name\":\"Bukesa Urban Health Centre\",\"parentLocation\":{\"locationId\":\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\",\"name\":\"Central Division\",\"voided\":false},\"voided\":false},\"tags\":[\"School\"],\"voided\":false},\"parent\":\"44de66fb-e6c6-4bae-92bb-386dfe626eba\"}},\"parent\":\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\"}},\"parent\":\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\"}},\"parent\":\"8340315f-48e4-4768-a1ce-414532b4c49b\"}},\"parent\":\"02ebbc84-5e29-4cd5-9b79-c594058923e9\"}}}},\"parentChildren\":{\"8340315f-48e4-4768-a1ce-414532b4c49b\":[\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\"],\"02ebbc84-5e29-4cd5-9b79-c594058923e9\":[\"8340315f-48e4-4768-a1ce-414532b4c49b\"],\"b1ef8a0b-275b-43fc-a580-1e21ceb34c78\":[\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\"],\"44de66fb-e6c6-4bae-92bb-386dfe626eba\":[\"982eb3f3-b7e3-450f-a38e-d067f2345212\"],\"4e188e6d-2ffb-4b25-85f9-b9fbf5010d40\":[\"44de66fb-e6c6-4bae-92bb-386dfe626eba\"]}}}";

private final static String METADATA_VERSION = "metadata_version";
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
Expand Down Expand Up @@ -130,6 +133,8 @@ public void testGetAllSettings() throws Exception {
config.setTeamId("TEAM-ID-123");
config.setIdentifier("setting_123");
config.setSettings(createSettingsList());
config.setMetadataVersion(0L);
config.setLimit(1000);
settingConfig.add(config);

SettingSearchBean settingSearchBean = new SettingSearchBean();
Expand All @@ -146,7 +151,10 @@ public void testGetAllSettings() throws Exception {
MvcResult result = mockMvc
.perform(MockMvcRequestBuilders.get(BASE_URL + "/").param(AllConstants.Event.TEAM_ID, EXPECTED_TEAM_ID)
.param(AllConstants.BaseEntity.SERVER_VERSIOIN, "15421904649873")
.param(AllConstants.Event.LOCATION_ID, "123232"))
.param(AllConstants.Event.LOCATION_ID, "123232")
.param(LIMIT,"1000")
.param(METADATA_VERSION, "100")
)
.andExpect(MockMvcResultMatchers.status().isOk()).andReturn();

Mockito.verify(settingService)
Expand Down

0 comments on commit f36a158

Please sign in to comment.