Source:
<code>public StudyParticipant updateIdentifiers(Study study, CriteriaContext context, IdentifierUpdate update) { checkNotNull(study); checkNotNull(context); checkNotNull(update); Validate.entityThrowingException(IdentifierUpdateValidator.INSTANCE, update); Account account = null; if (update.getSignIn().getReauthToken() != null) { account = accountDao.reauthenticate(study, update.getSignIn()); } else { account = accountDao.authenticate(study, update.getSignIn()); } if (!account.getId().equals(context.getUserId())) { throw new EntityNotFoundException(Account.class); } account = accountDao.getAccount(AccountId.forId(study.getIdentifier(), account.getId())); boolean sendEmailVerification = false; boolean assignExternalId = false; boolean accountUpdated = false; if (update.getPhoneUpdate() != null && account.getPhone() == null) { account.setPhone(update.getPhoneUpdate()); account.setPhoneVerified(false); accountUpdated = true; } if (update.getEmailUpdate() != null && account.getEmail() == null) { account.setEmail(update.getEmailUpdate()); account.setEmailVerified( !study.isEmailVerificationEnabled() ); sendEmailVerification = true; accountUpdated = true; } if (update.getExternalIdUpdate() != null && account.getExternalId() == null) { account.setExternalId(update.getExternalIdUpdate()); accountUpdated = true; assignExternalId = true; } if (accountUpdated) { accountDao.updateAccount(account, true); } if (sendEmailVerification && study.isEmailVerificationEnabled() && !study.isAutoVerificationEmailSuppressed()) { accountWorkflowService.sendEmailVerificationToken(study, account.getId(), account.getEmail()); } if (assignExternalId) { externalIdService.assignExternalId(study, account.getExternalId(), account.getHealthCode()); <START> } <END> return getParticipant(study, account.getId(), false); }</code><technical_language>a test verifies assigning external ID try assign external ID again</technical_language>

Target:
public StudyParticipant updateIdentifiers(Study study, CriteriaContext context, IdentifierUpdate update) { checkNotNull(study); checkNotNull(context); checkNotNull(update); Validate.entityThrowingException(new IdentifierUpdateValidator(study, externalIdService), update); Account account = null; if (update.getSignIn().getReauthToken() != null) { account = accountDao.reauthenticate(study, update.getSignIn()); } else { account = accountDao.authenticate(study, update.getSignIn()); } if (!account.getId().equals(context.getUserId())) { throw new EntityNotFoundException(Account.class); } account = accountDao.getAccount(AccountId.forId(study.getIdentifier(), account.getId())); boolean sendEmailVerification = false; boolean assignExternalId = false; boolean accountUpdated = false; if (update.getPhoneUpdate() != null && account.getPhone() == null) { account.setPhone(update.getPhoneUpdate()); account.setPhoneVerified(false); accountUpdated = true; } if (update.getEmailUpdate() != null && account.getEmail() == null) { account.setEmail(update.getEmailUpdate()); account.setEmailVerified( !study.isEmailVerificationEnabled() ); sendEmailVerification = true; accountUpdated = true; } if (update.getExternalIdUpdate() != null && account.getExternalId() == null) { account.setExternalId(update.getExternalIdUpdate()); accountUpdated = true; assignExternalId = true; } if (accountUpdated) { accountDao.updateAccount(account, true); } if (sendEmailVerification && study.isEmailVerificationEnabled() && !study.isAutoVerificationEmailSuppressed()) { accountWorkflowService.sendEmailVerificationToken(study, account.getId(), account.getEmail()); } if (assignExternalId) { externalIdService.assignExternalId(study, account.getExternalId(), account.getHealthCode()); } return getParticipant(study, account.getId(), false); }