Source:
<code>public UserSession createUser(Study study, StudyParticipant participant, SubpopulationGuid subpopGuid, boolean signUserIn, boolean consentUser) { checkNotNull(study, "Study cannot be null"); checkNotNull(participant, "Participant cannot be null"); IdentifierHolder identifier = null; try { identifier = participantService.createParticipant(study, ADMIN_ROLE, participant, false); StudyParticipant updatedParticipant = participantService.getParticipant(study, identifier.getIdentifier(), false); CriteriaContext context = new CriteriaContext.Builder() .withUserId(identifier.getIdentifier()) .withStudyIdentifier(study.getStudyIdentifier()).build(); if (consentUser) { String name = String.format("[Signature for %s]", updatedParticipant.getEmail()); ConsentSignature signature = new ConsentSignature.Builder().withName(name) .withBirthdate("1989-08-19").withSignedOn(DateUtils.getCurrentMillisFromEpoch()).build(); if (subpopGuid != null) { consentService.consentToResearch(study, subpopGuid, updatedParticipant, signature, NO_SHARING, false); } else { Map<SubpopulationGuid,ConsentStatus> statuses = consentService.getConsentStatuses(context); for (ConsentStatus consentStatus : statuses.values()) { if (consentStatus.isRequired()) { SubpopulationGuid guid = SubpopulationGuid.create(consentStatus.getSubpopulationGuid()); consentService.consentToResearch(study, guid, updatedParticipant, signature, NO_SHARING, false); } } } } if (signUserIn) { SignIn signIn = new SignIn.Builder().withStudy(study.getIdentifier()).withEmail(participant.getEmail()) .withPassword(participant.getPassword()).build(); return authenticationService.signIn(study, context, signIn); <START> } <END> UserSession session = authenticationService.getSession(study, context); session.setAuthenticated(false); return session; } catch(RuntimeException e) { if (identifier != null) { deleteUser(study, identifier.getIdentifier()); } throw e; } }</code><technical_language>This works if user is created email. it, throw 400 InvalidEntityException. Do for this is called for users emails? a check for if participant.getEmail() exists throw a exception? Fail silently</technical_language>

Target:
public UserSession createUser(Study study, StudyParticipant participant, SubpopulationGuid subpopGuid, boolean signUserIn, boolean consentUser) { checkNotNull(study, "Study cannot be null"); checkNotNull(participant, "Participant cannot be null"); SignIn signIn = new SignIn.Builder().withStudy(study.getIdentifier()).withEmail(participant.getEmail()) .withPhone(participant.getPhone()).withPassword(participant.getPassword()).build(); Validate.entityThrowingException(SignInValidator.MINIMAL, signIn); IdentifierHolder identifier = null; try { identifier = participantService.createParticipant(study, ADMIN_ROLE, participant, false); StudyParticipant updatedParticipant = participantService.getParticipant(study, identifier.getIdentifier(), false); CriteriaContext context = new CriteriaContext.Builder() .withUserId(identifier.getIdentifier()) .withStudyIdentifier(study.getStudyIdentifier()).build(); if (consentUser) { String name = String.format("[Signature for %s]", updatedParticipant.getEmail()); ConsentSignature signature = new ConsentSignature.Builder().withName(name) .withBirthdate("1989-08-19").withSignedOn(DateUtils.getCurrentMillisFromEpoch()).build(); if (subpopGuid != null) { consentService.consentToResearch(study, subpopGuid, updatedParticipant, signature, NO_SHARING, false); } else { Map<SubpopulationGuid,ConsentStatus> statuses = consentService.getConsentStatuses(context); for (ConsentStatus consentStatus : statuses.values()) { if (consentStatus.isRequired()) { SubpopulationGuid guid = SubpopulationGuid.create(consentStatus.getSubpopulationGuid()); consentService.consentToResearch(study, guid, updatedParticipant, signature, NO_SHARING, false); } } } } if (signUserIn) { return authenticationService.signIn(study, context, signIn); } UserSession session = authenticationService.getSession(study, context); session.setAuthenticated(false); return session; } catch(RuntimeException e) { if (identifier != null) { deleteUser(study, identifier.getIdentifier()); } throw e; } }