Search in sources :

Example 1 with SnapshotDraftEntity

use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotDraftEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotDraftServiceImpl method updateSnapshotDraft.

@Override
public SnapshotDraft updateSnapshotDraft(Long id, SnapshotDraft snapshotDraft) {
    checkArgument(id != null && id > 0, i18n.translate("argument.nonNegative", id));
    checkArgument(snapshotDraft != null, i18n.translate("argument.notNull", snapshotDraft));
    SnapshotDraftEntity snapshotEntity = Optional.ofNullable(repository.findOne(id)).orElseThrow(() -> new CustomParameterizedException(i18n.translate("snapshotDraft.notExist", id)));
    if (snapshotEntity == null) {
        return mapper.entityToDto(new SnapshotDraftEntity());
    }
    snapshotEntity.setStateDraft(snapshotDraft.getStateDraft());
    if (snapshotDraft.getUserName() != null) {
        snapshotEntity.setUser(userRepository.findOneByUsername(snapshotDraft.getUserName()).orElseThrow(() -> new CustomParameterizedException(i18n.translate("user.notExist", snapshotDraft.getUserName()))));
    }
    snapshotEntity = repository.save(snapshotEntity);
    return mapper.entityToDto(snapshotEntity);
}
Also used : SnapshotDraftEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotDraftEntity) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)

Example 2 with SnapshotDraftEntity

use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotDraftEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotDraftServiceImpl method getSnapshotDraftByUser.

public List<SnapshotDraft> getSnapshotDraftByUser(UserDetailsDTO details, String familyName) {
    UserEntity user = userRepository.findOneByUsername(details.getUsername()).orElse(null);
    if (user == null) {
        return Collections.emptyList();
    }
    List<SnapshotDraftEntity> draftList = repository.findAll(where(userEquals(user.getId())).and(likeFamilyName(familyName)).and(createdAtLessDays(SNAPSHOT_DRAFT_MAX_DAY)));
    return mapper.entityListToDtoList(draftList);
}
Also used : SnapshotDraftEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotDraftEntity) UserEntity(py.org.fundacionparaguaya.pspserver.security.entities.UserEntity)

Example 3 with SnapshotDraftEntity

use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotDraftEntity in project FP-PSP-SERVER by FundacionParaguaya.

the class SnapshotDraftServiceImpl method addSnapshotDraft.

@Override
public SnapshotDraft addSnapshotDraft(SnapshotDraft snapshot) {
    SnapshotDraftEntity snapshotEntity = mapper.dtoToEntity(snapshot);
    snapshotEntity = repository.save(snapshotEntity);
    return mapper.entityToDto(snapshotEntity);
}
Also used : SnapshotDraftEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotDraftEntity)

Aggregations

SnapshotDraftEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotDraftEntity)3 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)1 UserEntity (py.org.fundacionparaguaya.pspserver.security.entities.UserEntity)1