use of py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException in project FP-PSP-SERVER by FundacionParaguaya.
the class ApplicationServiceImpl method updateApplication.
@Override
public ApplicationDTO updateApplication(Long applicationId, ApplicationDTO applicationDTO) {
checkArgument(applicationId > 0, "Argument was %s but expected nonnegative", applicationId);
return Optional.ofNullable(applicationRepository.findOne(applicationId)).map(application -> {
application.setName(applicationDTO.getName());
application.setDescription(applicationDTO.getDescription());
application.setInformation(applicationDTO.getInformation());
if (applicationDTO.getFile() != null) {
ImageDTO imageDTO = ImageParser.parse(applicationDTO.getFile(), applicationProperties.getAws().getHubsImageDirectory());
String generatedURL = imageUploadService.uploadImage(imageDTO);
if (generatedURL != null) {
imageUploadService.deleteImage(application.getLogoUrl(), applicationProperties.getAws().getHubsImageDirectory());
application.setLogoUrl(generatedURL);
}
}
LOG.debug("Changed Information for Application: {}", application);
return applicationRepository.save(application);
}).map(applicationMapper::entityToDto).orElseThrow(() -> new UnknownResourceException("Application does not exist"));
}
use of py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException in project FP-PSP-SERVER by FundacionParaguaya.
the class UserApplicationServiceImpl method updateUserApplication.
@Override
public UserApplicationDTO updateUserApplication(Long userApplicationId, UserApplicationDTO userApplicationDTO) {
checkArgument(userApplicationId > 0, "Argument was %s but expected nonnegative", userApplicationId);
return Optional.ofNullable(userApplicationRepository.findOne(userApplicationId)).map(parameter -> {
BeanUtils.copyProperties(userApplicationDTO, parameter);
LOG.debug("Changed Information for User Application: {}", parameter);
return parameter;
}).map(userApplicationMapper::entityToDto).orElseThrow(() -> new UnknownResourceException("User Application does not exist"));
}
use of py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException in project FP-PSP-SERVER by FundacionParaguaya.
the class FamilyServiceImpl method updateFamily.
@Override
public FamilyDTO updateFamily(Long familyId, FamilyDTO familyDTO) {
checkArgument(familyId > 0, i18n.translate("argument.nonNegative", familyId));
return Optional.ofNullable(familyRepository.findOne(familyId)).map(family -> {
BeanUtils.copyProperties(familyDTO, family);
family.setLastModifiedAt(LocalDateTime.now());
LOG.debug("Changed Information for Family: {}", family);
return family;
}).map(familyMapper::entityToDto).orElseThrow(() -> new UnknownResourceException(i18n.translate("family.notExist")));
}
use of py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException in project FP-PSP-SERVER by FundacionParaguaya.
the class FamilyServiceImpl method imageUpload.
@Override
public String imageUpload(Long idFamily, MultipartFile multipartFile) throws IOException {
FamilyEntity familyEntity = familyRepository.findOne(idFamily);
if (familyEntity == null) {
throw new UnknownResourceException(i18n.translate("family.notExist"));
}
String familiesImageDirectory = this.applicationProperties.getAws().getFamiliesImageDirectory();
ImageDTO image = ImageParser.parse(multipartFile, familiesImageDirectory);
// control if image already exists: if so, deletes the old image
if (familyEntity.getImageURL() != null) {
imageUploadService.deleteImage(familyEntity.getImageURL(), familiesImageDirectory);
}
// uploads the image and obtains its URL
String url = imageUploadService.uploadImage(image);
familyEntity.setImageURL(url);
LOG.debug("Updating family {} with image {}", familyEntity.getFamilyId(), familyEntity.getImageURL());
familyRepository.save(familyEntity);
return url;
}
use of py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException in project FP-PSP-SERVER by FundacionParaguaya.
the class PasswordResetTokenServiceImpl method validatePasswordResetToken.
@Override
public void validatePasswordResetToken(String token, Long userId, String password, String repeatPassword) {
checkArgument(userId > 0, i18n.translate("argument.nonNegative", userId));
UserEntity userEntity = userRepository.findOne(userId);
if (userEntity == null) {
throw new UnknownResourceException(i18n.translate("user.notExist", userId));
}
PasswordResetTokenEntity passwordResetTokenEntity = passwordTokenRepository.findByToken(token);
if (passwordResetTokenEntity == null || passwordResetTokenEntity.getUser().getId().longValue() != userId.longValue()) {
throw new CustomParameterizedException(i18n.translate("email.invalidToken", token));
}
Calendar cal = Calendar.getInstance();
if ((passwordResetTokenEntity.getExpiryDate().getTime() - cal.getTime().getTime()) <= 0) {
throw new CustomParameterizedException(i18n.translate("email.expiredToken", token));
}
if (!password.equals(repeatPassword)) {
throw new CustomParameterizedException("Password does not match the confirm password");
}
userEntity.setPass(encryptPassword(repeatPassword));
userRepository.save(userEntity);
}
Aggregations