Search in sources :

Example 1 with UnknownResourceException

use of py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException in project FP-PSP-SERVER by FundacionParaguaya.

the class UserServiceImpl method updateUser.

@Override
public UserDTO updateUser(Long userId, UserDTO userDTO) {
    checkArgument(userId > 0, "Argument was %s but expected nonnegative", userId);
    return Optional.ofNullable(userRepository.findOne(userId)).map(user -> {
        BeanUtils.copyProperties(userDTO, user);
        LOG.debug("Changed Information for User: {}", user);
        return user;
    }).map(userMapper::entityToDto).orElseThrow(() -> new UnknownResourceException("User does not exist"));
}
Also used : UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 2 with UnknownResourceException

use of py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException in project FP-PSP-SERVER by FundacionParaguaya.

the class SurveyServiceImpl method getSurveyDefinition.

@Override
public SurveyDefinition getSurveyDefinition(Long surveyId) {
    checkNotNull(surveyId);
    checkArgument(surveyId > 0, "Argument was %s but expected nonnegative", surveyId);
    return Optional.ofNullable(repo.findOne(surveyId)).map(entity -> new SurveyDefinition().id(entity.getId()).description(entity.getDescription()).title(entity.getTitle()).surveySchema(entity.getSurveyDefinition().getSurveySchema()).surveyUiSchema(entity.getSurveyDefinition().getSurveyUISchema()).organizations(organizationMapper.entityListToDtoList(surveyOrganizationRepo.findBySurveyId(entity.getId()).stream().map(o -> o.getOrganization()).collect(Collectors.toList()))).applications(applicationMapper.entityListToDtoList(surveyOrganizationRepo.findBySurveyId(entity.getId()).stream().map(o -> o.getApplication()).collect(Collectors.toList())))).orElseThrow(() -> new UnknownResourceException("Survey definition does not exist"));
}
Also used : OrganizationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.OrganizationRepository) Specifications.where(org.springframework.data.jpa.domain.Specifications.where) UserDetailsDTO(py.org.fundacionparaguaya.pspserver.security.dtos.UserDetailsDTO) SurveyEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SurveyEntity) SurveyMapper(py.org.fundacionparaguaya.pspserver.surveys.mapper.SurveyMapper) LocalDateTime(java.time.LocalDateTime) SchemaValidator.requiredValue(py.org.fundacionparaguaya.pspserver.surveys.validation.SchemaValidator.requiredValue) ArrayList(java.util.ArrayList) SurveySchema(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveySchema) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ApplicationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.ApplicationDTO) SurveyService(py.org.fundacionparaguaya.pspserver.surveys.services.SurveyService) MultipleSchemaValidator(py.org.fundacionparaguaya.pspserver.surveys.validation.MultipleSchemaValidator) ApplicationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.ApplicationRepository) Service(org.springframework.stereotype.Service) SurveyOrganizationEntity(py.org.fundacionparaguaya.pspserver.network.entities.SurveyOrganizationEntity) SurveyOrganizationService(py.org.fundacionparaguaya.pspserver.network.services.SurveyOrganizationService) PropertyValidator.validType(py.org.fundacionparaguaya.pspserver.surveys.validation.PropertyValidator.validType) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) NewSnapshot(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSnapshot) OrganizationDTO(py.org.fundacionparaguaya.pspserver.network.dtos.OrganizationDTO) Property(py.org.fundacionparaguaya.pspserver.surveys.dtos.Property) PropertyAttributeSupport(py.org.fundacionparaguaya.pspserver.surveys.mapper.PropertyAttributeSupport) ValidationResults(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResults) SurveyOrganizationSpecification.lastModifiedGt(py.org.fundacionparaguaya.pspserver.network.specifications.SurveyOrganizationSpecification.lastModifiedGt) NewSurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSurveyDefinition) MultipleSchemaValidator.all(py.org.fundacionparaguaya.pspserver.surveys.validation.MultipleSchemaValidator.all) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SurveyRepository(py.org.fundacionparaguaya.pspserver.surveys.repositories.SurveyRepository) ValidationResult(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationResult) Role(py.org.fundacionparaguaya.pspserver.security.constants.Role) Collectors(java.util.stream.Collectors) OrganizationMapper(py.org.fundacionparaguaya.pspserver.network.mapper.OrganizationMapper) SurveyOrganizationRepository(py.org.fundacionparaguaya.pspserver.network.repositories.SurveyOrganizationRepository) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException) ApplicationMapper(py.org.fundacionparaguaya.pspserver.network.mapper.ApplicationMapper) List(java.util.List) StopLightType(py.org.fundacionparaguaya.pspserver.surveys.entities.StopLightType) ValidationSupport(py.org.fundacionparaguaya.pspserver.surveys.validation.ValidationSupport) SurveyOrganizationSpecification.byOrganization(py.org.fundacionparaguaya.pspserver.network.specifications.SurveyOrganizationSpecification.byOrganization) SchemaValidator.presentInSchema(py.org.fundacionparaguaya.pspserver.surveys.validation.SchemaValidator.presentInSchema) Optional(java.util.Optional) SurveyOrganizationSpecification.byApplication(py.org.fundacionparaguaya.pspserver.network.specifications.SurveyOrganizationSpecification.byApplication) SchemaValidator.markedAsRequired(py.org.fundacionparaguaya.pspserver.surveys.validation.SchemaValidator.markedAsRequired) Transactional(org.springframework.transaction.annotation.Transactional) NewSurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.NewSurveyDefinition) SurveyDefinition(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyDefinition) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 3 with UnknownResourceException

