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"));
}
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"));
}
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"));
}
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())));
}
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"));
}
Aggregations