Search in sources :

Example 1 with SnapshotIndicatorPriorityEntity

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);
}
Also used : SnapshotIndicatorPriorityEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorPriorityEntity) CustomParameterizedException(py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException) SnapshotIndicatorEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SnapshotIndicatorPriorityEntity

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;
}
Also used : SnapshotIndicatorPriorityEntity(py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorPriorityEntity)

Aggregations

SnapshotIndicatorPriorityEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorPriorityEntity)2 Transactional (org.springframework.transaction.annotation.Transactional)1 CustomParameterizedException (py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException)1 SnapshotIndicatorEntity (py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity)1