use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorPriorityEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotIndicatorPriorityServiceImpl method addSnapshotIndicatorPriority.
@Override
@Transactional
public SnapshotIndicatorPriority addSnapshotIndicatorPriority(SnapshotIndicatorPriority priority) {
checkArgument(priority != null, i18n.translate("argument.notNull", priority));
checkArgument(priority.getSnapshotIndicatorId() > 0, "Argument was %s but expected nonnegative", priority.getSnapshotIndicatorId());
if (!priority.getIsAttainment() && snapshotPriorityRepository.countAllBySnapshotIndicatorIdAndIsAttainmentFalse(priority.getSnapshotIndicatorId()) >= 5) {
throw new CustomParameterizedException(i18n.translate("snapshotPriority.onlyFivePriorities"));
}
SnapshotIndicatorPriorityEntity entity = new SnapshotIndicatorPriorityEntity();
entity.setReason(priority.getReason());
entity.setAction(priority.getAction());
entity.setIndicator(priority.getIndicator());
entity.setIsAttainment(priority.getIsAttainment());
entity.setEstimatedDateAsISOString(priority.getEstimatedDate());
SnapshotIndicatorEntity indicator = snapshotIndicatorRepository.getOne(priority.getSnapshotIndicatorId());
entity.setSnapshotIndicator(indicator);
SnapshotIndicatorPriorityEntity newSnapshotIndicatorPriority = snapshotPriorityRepository.save(entity);
// We publish this event so that other components can
// execute some operations on other entities, like an update
// on the familiy#lastmModifiedAt property:
// https://github.com/FundacionParaguaya/FP-PSP-SERVER/issues/134
// In this way we only need one extra dependency in this service.
publisher.publishEvent(PriorityCreatedEvent.of(indicator));
return snapshotPriorityMapper.entityToDto(newSnapshotIndicatorPriority);
}
use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorPriorityEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotIndicatorPriorityMapper method dtoToEntity.
@Override
public SnapshotIndicatorPriorityEntity dtoToEntity(SnapshotIndicatorPriority dto) {
SnapshotIndicatorPriorityEntity entity = modelMapper.map(dto, SnapshotIndicatorPriorityEntity.class);
entity = entity.setEstimatedDateAsISOString(dto.getEstimatedDate());
return entity;
}
Aggregations