use of org.sagebionetworks.bridge.exceptions.BadRequestException in project BridgeServer2 by Sage-Bionetworks.
the class AppService method deleteApp.
public void deleteApp(String identifier, boolean physical) {
checkArgument(isNotBlank(identifier));
if (appWhitelist.contains(identifier)) {
throw new UnauthorizedException(identifier + " is protected by whitelist.");
}
// only admin can call this method, should contain deactivated ones.
App existing = getApp(identifier, true);
if (!physical) {
// deactivate
if (!existing.isActive()) {
throw new BadRequestException("App '" + identifier + "' already deactivated.");
}
appDao.deactivateApp(existing.getIdentifier());
} else {
// delete app data
accountService.deleteAllAccounts(existing.getIdentifier());
studyService.deleteAllStudies(existing.getIdentifier());
scheduleService.deleteAllSchedules(existing.getIdentifier());
assessmentResourceService.deleteAllAssessmentResources(existing.getIdentifier());
assessmentService.deleteAllAssessments(existing.getIdentifier());
organizationService.deleteAllOrganizations(existing.getIdentifier());
templateService.deleteAllTemplates(existing.getIdentifier());
compoundActivityDefinitionService.deleteAllCompoundActivityDefinitionsInApp(existing.getIdentifier());
subpopService.deleteAllSubpopulations(existing.getIdentifier());
topicService.deleteAllTopics(existing.getIdentifier());
fileService.deleteAllAppFiles(existing.getIdentifier());
// actual delete
appDao.deleteApp(existing);
}
cacheProvider.removeApp(identifier);
}
use of org.sagebionetworks.bridge.exceptions.BadRequestException in project BridgeServer2 by Sage-Bionetworks.
the class AccountWorkflowService method resetPassword.
/**
* Use a supplied password reset token to change the password on an account. If the supplied
* token is not valid, this method throws an exception. If the token is valid but the account
* does not exist, an exception is also thrown (this would be unusual).
*/
public void resetPassword(PasswordReset passwordReset) {
checkNotNull(passwordReset);
// This pathway is unusual as the token may have been sent via email or phone, so test for both.
CacheKey emailCacheKey = CacheKey.passwordResetForEmail(passwordReset.getSptoken(), passwordReset.getAppId());
CacheKey phoneCacheKey = CacheKey.passwordResetForPhone(passwordReset.getSptoken(), passwordReset.getAppId());
String email = cacheProvider.getObject(emailCacheKey, String.class);
Phone phone = cacheProvider.getObject(phoneCacheKey, Phone.class);
if (email == null && phone == null) {
throw new BadRequestException(PASSWORD_RESET_TOKEN_EXPIRED);
}
cacheProvider.removeObject(emailCacheKey);
cacheProvider.removeObject(phoneCacheKey);
App app = appService.getApp(passwordReset.getAppId());
ChannelType channelType = null;
AccountId accountId = null;
if (email != null) {
accountId = AccountId.forEmail(app.getIdentifier(), email);
channelType = ChannelType.EMAIL;
} else if (phone != null) {
accountId = AccountId.forPhone(app.getIdentifier(), phone);
channelType = ChannelType.PHONE;
} else {
throw new BridgeServiceException("Could not reset password");
}
Account account = accountService.getAccount(accountId).orElseThrow(() -> new EntityNotFoundException(Account.class));
accountService.changePassword(account, channelType, passwordReset.getPassword());
}
use of org.sagebionetworks.bridge.exceptions.BadRequestException in project BridgeServer2 by Sage-Bionetworks.
the class AccountWorkflowService method resendVerificationToken.
/**
* Send another verification token via email or phone. This creates and sends a new verification token
* using the specified channel (an email or SMS message).
*/
public void resendVerificationToken(ChannelType type, AccountId accountId) {
checkNotNull(accountId);
App app = appService.getApp(accountId.getAppId());
Account account = accountService.getAccount(accountId).orElseThrow(() -> new EntityNotFoundException(Account.class));
if (type == ChannelType.EMAIL) {
if (account.getEmail() == null) {
throw new BadRequestException("Email address has not been set.");
}
if (TRUE.equals(account.getEmailVerified())) {
throw new BadRequestException("Email address is already verified.");
}
sendEmailVerificationToken(app, account.getId(), account.getEmail());
} else if (type == ChannelType.PHONE) {
if (account.getPhone() == null) {
throw new BadRequestException("Phone number has not been set.");
}
if (TRUE.equals(account.getPhoneVerified())) {
throw new BadRequestException("Phone number is already verified.");
}
sendPhoneVerificationToken(app, account.getId(), account.getPhone());
} else {
throw new UnsupportedOperationException("Channel type not implemented");
}
}
use of org.sagebionetworks.bridge.exceptions.BadRequestException in project BridgeServer2 by Sage-Bionetworks.
the class ActivityEventService method deleteCustomEvent.
/**
* Delete a custom event.
*/
public void deleteCustomEvent(App app, String healthCode, String eventKey) {
if (!app.getCustomEvents().containsKey(eventKey) && !app.getAutomaticCustomEvents().containsKey(eventKey)) {
throw new BadRequestException("App's customEvents do not contain event ID: " + eventKey);
}
ActivityEvent event = new DynamoActivityEvent.Builder().withHealthCode(healthCode).withObjectType(CUSTOM).withUpdateType(app.getCustomEvents().get(eventKey)).withObjectId(eventKey).build();
activityEventDao.deleteCustomEvent(event);
}
use of org.sagebionetworks.bridge.exceptions.BadRequestException in project BridgeServer2 by Sage-Bionetworks.
the class AssessmentConfigService method customizeAssessmentConfig.
public AssessmentConfig customizeAssessmentConfig(String appId, String ownerId, String guid, Map<String, Map<String, JsonNode>> updates) {
if (updates == null) {
throw new BadRequestException("Updates to configuration are missing");
}
Assessment assessment = assessmentService.getAssessmentByGuid(appId, ownerId, guid);
CAN_EDIT_ASSESSMENTS.checkAndThrow(ORG_ID, assessment.getOwnerId());
Map<String, Set<PropertyInfo>> fields = assessment.getCustomizationFields();
AssessmentConfigCustomizer customizer = new AssessmentConfigCustomizer(fields, updates);
AssessmentConfig existing = dao.getAssessmentConfig(guid).orElseThrow(() -> new EntityNotFoundException(AssessmentConfig.class));
BridgeUtils.walk(existing.getConfig(), customizer);
if (!customizer.hasUpdated()) {
return existing;
}
Validate.entityThrowingException(getValidator(), existing);
existing.setModifiedOn(getModifiedOn());
return dao.customizeAssessmentConfig(guid, existing);
}
Aggregations