Search in sources :

Example 11 with UnknownResourceException

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"));
}
Also used : ImageDTO(py.org.fundacionparaguaya.pspserver.system.dtos.ImageDTO) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 12 with UnknownResourceException

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"));
}
Also used : UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 13 with UnknownResourceException

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")));
}
Also used : UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 14 with UnknownResourceException

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;
}
Also used : FamilyEntity(py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity) ImageDTO(py.org.fundacionparaguaya.pspserver.system.dtos.ImageDTO) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 15 with UnknownResourceException

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);
}
Also used : PasswordResetTokenEntity(py.org.fundacionparaguaya.pspserver.security.entities.PasswordResetTokenEntity) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) Calendar(java.util.Calendar) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException) UserEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserEntity)

Aggregations

UnknownResourceException (py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)17 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)3 Transactional (org.springframework.transaction.annotation.Transactional)2 ImageDTO (py.org.fundacionparaguaya.pspserver.system.dtos.ImageDTO)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Specifications.where (org.springframework.data.jpa.domain.Specifications.where)1 Service (org.springframework.stereotype.Service)1 FamilyDTO (py.org.fundacionparaguaya.pspserver.families.dtos.FamilyDTO)1 FamilyMapDTO (py.org.fundacionparaguaya.pspserver.families.dtos.FamilyMapDTO)1 FamilyEntity (py.org.fundacionparaguaya.pspserver.families.entities.FamilyEntity)1 ApplicationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO)1 OrganizationDTO (py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO)1 SurveyOrganizationEntity (py.org.fundacionparaguaya.pspserver.network.entities.SurveyOrganizationEntity)1