use of org.sagebionetworks.bridge.exceptions.EntityAlreadyExistsException in project BridgeServer2 by Sage-Bionetworks.
the class DynamoAppDao method createApp.
@Override
public App createApp(App app) {
checkNotNull(app);
checkArgument(app.getVersion() == null, "%s has a version; may not be new", "app");
try {
mapper.save(app);
} catch (ConditionalCheckFailedException e) {
// in the create scenario, this should be a hash key clash.
throw new EntityAlreadyExistsException(App.class, "identifier", app.getIdentifier());
}
return app;
}
use of org.sagebionetworks.bridge.exceptions.EntityAlreadyExistsException in project BridgeServer2 by Sage-Bionetworks.
the class ConsentServiceTest method noConsentIfAlreadyConsented.
@Test
public void noConsentIfAlreadyConsented() {
ConsentSignature sig = new ConsentSignature.Builder().withConsentCreatedOn(CONSENT_CREATED_ON).withSignedOn(DateTime.now().getMillis()).withName("A Name").withBirthdate("1960-10-10").build();
account.setConsentSignatureHistory(SUBPOP_GUID, ImmutableList.of(sig));
try {
consentService.consentToResearch(app, SUBPOP_GUID, PARTICIPANT, CONSENT_SIGNATURE, SharingScope.NO_SHARING, false);
fail("Exception expected.");
} catch (EntityAlreadyExistsException e) {
verify(accountService).getAccount(any());
verifyNoMoreInteractions(accountService);
}
}
use of org.sagebionetworks.bridge.exceptions.EntityAlreadyExistsException in project BridgeServer2 by Sage-Bionetworks.
the class SurveyService method createSurvey.
/**
* Create a survey.
*/
public Survey createSurvey(Survey survey) {
checkNotNull(survey, "Survey cannot be null");
// Check survey ID uniqueness.
if (isNotBlank(survey.getAppId()) && isNotBlank(survey.getIdentifier())) {
String appId = survey.getAppId();
String existingSurveyGuid = surveyDao.getSurveyGuidForIdentifier(appId, survey.getIdentifier());
if (existingSurveyGuid != null) {
String errMsg = "Survey identifier " + survey.getIdentifier() + " is already used by survey " + existingSurveyGuid;
Map<String, Object> entityKeyMap = ImmutableMap.of(KEY_IDENTIFIER, survey.getIdentifier());
throw new EntityAlreadyExistsException(Survey.class, errMsg, entityKeyMap);
}
}
// Validate survey.
survey.setGuid(BridgeUtils.generateGuid());
for (SurveyElement element : survey.getElements()) {
element.setGuid(BridgeUtils.generateGuid());
}
Set<String> dataGroups = Collections.emptySet();
if (survey.getAppId() != null) {
App app = appService.getApp(survey.getAppId());
dataGroups = app.getDataGroups();
}
Validate.entityThrowingException(new SurveySaveValidator(dataGroups), survey);
return surveyDao.createSurvey(survey);
}
use of org.sagebionetworks.bridge.exceptions.EntityAlreadyExistsException in project BridgeServer2 by Sage-Bionetworks.
the class AuthenticationServiceTest method signUpExistingAccount.
@Test
public void signUpExistingAccount() {
app.setPasswordPolicy(PasswordPolicy.DEFAULT_PASSWORD_POLICY);
StudyParticipant participant = new StudyParticipant.Builder().withEmail(RECIPIENT_EMAIL).withPassword(PASSWORD).build();
doThrow(new EntityAlreadyExistsException(Account.class, "userId", "user-id")).when(participantService).createParticipant(app, participant, true);
service.signUp(app, participant);
verify(participantService).createParticipant(eq(app), any(), eq(true));
verify(accountWorkflowService).notifyAccountExists(eq(app), accountIdCaptor.capture());
AccountId captured = accountIdCaptor.getValue();
assertEquals(captured.getId(), "user-id");
assertEquals(captured.getAppId(), TEST_APP_ID);
}
use of org.sagebionetworks.bridge.exceptions.EntityAlreadyExistsException in project BridgeServer2 by Sage-Bionetworks.
the class AuthenticationServiceTest method signUpExistingExternalId.
@Test
public void signUpExistingExternalId() {
app.setPasswordPolicy(PasswordPolicy.DEFAULT_PASSWORD_POLICY);
StudyParticipant participant = new StudyParticipant.Builder().withExternalId(EXTERNAL_ID).build();
doThrow(new EntityAlreadyExistsException(ExternalIdentifier.class, "identifier", EXTERNAL_ID)).when(participantService).createParticipant(app, participant, true);
service.signUp(app, participant);
verify(participantService).createParticipant(eq(app), any(), eq(true));
verify(accountWorkflowService).notifyAccountExists(eq(app), accountIdCaptor.capture());
AccountId captured = accountIdCaptor.getValue();
assertEquals(captured.getExternalId(), EXTERNAL_ID);
assertEquals(captured.getAppId(), TEST_APP_ID);
}
Aggregations