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

893 : Expose new end-point on /getAll on SettingsResource v2 #894

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
61 changes: 60 additions & 1 deletion src/main/java/org/opensrp/web/rest/v2/SettingResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -42,7 +43,8 @@

import javax.servlet.http.HttpServletRequest;

import static org.opensrp.web.Constants.LIMIT;
import static org.opensrp.common.AllConstants.BaseEntity.SERVER_VERSIOIN;
import static org.opensrp.web.Constants.*;

@Controller("settingResourceV2")
@RequestMapping(value = Constants.RestEndpointUrls.SETTINGS_V2_URL)
Expand Down Expand Up @@ -116,6 +118,8 @@ public ResponseEntity<String> getAllSettings(HttpServletRequest request) {
boolean resolveSettings = RestUtils.getBooleanFilter(AllConstants.Event.RESOLVE_SETTINGS, request);
String metadataVersion = RestUtils.getStringFilter(METADATA_VERSION, request);
String limit = RestUtils.getStringFilter(LIMIT, request);
String orderByType = RestUtils.getStringFilter(ORDER_BY_TYPE, request);
String orderByFieldName = RestUtils.getStringFilter(ORDER_BY_FIELD_NAME, request);
Map<String, TreeNode<String, Location>> treeNodeHashMap = null;

if (StringUtils.isBlank(team) && StringUtils.isBlank(providerId) && StringUtils.isBlank(locationId)
Expand Down Expand Up @@ -148,6 +152,12 @@ public ResponseEntity<String> getAllSettings(HttpServletRequest request) {
settingQueryBean.setServerVersion(lastSyncedServerVersion);
settingQueryBean.setMetadataVersion(lastMetadataVersion);
settingQueryBean.setLimit(pageLimit);
if (orderByType != null) {
settingQueryBean.setOrderByType(SettingSearchBean.OrderByType.valueOf(orderByType));
}
if (orderByFieldName != null) {
settingQueryBean.setOrderByFieldName(SettingSearchBean.FieldName.valueOf(orderByFieldName));
}
if (StringUtils.isNotBlank(identifier)) {
settingQueryBean.setIdentifier(identifier);
}
Expand All @@ -163,6 +173,55 @@ public ResponseEntity<String> getAllSettings(HttpServletRequest request) {
return new ResponseEntity<>(gson.toJson(settingList), RestUtils.getJSONUTF8Headers(), HttpStatus.OK);
}

@GetMapping(value = "/getAll", produces = {MediaType.APPLICATION_JSON_VALUE })
public List<Setting> getAll(
@RequestParam(value = SERVER_VERSIOIN, required = false) String serverVersion,
@RequestParam(value = AllConstants.Event.LOCATION_ID, required = false) String locationId,
@RequestParam(value = AllConstants.Event.RESOLVE_SETTINGS, required = false) boolean resolveSettings,
@RequestParam(required = false) String limit,
@RequestParam(value = METADATA_VERSION) String metadataVersion,
@RequestParam(value = ORDER_BY_TYPE, required = false) String orderByType,
@RequestParam(value = ORDER_BY_FIELD_NAME, required = false) String orderByFieldName){

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);
}
Map<String, TreeNode<String, Location>> treeNodeHashMap = null;

SettingSearchBean settingQueryBean = new SettingSearchBean();
settingQueryBean.setServerVersion(lastSyncedServerVersion);
settingQueryBean.setMetadataVersion(lastMetadataVersion);
settingQueryBean.setLimit(pageLimit);
if (orderByType != null) {
settingQueryBean.setOrderByType(SettingSearchBean.OrderByType.valueOf(orderByType));
}
if (orderByFieldName != null) {
settingQueryBean.setOrderByFieldName(SettingSearchBean.FieldName.valueOf(orderByFieldName));
}
if (StringUtils.isNotBlank(locationId)) {
settingQueryBean.setResolveSettings(resolveSettings);
treeNodeHashMap = getChildParentLocationTree(locationId);
}

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

return settingList;
}

private List<Setting> extractSettings(List<SettingConfiguration> settingConfigurations) {
List<Setting> settingList = new ArrayList<>();
if (settingConfigurations != null && settingConfigurations.size() > 0) {
Expand Down