Search in sources :

Example 1 with IdSelectorFactory

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());
}
Also used : SetUtilities.fromCollection(com.khartec.waltz.common.SetUtilities.fromCollection) IdSelectorFactory(com.khartec.waltz.data.IdSelectorFactory) InvolvementDao(com.khartec.waltz.data.involvement.InvolvementDao) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Autowired(org.springframework.beans.factory.annotation.Autowired) SurveyInstanceRecipientDao(com.khartec.waltz.data.survey.SurveyInstanceRecipientDao) Record1(org.jooq.Record1) Service(org.springframework.stereotype.Service) Map(java.util.Map) PersonDao(com.khartec.waltz.data.person.PersonDao) ImmutableChangeLog(com.khartec.waltz.model.changelog.ImmutableChangeLog) com.khartec.waltz.model.survey(com.khartec.waltz.model.survey) Select(org.jooq.Select) SurveyRunDao(com.khartec.waltz.data.survey.SurveyRunDao) SurveyTemplateDao(com.khartec.waltz.data.survey.SurveyTemplateDao) Checks.checkNotNull(com.khartec.waltz.common.Checks.checkNotNull) com.khartec.waltz.model(com.khartec.waltz.model) Set(java.util.Set) IdSelectorFactoryProvider(com.khartec.waltz.data.IdSelectorFactoryProvider) Objects(java.util.Objects) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Person(com.khartec.waltz.model.person.Person) LocalDate(java.time.LocalDate) SurveyInstanceDao(com.khartec.waltz.data.survey.SurveyInstanceDao) ChangeLogService(com.khartec.waltz.service.changelog.ChangeLogService) Checks.checkTrue(com.khartec.waltz.common.Checks.checkTrue) IdSelectorFactory(com.khartec.waltz.data.IdSelectorFactory) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Record1(org.jooq.Record1)

Aggregations

Checks.checkNotNull (com.khartec.waltz.common.Checks.checkNotNull)1 Checks.checkTrue (com.khartec.waltz.common.Checks.checkTrue)1 SetUtilities.fromCollection (com.khartec.waltz.common.SetUtilities.fromCollection)1 IdSelectorFactory (com.khartec.waltz.data.IdSelectorFactory)1 IdSelectorFactoryProvider (com.khartec.waltz.data.IdSelectorFactoryProvider)1 InvolvementDao (com.khartec.waltz.data.involvement.InvolvementDao)1 PersonDao (com.khartec.waltz.data.person.PersonDao)1 SurveyInstanceDao (com.khartec.waltz.data.survey.SurveyInstanceDao)1 SurveyInstanceRecipientDao (com.khartec.waltz.data.survey.SurveyInstanceRecipientDao)1 SurveyRunDao (com.khartec.waltz.data.survey.SurveyRunDao)1 SurveyTemplateDao (com.khartec.waltz.data.survey.SurveyTemplateDao)1 com.khartec.waltz.model (com.khartec.waltz.model)1 ImmutableChangeLog (com.khartec.waltz.model.changelog.ImmutableChangeLog)1 Person (com.khartec.waltz.model.person.Person)1 com.khartec.waltz.model.survey (com.khartec.waltz.model.survey)1 ChangeLogService (com.khartec.waltz.service.changelog.ChangeLogService)1 LocalDate (java.time.LocalDate)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1