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