Search in sources :

Example 6 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) {
    checkArgument(familyId > 0, i18n.translate("argument.nonNegative", familyId));
    LOG.debug("Updating family with id: {}", familyId);
    return Optional.ofNullable(familyRepository.findOne(familyId)).map(family -> {
        family.setLastModifiedAt(LocalDateTime.now());
        return familyRepository.save(family);
    }).map(familyMapper::entityToDto).orElseThrow(() -> new UnknownResourceException(i18n.translate("family.notExist")));
}
Also used : UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 7 with UnknownResourceException

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

the class PersonServiceImpl method updatePerson.

@Override
public PersonDTO updatePerson(Long personId, PersonDTO personDTO) {
    checkArgument(personId > 0, "Argument was %s but expected nonnegative", personId);
    return Optional.ofNullable(personRepository.findOne(personId)).map(person -> {
        BeanUtils.copyProperties(personDTO, person);
        LOG.debug("Changed Information for Person: {}", person);
        return person;
    }).map(personMapper::entityToDto).orElseThrow(() -> new UnknownResourceException("Person does not exist"));
}
Also used : UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 8 with UnknownResourceException

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

the class SurveyServiceImpl method updateSurvey.

@Override
@Transactional
public SurveyDefinition updateSurvey(UserDetailsDTO details, Long surveyId, SurveyDefinition surveyDefinition) {
    checkArgument(surveyId > 0, "Argument was %s but expected nonnegative", surveyId);
    return Optional.ofNullable(repo.findOne(surveyId)).map(survey -> {
        survey.setDescription(surveyDefinition.getDescription());
        survey.setTitle(surveyDefinition.getTitle());
        survey.setSurveyDefinition(surveyDefinition);
        survey.setLastModifiedAt(LocalDateTime.now());
        surveyOrganizationService.crudSurveyOrganization(details, surveyId, surveyDefinition, survey);
        repo.save(survey);
        return survey;
    }).map(mapper::entityToDto).orElseThrow(() -> new UnknownResourceException("Survey does not exist"));
}
Also used : UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with UnknownResourceException

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

the class ParameterServiceImpl method updateParameter.

@Override
public ParameterDTO updateParameter(Long parameterId, ParameterDTO parameterDTO) {
    checkArgument(parameterId > 0, "Argument was %s but expected nonnegative", parameterId);
    return Optional.ofNullable(parameterRepository.findOne(parameterId)).map(parameter -> {
        BeanUtils.copyProperties(parameterDTO, parameter);
        LOG.debug("Changed Information for Parameter: {}", parameter);
        return parameter;
    }).map(parameterMapper::entityToDto).orElseThrow(() -> new UnknownResourceException("Parameter does not exist"));
}
Also used : UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException)

Example 10 with UnknownResourceException

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

the class SnapshotServiceImpl method countSnapshotIndicators.

private SnapshotIndicators countSnapshotIndicators(SnapshotEconomicEntity snapshot) {
    SnapshotIndicators indicators = new SnapshotIndicators();
    try {
        SurveyData properties = indicatorMapper.entityToDto(snapshot.getSnapshotIndicator());
        properties.forEach((k, v) -> {
            countIndicators(indicators, v);
        });
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new UnknownResourceException(i18n.translate("snapshot.invalid", snapshot.getId()));
    }
    return indicators;
}
Also used : SnapshotIndicators(py.org.fundacionparaguaya.pspserver.surveys.dtos.SnapshotIndicators) SurveyData(py.org.fundacionparaguaya.pspserver.surveys.dtos.SurveyData) UnknownResourceException(py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) 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