use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class SnapshotServiceImpl method addSurveySnapshot.
@Override
@Transactional
public Snapshot addSurveySnapshot(UserDetailsDTO details, NewSnapshot snapshot) {
checkNotNull(snapshot);
ValidationResults results = surveyService.checkSchemaCompliance(snapshot);
if (!results.isValid()) {
throw new CustomParameterizedException(i18n.translate("snapshot.invalid"), results.asMap());
}
SnapshotIndicatorEntity indicatorEntity = economicMapper.newSnapshotToIndicatorEntity(snapshot);
PersonEntity personEntity = personMapper.snapshotPersonalToEntity(snapshot);
FamilyEntity family = familyService.getOrCreateFamilyFromSnapshot(details, snapshot, personEntity);
SnapshotEconomicEntity snapshotEconomicEntity = saveEconomic(snapshot, indicatorEntity, family);
familyService.updateFamily(family.getFamilyId());
return economicMapper.entityToDto(snapshotEconomicEntity);
}
use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity 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.SnapshotIndicatorEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class OrganizationServiceImpl method countSnapshotIndicators.
private SnapshotIndicators countSnapshotIndicators(Long organizationId) {
List<FamilyEntity> families = familyService.findByOrganizationId(organizationId);
List<SnapshotEconomicEntity> snapshotEconomics = snapshotEconomicRepo.findByFamilyIn(families);
List<SnapshotIndicatorEntity> entityList = new ArrayList<SnapshotIndicatorEntity>();
for (SnapshotEconomicEntity economics : snapshotEconomics) {
entityList.add(economics.getSnapshotIndicator());
}
SnapshotIndicators indicators = new SnapshotIndicators();
List<SurveyData> listProperties = indicatorMapper.entityListToDtoList(entityList);
for (SurveyData properties : listProperties) {
properties.forEach((k, v) -> {
countIndicators(indicators, v);
});
}
return indicators;
}
use of py.org.fundacionparaguaya.pspserver.surveys.entities.SnapshotIndicatorEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class PriorityCreatedEventListener method getFamilyFromEvent.
private Optional<FamilyEntity> getFamilyFromEvent(PriorityCreatedEvent event) {
SnapshotIndicatorEntity indicator = event.getSnapshotIndicatorEntity();
SnapshotEconomicEntity economic = economicRepo.findBySnapshotIndicator(indicator);
return Optional.ofNullable(economic.getFamily());
}
Aggregations