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

Bug Fix: Handle Missing baseEntityId in Event JSON for Save for v2 #591

Merged
merged 4 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
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.14.3-SNAPSHOT</version>
<version>2.14.4-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 @@ -52,7 +52,7 @@ public Event get(String id) {
@Override
public void add(Event entity) {
if (entity == null || entity.getBaseEntityId() == null) {
return;
throw new IllegalArgumentException("Empty event or missing baseEntityId");
}

if (retrievePrimaryKey(entity) != null) { // Event already added
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/org/opensrp/service/EventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,24 +223,29 @@ && getByBaseEntityAndFormSubmissionId(event.getBaseEntityId(), event.getFormSubm
*/
public synchronized Event processOutOfArea(Event event) {
try {
String identifier = StringUtils.isBlank(event.getIdentifier(Client.ZEIR_ID)) ?
event.getIdentifier(OPENSRP_ID) : event.getIdentifier(Client.ZEIR_ID);
String programClientId = event.getDetails() != null
? event.getDetails().getOrDefault("program_client_id", "")
: "";

String identifier = StringUtils.isBlank(event.getIdentifier(Client.ZEIR_ID))
? (StringUtils.isBlank(event.getIdentifier(OPENSRP_ID)) ? programClientId : event.getIdentifier(OPENSRP_ID))
: event.getIdentifier(Client.ZEIR_ID);

logger.info("Processing out of area event: baseEntityId=" + event.getBaseEntityId() + "; identifier=" + identifier);

if (StringUtils.isNotBlank(event.getBaseEntityId()) || StringUtils.isBlank(identifier)) {
return event;
}

List<org.smartregister.domain.Client> clients =
identifier.startsWith(CARD_ID_PREFIX) ? clientService
.findAllByAttribute(NFC_CARD_IDENTIFIER, identifier.substring(CARD_ID_PREFIX.length()))
List<org.smartregister.domain.Client> clients = identifier.startsWith(CARD_ID_PREFIX)
? clientService.findAllByAttribute(NFC_CARD_IDENTIFIER, identifier.substring(CARD_ID_PREFIX.length()))
: getClientByIdentifier(identifier);

if (clients == null || clients.isEmpty()) {
return event;
}

for (org.smartregister.domain.Client client : clients) {

List<Event> existingEvents = findByBaseEntityAndType(client.getBaseEntityId(), BIRTH_REGISTRATION_EVENT);

if (existingEvents == null || existingEvents.isEmpty()) {
Expand Down Expand Up @@ -557,7 +562,6 @@ public List<Event> findEventsByConceptAndValue(String concept, String conceptVal

public List<Event> findByBaseEntityAndType(String baseEntityId, String eventType) {
return allEvents.findByBaseEntityAndType(baseEntityId, eventType);

}

private Event getUniqueEventFromEventList(List<Event> events) throws IllegalArgumentException {
Expand Down