Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 767ded8

Browse files
SORMAS-Foundation#3188 use optionals in queryPatientDiary
1 parent 66b1da2 commit 767ded8

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

sormas-backend/src/main/java/de/symeda/sormas/backend/externaljournal/ExternalJournalService.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,15 @@ public PatientDiaryPersonValidation validatePatientDiaryPerson(PersonDto person)
356356
}
357357

358358
private boolean isEmailAvailable(String emailAddress) {
359-
return queryPatientDiary(EMAIL_QUERY_PARAM, emailAddress).getCount() == 0;
359+
return queryPatientDiary(EMAIL_QUERY_PARAM, emailAddress)
360+
.orElseThrow(() -> new RuntimeException("Could not query patient diary for Email address availability"))
361+
.getCount() == 0;
360362
}
361363

362364
private boolean isPhoneAvailable(String phone) {
363-
return queryPatientDiary(MOBILE_PHONE_QUERY_PARAM, phone).getCount() == 0;
365+
return queryPatientDiary(MOBILE_PHONE_QUERY_PARAM, phone)
366+
.orElseThrow(() -> new RuntimeException("Could not query patient diary for phone number availability"))
367+
.getCount() == 0;
364368
}
365369

366370
/**
@@ -372,7 +376,7 @@ private boolean isPhoneAvailable(String phone) {
372376
* the value of the property to match
373377
* @return result of query
374378
*/
375-
public PatientDiaryPersonQueryResponse queryPatientDiary(String key, String value) {
379+
public Optional<PatientDiaryPersonQueryResponse> queryPatientDiary(String key, String value) {
376380
try {
377381
String probandsUrl = configFacade.getPatientDiaryConfig().getProbandsUrl() + "/probands";
378382
String queryParam = "\"" + key + "\" = \"" + value + "\"";
@@ -383,7 +387,10 @@ public PatientDiaryPersonQueryResponse queryPatientDiary(String key, String valu
383387
.request(MediaType.APPLICATION_JSON)
384388
.header("x-access-token", getPatientDiaryAuthToken())
385389
.get();
386-
return response.readEntity(PatientDiaryPersonQueryResponse.class);
390+
if (response.getStatus() == NOT_FOUND_STATUS) {
391+
return Optional.empty();
392+
}
393+
return Optional.ofNullable(response.readEntity(PatientDiaryPersonQueryResponse.class));
387394
} catch (IOException e) {
388395
logger.error("Could not retrieve patient query response: {}", e.getMessage());
389396
throw new RuntimeException(e);

0 commit comments

Comments
 (0)