@@ -312,19 +312,20 @@ public PatientDiaryRegisterResult registerPatientDiaryPerson(PersonDto person) {
312312 private Invocation .Builder getExternalDataPersonInvocationBuilder (String personUuid ) {
313313 String externalDataUrl = configFacade .getPatientDiaryConfig ().getProbandsUrl () + "/external-data/" + personUuid ;
314314 Client client = ClientBuilder .newClient ();
315- return client .target (externalDataUrl )
316- .request (MediaType .APPLICATION_JSON )
317- .header ("x-access-token" , getPatientDiaryAuthToken ());
315+ return client .target (externalDataUrl ).request (MediaType .APPLICATION_JSON ).header ("x-access-token" , getPatientDiaryAuthToken ());
318316 }
319317
320318 /**
321- * Check whether a person has valid data in order to be registered in the patient diary
322319 *
323320 * @param person
324321 * the person to validate
322+ * @param calledForTest
323+ * defines if method makes a call to a patient diary to check for availability of phone and mail addresses.
324+ * In tests, this call is not made.
325+ * This boolean should be false unless it's called from tests.
325326 * @return the result of the validation
326327 */
327- public PatientDiaryPersonValidation validatePatientDiaryPerson (PersonDto person ) {
328+ public PatientDiaryPersonValidation validatePatientDiaryPerson (PersonDto person , boolean calledForTest ) {
328329 String email = person .getEmailAddress ();
329330 String phone = person .getPhone ();
330331 boolean validEmail = true ;
@@ -335,7 +336,9 @@ public PatientDiaryPersonValidation validatePatientDiaryPerson(PersonDto person)
335336 if (StringUtils .isNotEmpty (email )) {
336337 EmailValidator validator = EmailValidator .getInstance ();
337338 validEmail = validator .isValid (email );
338- emailAvailable = isEmailAvailable (person .getEmailAddress ());
339+ if (!calledForTest ) {
340+ emailAvailable = isEmailAvailable (person .getEmailAddress ());
341+ }
339342 }
340343 if (StringUtils .isNotEmpty (phone )) {
341344 validPhone = false ;
@@ -344,7 +347,9 @@ public PatientDiaryPersonValidation validatePatientDiaryPerson(PersonDto person)
344347 Phonenumber .PhoneNumber germanNumberProto = phoneUtil .parse (phone , "DE" );
345348 validPhone = phoneUtil .isValidNumber (germanNumberProto );
346349 String internationalPhone = phoneUtil .format (germanNumberProto , PhoneNumberUtil .PhoneNumberFormat .INTERNATIONAL );
347- phoneAvailable = isPhoneAvailable (internationalPhone );
350+ if (!calledForTest ) {
351+ phoneAvailable = isPhoneAvailable (internationalPhone );
352+ }
348353 } catch (NumberParseException e ) {
349354 logger .warn ("NumberParseException was thrown: " + e .toString ());
350355 }
@@ -361,14 +366,14 @@ public PatientDiaryPersonValidation validatePatientDiaryPerson(PersonDto person)
361366
362367 private boolean isEmailAvailable (String emailAddress ) {
363368 return queryPatientDiary (EMAIL_QUERY_PARAM , emailAddress )
364- .orElseThrow (() -> new RuntimeException ("Could not query patient diary for Email address availability" ))
365- .getCount () == 0 ;
369+ .orElseThrow (() -> new RuntimeException ("Could not query patient diary for Email address availability" ))
370+ .getCount () == 0 ;
366371 }
367372
368373 private boolean isPhoneAvailable (String phone ) {
369374 return queryPatientDiary (MOBILE_PHONE_QUERY_PARAM , phone )
370- .orElseThrow (() -> new RuntimeException ("Could not query patient diary for phone number availability" ))
371- .getCount () == 0 ;
375+ .orElseThrow (() -> new RuntimeException ("Could not query patient diary for phone number availability" ))
376+ .getCount () == 0 ;
372377 }
373378
374379 /**
@@ -387,10 +392,7 @@ public Optional<PatientDiaryPersonQueryResponse> queryPatientDiary(String key, S
387392 String encodedParams = URLEncoder .encode (queryParam , StandardCharsets .UTF_8 .toString ());
388393 String fullUrl = probandsUrl + "?q=" + encodedParams ;
389394 Client client = ClientBuilder .newClient ();
390- Response response = client .target (fullUrl )
391- .request (MediaType .APPLICATION_JSON )
392- .header ("x-access-token" , getPatientDiaryAuthToken ())
393- .get ();
395+ Response response = client .target (fullUrl ).request (MediaType .APPLICATION_JSON ).header ("x-access-token" , getPatientDiaryAuthToken ()).get ();
394396 if (response .getStatus () == NOT_FOUND_STATUS ) {
395397 return Optional .empty ();
396398 }
0 commit comments