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

830 : Add metadata version and limit param setting v2 #849

Open
wants to merge 2 commits into
base: v2.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>org.smartregister</groupId>
<artifactId>opensrp-server-web</artifactId>
<packaging>war</packaging>
<version>2.1.53.2-SNAPSHOT</version>
<version>2.1.53.3-SNAPSHOT</version>
<name>opensrp-server-web</name>
<description>OpenSRP Server Web Application</description>
<url>https://github.com/OpenSRP/opensrp-server-web</url>
Expand All @@ -24,7 +24,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.3-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.common.version>2.0.3-SNAPSHOT</opensrp.common.version>
Expand Down
30 changes: 24 additions & 6 deletions 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 @@ -112,18 +116,22 @@ 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);
Map<String, TreeNode<String, Location>> treeNodeHashMap = null;
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)) {
return new ResponseEntity<>("All parameters cannot be null for this endpoint",
RestUtils.getJSONUTF8Headers(), HttpStatus.BAD_REQUEST);
}

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

SettingSearchBean settingQueryBean = new SettingSearchBean();
settingQueryBean.setTeam(team);
Expand All @@ -138,8 +146,18 @@ public ResponseEntity<String> getAllSettings(HttpServletRequest request) {
settingQueryBean.setResolveSettings(resolveSettings);
treeNodeHashMap = getChildParentLocationTree(locationId);
}
if (StringUtils.isNotBlank(metadataVersion)) {
lastMetadataVersion = Long.parseLong(metadataVersion);
}

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

settingQueryBean.setMetadataVersion(lastMetadataVersion);
settingQueryBean.setLimit(pageLimit);

List<SettingConfiguration> settingConfigurations = settingService.findSettings(settingQueryBean,
List<SettingConfiguration> settingConfigurations = settingService.findSettings(settingQueryBean,
treeNodeHashMap);
List<Setting> settingList = extractSettings(settingConfigurations);

Expand Down