use of py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException in project FP-PSP-SERVER by FundacionParaguaya.

the class CityServiceImpl method updateCity.

@Override
public CityDTO updateCity(Long cityId, CityDTO cityDTO) {
    checkArgument(cityId > 0, "Argument was %s but expected nonnegative", cityId);
    return Optional.ofNullable(cityRepository.findOne(cityId)).map(city -> {
        BeanUtils.copyProperties(cityDTO, city);
        LOG.debug("Changed Information for City: {}", city);
        return city;
    }).map(cityMapper::entityToDto).orElseThrow(() -> new UnknownResourceException("City does not exist"));
}
Also used : UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 4 with UnknownResourceException

use of py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotIndicatorPriorityServiceImpl method updateSnapshotIndicatorPriority.

@Override
public SnapshotIndicatorPriority updateSnapshotIndicatorPriority(SnapshotIndicatorPriority priority) {
    checkArgument(priority.getId() > 0, i18n.translate("argument.nonNegative", priority.getId()));
    return Optional.ofNullable(snapshotPriorityRepository.findOne(priority.getId())).map(p -> {
        p.setAction(priority.getAction());
        p.setReason(priority.getReason());
        p.setEstimatedDateAsISOString(priority.getEstimatedDate());
        LOG.debug("Changed Information for" + " Snapshot Indicator Priority: {}", p);
        return snapshotPriorityRepository.save(p);
    }).map(snapshotPriorityMapper::entityToDto).orElseThrow(() -> new UnknownResourceException(i18n.translate("snapshotPriority.notExist", priority.getId())));
}
Also used : UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 5 with UnknownResourceException

use of py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException in project FP-PSP-SERVER by FundacionParaguaya.

the class OrganizationServiceImpl method updateOrganization.

@Override
public OrganizationDTO updateOrganization(Long organizationId, OrganizationDTO organizationDTO) {
    checkArgument(organizationId > 0, "Argument was %s but expected nonnegative", organizationId);
    return Optional.ofNullable(organizationRepository.findOne(organizationId)).map(organization -> {
        organization.setName(organizationDTO.getName());
        organization.setDescription(organizationDTO.getDescription());
        organization.setInformation(organizationDTO.getInformation());
        if (organizationDTO.getFile() != null) {
            ImageDTO imageDTO = ImageParser.parse(organizationDTO.getFile(), applicationProperties.getAws().getOrgsImageDirectory());
            String generatedURL = imageUploadService.uploadImage(imageDTO);
            if (generatedURL != null) {
                imageUploadService.deleteImage(organization.getLogoUrl(), applicationProperties.getAws().getOrgsImageDirectory());
                organization.setLogoUrl(generatedURL);
            }
        }
        LOG.debug("Changed Information for Organization: {}", organization);
        return organizationRepository.save(organization);
    }).map(organizationMapper::entityToDto).orElseThrow(() -> new UnknownResourceException("Organization does not exist"));
}
Also used : ImageDTO(py.org.fundacionparaguaya.pspserver.system.dtos.ImageDTO) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

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