Skip to content

Commit a5dc6b0

Browse files
Code Rabbit Fixes
1 parent 7439648 commit a5dc6b0

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

JeMPI_Apps/JeMPI_LibAPI/src/main/java/org/jembi/jempi/libapi/BackEnd.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ private Behavior<Event> getFieldCountHandler(final GetFieldCountRequest request)
528528
request.replyTo.tell(new GetFieldCountResponse(getCount));
529529
} catch (Exception e) {
530530
LOGGER.error(e.getLocalizedMessage(), e);
531-
LOGGER.error("libMPI.findExpandedGoldenRecord failed for goldenId: {} with error: {}", e.getMessage());
531+
LOGGER.error("libMPI.getFieldCount failed for goldenId: {} with error: {}", e.getMessage());
532532
}
533533
return Behaviors.same();
534534
}
@@ -543,7 +543,7 @@ private Behavior<Event> getAgeGroupCountHandler(final GetAgeGroupCountRequest re
543543
request.replyTo.tell(new GetAgeGroupCountResponse(getCount));
544544
} catch (Exception e) {
545545
LOGGER.error(e.getLocalizedMessage(), e);
546-
LOGGER.error("libMPI.findExpandedGoldenRecord failed for goldenId: {} with error: {}", e.getMessage());
546+
LOGGER.error("libMPI.getAgeGroupCountHandler failed for goldenId: {} with error: {}", e.getMessage());
547547
}
548548
return Behaviors.same();
549549
}
@@ -569,14 +569,14 @@ public static double calculateAvarageAge(final List<String> dobList) {
569569
int count = 0;
570570
// Iterate through the list of DOBs and calculate the age for each
571571
for (String dob : dobList) {
572-
if (!dob.isEmpty()) {
572+
if (dob != null && !dob.isEmpty()) {
573573
try {
574574
LocalDate birthDate = LocalDate.parse(dob, formatter); // Try to convert DOB to LocalDate
575575
int age = Period.between(birthDate, today).getYears(); // Calculate age in years
576576
totalAge += age;
577577
count++;
578578
} catch (DateTimeParseException e) {
579-
LOGGER.error("Invalid date format for dob: " + dob + ". Skipping this record.");
579+
LOGGER.error("Invalid date format for dob: {}. Skipping this record.", dob);
580580
}
581581
}
582582
}

JeMPI_Apps/JeMPI_LibAPI/src/main/java/org/jembi/jempi/libapi/Routes.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import akka.http.javadsl.model.*;
99
import akka.http.javadsl.server.Route;
1010
import com.fasterxml.jackson.databind.JsonNode;
11-
import com.fasterxml.jackson.databind.ObjectMapper;
1211
import org.apache.logging.log4j.LogManager;
1312
import org.apache.logging.log4j.Logger;
1413
import org.jembi.jempi.libmpi.MpiServiceError;
@@ -559,10 +558,9 @@ public static Route getFieldCount(
559558
if (!result.isSuccess()) {
560559
return handleError(result.failed().get());
561560
}
562-
ObjectMapper objectMapper = new ObjectMapper();
563561
JsonNode jsonResponse = null;
564562
try {
565-
jsonResponse = objectMapper.readTree(result.get().genderCount());
563+
jsonResponse = OBJECT_MAPPER.readTree(result.get().genderCount());
566564
} catch (JsonProcessingException e) {
567565
throw new RuntimeException(e);
568566
}

JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/dgraph/DgraphQueries.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ static String getFieldCount(final ApiModels.CountFields countFields) {
489489
String endDate = countFields.endDate(); // Assume endDate is of LocalDate type
490490

491491
boolean hasValues = fieldValues != null && !fieldValues.isEmpty();
492-
boolean hasDateRange = startDate != null && endDate != null;
492+
boolean hasDateRange = startDate != null && endDate != null && !startDate.isEmpty() && !endDate.isEmpty();
493493

494494
StringBuilder queryBuilder = new StringBuilder();
495495
queryBuilder.append("query count() {");
@@ -1292,7 +1292,7 @@ public static List<String> getAllList(final ApiModels.AllList allListRequest) {
12921292

12931293
// Build the query dynamically based on date range availability
12941294
String query;
1295-
if (!startDate.isEmpty() && !endDate.isEmpty()) {
1295+
if (startDate != null && endDate != null && !startDate.isEmpty() && !endDate.isEmpty()) {
12961296
query = String.format("""
12971297
{
12981298
peopleInDateRange(func: has(GoldenRecord.%s))
@@ -1326,14 +1326,16 @@ private static List<String> parseDobFromResponse(final String responseJson) thro
13261326
List<String> dobList = new ArrayList<>();
13271327
ObjectMapper mapper = new ObjectMapper();
13281328
JsonNode jsonNode = mapper.readTree(responseJson);
1329-
JsonNode peopleArray = jsonNode.get("peopleInDateRange");
1329+
JsonNode recordArray = jsonNode.get("peopleInDateRange");
13301330

13311331
// Extract each `dob` and add to the list
1332-
for (JsonNode person : peopleArray) {
1333-
if (person.has("GoldenRecord.dob")) {
1334-
dobList.add(person.get("GoldenRecord.dob").asText());
1332+
if (recordArray != null) {
1333+
for (JsonNode person : recordArray) {
1334+
if (person.has("GoldenRecord.dob")) {
1335+
dobList.add(person.get("GoldenRecord.dob").asText());
1336+
}
13351337
}
1336-
}
1338+
}
13371339
return dobList;
13381340
}
13391341

JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/ApiModels.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ public record ApiOffsetSearch(
444444
Boolean sortAsc) {
445445
}
446446

447+
@JsonInclude(JsonInclude.Include.NON_NULL)
447448
public record AllList(String field, String startDate, String endDate) { }
448449

449450
public record AverageAgeResponse(double averageAge) { }

0 commit comments

Comments
 (0)