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

allow search via post #1176

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
10e25c3
allow search via post
hilpitome Nov 16, 2022
9cc4010
rename test methods
hilpitome Nov 16, 2022
93abcba
apply formating
hilpitome Nov 17, 2022
db87055
rename searchByPath methods
hilpitome Nov 23, 2022
87c1806
fix codacy issues
hilpitome Nov 23, 2022
6e72c94
revert deleted exportEventDataMapper
hilpitome Nov 23, 2022
c98a3d1
use SearchService#searchGlobalClient instead of searchClient method
hilpitome Dec 22, 2022
0327bc4
get json string values as null instead of empty string
hilpitome Dec 22, 2022
5739e75
extract out duplicates in old search method
hilpitome Dec 23, 2022
7b80ee6
Trigger checks
hilpitome Dec 23, 2022
11d8a05
update codacy suggestions
hilpitome Jan 9, 2023
92098c9
reduce NPath complexity
hilpitome Jan 9, 2023
451dad7
deduplicate setCoreFilters
hilpitome Jan 9, 2023
b7e27a0
deduplicate setcorefilters
hilpitome Jan 12, 2023
69de169
Trigger checks
hilpitome Jan 13, 2023
042c9a1
fix nullpointerexception from Utils class
hilpitome Jan 13, 2023
4df76a4
use valid opensrp-server-core version
hilpitome Jan 13, 2023
a5b90a5
codacy fixe
hilpitome Jan 16, 2023
a7638bb
apply openmrs formatter
hilpitome Jan 17, 2023
ae921d4
initialize variable
hilpitome Jan 17, 2023
e2004db
fix codacy issue
hilpitome Jan 20, 2023
1fdcb9f
revert to clientService methods without acl
hilpitome Jan 20, 2023
19aaee8
create alpha snapshot for testing
hilpitome Jan 23, 2023
8d879be
version as alpha
hilpitome Jan 23, 2023
d7c6e72
bump up version
hilpitome Mar 7, 2023
17942f6
add logging
hilpitome Mar 8, 2023
4bdc8d8
Merge branch '1172-master-allow-search-via-post' of github.com:opensr…
hilpitome Mar 8, 2023
b229f88
refactor getStringFilter mthd
hilpitome Mar 9, 2023
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<artifactId>opensrp-server-web</artifactId>
<packaging>war</packaging>
<version>3.2.11-SNAPSHOT</version>
<version>3.2.12-SNAPSHOT</version>
<name>opensrp-server-web</name>
<description>OpenSRP Server Web Application</description>
<url>https://github.com/OpenSRP/opensrp-server-web</url>
Expand Down
34 changes: 21 additions & 13 deletions src/main/java/org/opensrp/web/rest/ClientResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import static org.opensrp.common.AllConstants.Event.LOCATION_ID;

import java.text.ParseException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

Expand Down Expand Up @@ -129,7 +133,8 @@ public Client update(Client entity) {//TODO check if send property and id matche
}

