use of py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotDraftServiceImpl method updateSnapshotDraft.
@Override
public SnapshotDraft updateSnapshotDraft(Long id, SnapshotDraft snapshotDraft) {
checkArgument(id != null && id > 0, i18n.translate("argument.nonNegative", id));
checkArgument(snapshotDraft != null, i18n.translate("argument.notNull", snapshotDraft));
SnapshotDraftEntity snapshotEntity = Optional.ofNullable(repository.findOne(id)).orElseThrow(() -> new CustomParameterizedException(i18n.translate("snapshotDraft.notExist", id)));
if (snapshotEntity == null) {
return mapper.entityToDto(new SnapshotDraftEntity());
}
snapshotEntity.setStateDraft(snapshotDraft.getStateDraft());
if (snapshotDraft.getUserName() != null) {
snapshotEntity.setUser(userRepository.findOneByUsername(snapshotDraft.getUserName()).orElseThrow(() -> new CustomParameterizedException(i18n.translate("user.notExist", snapshotDraft.getUserName()))));
}
snapshotEntity = repository.save(snapshotEntity);
return mapper.entityToDto(snapshotEntity);
}
use of py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotServiceImpl method addSurveySnapshot.
@Override
@Transactional
public Snapshot addSurveySnapshot(UserDetailsDTO details, NewSnapshot snapshot) {
checkNotNull(snapshot);
ValidationResults results = surveyService.checkSchemaCompliance(snapshot);
if (!results.isValid()) {
throw new CustomParameterizedException(i18n.translate("snapshot.invalid"), results.asMap());
}
SnapshotIndicatorEntity indicatorEntity = economicMapper.newSnapshotToIndicatorEntity(snapshot);
PersonEntity personEntity = personMapper.snapshotPersonalToEntity(snapshot);
FamilyEntity family = familyService.getOrCreateFamilyFromSnapshot(details, snapshot, personEntity);
SnapshotEconomicEntity snapshotEconomicEntity = saveEconomic(snapshot, indicatorEntity, family);
familyService.updateFamily(family.getFamilyId());
return economicMapper.entityToDto(snapshotEconomicEntity);
}
use of py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException in project FP-PSP-SERVER by FundacionParaguaya.
the class PasswordResetTokenServiceImpl method resetPassword.
@Override
public void resetPassword(String userEmail) {
UserEntity user = null;
try {
user = userRepository.findUserByEmail(userEmail).get();
} catch (NoSuchElementException e) {
throw new CustomParameterizedException(i18n.translate("email.emailUserNotFound"));
} catch (Exception ex) {
throw new CustomParameterizedException(i18n.translate("email.errorResetMail"));
}
if (user == null) {
throw new CustomParameterizedException(i18n.translate("email.emailUserNotFound"));
}
String token = UUID.randomUUID().toString();
createPasswordResetTokenForUser(user, token);
SimpleMailMessage template = new SimpleMailMessage();
template.setText(loadTemplate(applicationProps.getTemplates().getResetMail()));
String[] args = { i18n.translate("email.bodyTitle"), i18n.translate("email.bodyGreeting"), applicationProps.getClient().getLoginUrl() + "?" + MAIL_PARAM_TOKEN + "=" + token + "&" + MAIL_PARAM_ID + "=" + user.getId(), i18n.translate("email.bodyReset", user.getEmail()), i18n.translate("email.bodySign") };
emailService.sendSimpleMessageUsingTemplate(user.getEmail(), i18n.translate("email.resetPassword"), template, args);
}
use of py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException in project FP-PSP-SERVER by FundacionParaguaya.
the class UserServiceImpl method addUser.
@Override
public UserDTO addUser(UserDTO userDTO) {
userRepository.findOneByUsername(userDTO.getUsername()).ifPresent(user -> {
throw new CustomParameterizedException("User already exists.", new ImmutableMultimap.Builder<String, String>().put("username", user.getUsername()).build().asMap());
});
UserEntity user = new UserEntity();
BeanUtils.copyProperties(userDTO, user);
UserEntity newUser = userRepository.save(user);
return userMapper.entityToDto(newUser);
}
use of py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException in project FP-PSP-SERVER by FundacionParaguaya.
the class SurveyServiceImpl method deleteSurvey.
@Override
public void deleteSurvey(Long surveyId) {
try {
Optional.ofNullable(repo.findOne(surveyId)).ifPresent(survey -> {
surveyOrganizationRepo.deleteBySurveyId(survey.getId());
repo.delete(survey);
});
} catch (Exception e) {
throw new CustomParameterizedException("The survey can not be deleted!");
}
}
Aggregations