use of com.khartec.waltz.data.IdSelectorFactory in project waltz by khartec.
the class SurveyRunService method generateSurveyInstanceRecipients.
public List<SurveyInstanceRecipient> generateSurveyInstanceRecipients(long surveyRunId) {
SurveyRun surveyRun = surveyRunDao.getById(surveyRunId);
checkNotNull(surveyRun, "surveyRun " + surveyRunId + " not found");
SurveyTemplate surveyTemplate = surveyTemplateDao.getById(surveyRun.surveyTemplateId());
checkNotNull(surveyTemplate, "surveyTemplate " + surveyRun.surveyTemplateId() + " not found");
IdSelectorFactory idSelectorFactory = idSelectorFactoryProvider.getForKind(surveyTemplate.targetEntityKind());
Select<Record1<Long>> idSelector = idSelectorFactory.apply(surveyRun.selectionOptions());
Map<EntityReference, List<Person>> entityRefToPeople = involvementDao.findPeopleByEntitySelectorAndInvolvement(surveyTemplate.targetEntityKind(), idSelector, surveyRun.involvementKindIds());
return entityRefToPeople.entrySet().stream().flatMap(e -> e.getValue().stream().map(p -> ImmutableSurveyInstanceRecipient.builder().surveyInstance(ImmutableSurveyInstance.builder().surveyEntity(e.getKey()).surveyRunId(surveyRun.id().get()).status(SurveyInstanceStatus.NOT_STARTED).dueDate(surveyRun.dueDate()).build()).person(p).build())).distinct().collect(toList());
}
Aggregations