@Override
public List<Client> search(HttpServletRequest request) throws ParseException {//TODO search should not call different url but only add params
public List<Client> search(HttpServletRequest request)
throws ParseException {//TODO search should not call different url but only add params
List<Client> clients = new ArrayList<>();
ClientSearchBean searchBean = new ClientSearchBean();
searchBean.setNameLike(getStringFilter("name", request));
Expand Down Expand Up @@ -224,7 +229,8 @@ private List<Client> getDependants(List<Client> clients, String searchRelationsh
List<Client> dependantClients = new ArrayList<>();
List<Client> clientsToRemove = new ArrayList<>();
for (Client client : clients) {
List<Client> dependants = clientService.findByRelationshipIdAndType(searchRelationship, client.getBaseEntityId());
List<Client> dependants = clientService
.findByRelationshipIdAndType(searchRelationship, client.getBaseEntityId());
if (dependants.size() > 0) {
dependantClients.addAll(dependants);
} else {
Expand Down Expand Up @@ -304,7 +310,8 @@ public ResponseEntity<String> searchByCriteria(HttpServletRequest request) throw
searchBean.setStartDate(startDate);
DateTime endDate = getDateFilter(ENDDATE, request);
searchBean.setEndDate(endDate);
} catch (ParseException e) {
}
catch (ParseException e) {
logger.error(e.getMessage());
}

Expand Down Expand Up @@ -376,7 +383,8 @@ private int getTotal(ClientSearchBean clientSearchBean, AddressSearchBean addres
if (HOUSEHOLD.equalsIgnoreCase(clientType)) {
total = clientService.findTotalCountHouseholdByCriteria(clientSearchBean, addressSearchBean).getTotalCount();
} else if (ALLCLIENTS.equalsIgnoreCase(clientType)) {
total = clientService.findTotalCountAllClientsByCriteria(clientSearchBean, addressSearchBean).getTotalCount();
total = clientService.findTotalCountAllClientsByCriteria(clientSearchBean, addressSearchBean)
.getTotalCount();
} else if (ANC.equalsIgnoreCase(clientType)) {
clientSearchBean.setClientType(null);
total = clientService.findCountANCByCriteria(clientSearchBean, addressSearchBean);
Expand Down Expand Up @@ -427,27 +435,27 @@ public ResponseEntity<String> getAllChild(ClientSearchBean clientSearchBean, Add
@RequestMapping(value = "/findIds", method = RequestMethod.GET, produces = {
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<Identifier> findIds(
@RequestParam(value = SERVER_VERSIOIN) long serverVersion,
@RequestParam(value = SERVER_VERSIOIN) long serverVersion,
@RequestParam(value = IS_ARCHIVED, defaultValue = FALSE, required = false) boolean isArchived,
@RequestParam(value = "fromDate", required = false) String fromDate,
@RequestParam(value = "toDate", required = false) String toDate) {
Pair<List<String>, Long> taskIdsPair = clientService.findAllIds(serverVersion, DEFAULT_GET_ALL_IDS_LIMIT, isArchived,
Utils.getDateTimeFromString(fromDate), Utils.getDateTimeFromString(toDate));
Utils.getDateFromString(fromDate), Utils.getDateFromString(toDate));
Identifier identifiers = new Identifier();
identifiers.setIdentifiers(taskIdsPair.getLeft());
identifiers.setLastServerVersion(taskIdsPair.getRight());
return new ResponseEntity<>(identifiers, HttpStatus.OK);
}

/**
* Fetch clients ordered by serverVersion ascending order
*
* @return a response with clients
*/
@GetMapping(value = "/getAll", produces = {MediaType.APPLICATION_JSON_VALUE })
@GetMapping(value = "/getAll", produces = { MediaType.APPLICATION_JSON_VALUE })
public List<Client> getAll(
@RequestParam(value = SERVER_VERSIOIN) long serverVersion,
@RequestParam(required = false, defaultValue = DEFAULT_LIMIT + "") int limit){
@RequestParam(value = SERVER_VERSIOIN) long serverVersion,
@RequestParam(required = false, defaultValue = DEFAULT_LIMIT + "") int limit) {

return clientService.findByServerVersion(serverVersion, limit);
}
Expand All @@ -457,9 +465,9 @@ public List<Client> getAll(
*
* @return a response with clients
*/
@GetMapping(value = "/countAll", produces = {MediaType.APPLICATION_JSON_VALUE })
@GetMapping(value = "/countAll", produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<ModelMap> countAll(
@RequestParam(value = SERVER_VERSIOIN) long serverVersion){
@RequestParam(value = SERVER_VERSIOIN) long serverVersion) {
Long countOfClients = clientService.countAll(serverVersion);
ModelMap modelMap = new ModelMap();
modelMap.put("count", countOfClients != null ? countOfClients : 0);
Expand Down
37 changes: 23 additions & 14 deletions src/main/java/org/opensrp/web/rest/EventResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ protected ResponseEntity<String> sync(HttpServletRequest request) throws JsonPro

if (team != null || providerId != null || locationId != null || baseEntityId != null || teamId != null) {

EventSyncBean eventSyncBean = sync(providerId, locationId, baseEntityId, serverVersion, team, teamId, limit, returnCount, false);
EventSyncBean eventSyncBean = sync(providerId, locationId, baseEntityId, serverVersion, team, teamId, limit,
returnCount, false);

HttpHeaders headers = getJSONUTF8Headers();
if (returnCount) {
Expand Down Expand Up @@ -202,7 +203,8 @@ protected ResponseEntity<String> syncByPost(@RequestBody SyncParam syncParam) th
* @return Events found matching the client IDs
* @throws JsonProcessingException
*/
@RequestMapping(value = "/sync-out-of-catchment", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/sync-out-of-catchment", method = RequestMethod.GET, produces = {
MediaType.APPLICATION_JSON_VALUE })
protected ResponseEntity<String> syncOutOfCatchment(HttpServletRequest request) throws JsonProcessingException {
EventSyncBean response = new EventSyncBean();

Expand All @@ -216,7 +218,8 @@ protected ResponseEntity<String> syncOutOfCatchment(HttpServletRequest request)
boolean returnCount = Boolean.getBoolean(getStringFilter(RETURN_COUNT, request));

if (team != null || providerId != null || locationId != null || baseEntityId != null || teamId != null) {
EventSyncBean eventSyncBean = sync(providerId, locationId, baseEntityId, serverVersion, team, teamId, limit, returnCount, true);
EventSyncBean eventSyncBean = sync(providerId, locationId, baseEntityId, serverVersion, team, teamId, limit,
returnCount, true);

HttpHeaders headers = getJSONUTF8Headers();
if (returnCount) {
Expand All @@ -231,7 +234,8 @@ protected ResponseEntity<String> syncOutOfCatchment(HttpServletRequest request)
}

@RequestMapping(value = "/sync-out-of-catchment", method = POST, produces = { MediaType.APPLICATION_JSON_VALUE })
protected ResponseEntity<String> syncOutOfCatchmentByPost(@RequestBody SyncParam syncParam) throws JsonProcessingException {
protected ResponseEntity<String> syncOutOfCatchmentByPost(@RequestBody SyncParam syncParam)
throws JsonProcessingException {
EventSyncBean response = new EventSyncBean();

try {
Expand Down Expand Up @@ -343,7 +347,8 @@ public EventSyncBean sync(String providerId, String locationId, String baseEntit
return getEventsAndClients(eventSearchBean, limit == null || limit == 0 ? 25 : limit, returnCount, isOutOfCatchment);
}

private EventSyncBean getEventsAndClients(EventSearchBean eventSearchBean, Integer limit, boolean returnCount, boolean isOutOfCatchment) {
private EventSyncBean getEventsAndClients(EventSearchBean eventSearchBean, Integer limit, boolean returnCount,
boolean isOutOfCatchment) {
List<Event> events = new ArrayList<Event>();
List<String> clientIds = new ArrayList<String>();
List<Client> clients = new ArrayList<Client>();
Expand Down Expand Up @@ -406,7 +411,8 @@ private List<Event> getEvents(EventSearchBean eventSearchBean, Integer limit, bo
List<String> relationships = getRelationships(baseEntityIds);
eventSearchBean.setBaseEntityId(eventSearchBean.getBaseEntityId() + "," + String.join(",", relationships));

return eventService.findOutOfCatchmentEvents(eventSearchBean, BaseEntity.SERVER_VERSIOIN, "asc", limit == null ? 25 : limit);
return eventService.findOutOfCatchmentEvents(eventSearchBean, BaseEntity.SERVER_VERSIOIN, "asc",
limit == null ? 25 : limit);
} else {
return eventService.findEvents(eventSearchBean, BaseEntity.SERVER_VERSIOIN, "asc", limit == null ? 25 : limit);
}
Expand Down Expand Up @@ -449,7 +455,8 @@ protected ResponseEntity<String> getAll(@RequestParam long serverVersion,
eventSearchBean.setServerVersion(serverVersion > 0 ? serverVersion + 1 : serverVersion);
eventSearchBean.setEventType(eventType);
return new ResponseEntity<>(
objectMapper.writeValueAsString(getEventsAndClients(eventSearchBean, limit == null ? 25 : limit, false, false)),
objectMapper
.writeValueAsString(getEventsAndClients(eventSearchBean, limit == null ? 25 : limit, false, false)),
getJSONUTF8Headers(), OK);
}

Expand Down Expand Up @@ -509,7 +516,8 @@ public ResponseEntity<String> save(@RequestBody String data, Authentication auth
clientService.addorUpdate(client);
}
catch (Exception e) {
logger.error("[SYNC_INFO] Sync failed for client {}; identifiers: {}", client.getBaseEntityId(), gson.toJson(client.getIdentifiers()), e);
logger.error("[SYNC_INFO] Sync failed for client {}; identifiers: {}", client.getBaseEntityId(),
gson.toJson(client.getIdentifiers()), e);
failedClientsIds.add(client.getBaseEntityId());
}
}
Expand All @@ -528,7 +536,8 @@ public ResponseEntity<String> save(@RequestBody String data, Authentication auth
event = eventService.processOutOfArea(event);
eventService.addorUpdateEvent(event, username);

logger.info("[SYNC_INFO] Event {} of type {} saved", event.getFormSubmissionId(), event.getEventType());
logger.info("[SYNC_INFO] Event {} of type {} saved", event.getFormSubmissionId(),
event.getEventType());
}
catch (Exception e) {
logger.error(
Expand Down Expand Up @@ -647,8 +656,8 @@ protected ResponseEntity<Identifier> getAllIdsByEventType(
try {

Pair<List<String>, Long> eventIdsPair = eventService.findAllIdsByEventType(eventType, isDeleted, serverVersion,
Constants.DEFAULT_GET_ALL_IDS_LIMIT, Utils.getDateTimeFromString(fromDate),
Utils.getDateTimeFromString(toDate));
Constants.DEFAULT_GET_ALL_IDS_LIMIT, Utils.getDateFromString(fromDate),
Utils.getDateFromString(toDate));
Identifier identifiers = new Identifier();
identifiers.setIdentifiers(eventIdsPair.getLeft());
identifiers.setLastServerVersion(eventIdsPair.getRight());
Expand Down Expand Up @@ -682,8 +691,8 @@ public ResponseEntity<ByteArrayResource> exportEventData(@RequestParam List<Stri
logger.info("Temp DIR is =============" + tempDirectory);
for (String eventType : eventTypes) {
ExportEventDataSummary exportEventDataSummary = eventService
.exportEventData(planIdentifier, eventType, Utils.getDateTimeFromString(fromDate),
Utils.getDateTimeFromString(toDate));
.exportEventData(planIdentifier, eventType, Utils.getDateFromString(fromDate),
Utils.getDateFromString(toDate));

missionName = exportEventDataSummary != null &&
exportEventDataSummary.getMissionName() != null ?
Expand Down Expand Up @@ -757,7 +766,7 @@ private boolean exportImagesAgainstFlagProblemEvent(String eventType, String pla

ExportImagesSummary exportImagesSummary =
eventService.getImagesMetadataForFlagProblemEvent(planIdentifier, eventType,
Utils.getDateTimeFromString(fromDate), Utils.getDateTimeFromString(toDate));
Utils.getDateFromString(fromDate), Utils.getDateFromString(toDate));
String imagesDirectoryName;
if (firstTime) {
formatted = df.format(new Date());
Expand Down
Loading