use of org.finos.waltz.model.person.Person in project waltz by khartec.
the class SurveyRunService method validateSurveyRunDelete.
private void validateSurveyRunDelete(String userName, long surveyRunId) {
Person owner = validateUser(userName);
SurveyRun surveyRun = validateSurveyRun(surveyRunId);
checkTrue(Objects.equals(surveyRun.ownerId(), owner.id().get()), "Permission denied");
}
use of org.finos.waltz.model.person.Person in project waltz by khartec.
the class SurveyRunService method createSurveyRun.
public IdCommandResponse createSurveyRun(String userName, SurveyRunCreateCommand command) {
checkNotNull(userName, "userName cannot be null");
checkNotNull(command, "create command cannot be null");
Person owner = personDao.getActiveByUserEmail(userName);
checkNotNull(owner, "userName " + userName + " cannot be resolved");
long surveyRunId = surveyRunDao.create(owner.id().get(), command);
// log against template
changeLogService.write(ImmutableChangeLog.builder().operation(Operation.ADD).userId(userName).parentReference(EntityReference.mkRef(EntityKind.SURVEY_TEMPLATE, command.surveyTemplateId())).childKind(EntityKind.SURVEY_RUN).message("Survey Run: " + command.name() + " (ID: " + surveyRunId + ") added").build());
// log against run
changeLogService.write(ImmutableChangeLog.builder().operation(Operation.ADD).userId(userName).parentReference(EntityReference.mkRef(EntityKind.SURVEY_RUN, surveyRunId)).message("Survey Run: " + command.name() + " added").build());
return ImmutableIdCommandResponse.builder().id(surveyRunId).build();
}
use of org.finos.waltz.model.person.Person in project waltz by khartec.
the class SurveyRunService method findForRecipient.
public List<SurveyRun> findForRecipient(String userName) {
checkNotNull(userName, "userName cannot be null");
Person person = personDao.getActiveByUserEmail(userName);
checkNotNull(person, "userName " + userName + " cannot be resolved");
return surveyRunDao.findForRecipient(person.id().get());
}
use of org.finos.waltz.model.person.Person in project waltz by khartec.
the class SurveyRunService method generateSurveyInstanceOwners.
public List<SurveyInstanceOwner> generateSurveyInstanceOwners(InstancesAndRecipientsCreateCommand command) {
SurveyRun surveyRun = surveyRunDao.getById(command.surveyRunId());
checkNotNull(surveyRun, "surveyRun " + command.surveyRunId() + " not found");
SurveyTemplate surveyTemplate = surveyTemplateDao.getById(surveyRun.surveyTemplateId());
checkNotNull(surveyTemplate, "surveyTemplate " + surveyRun.surveyTemplateId() + " not found");
GenericSelector genericSelector = genericSelectorFactory.applyForKind(surveyTemplate.targetEntityKind(), surveyRun.selectionOptions());
Map<EntityReference, List<Person>> entityRefToPeople = involvementDao.findPeopleByEntitySelectorAndInvolvement(surveyTemplate.targetEntityKind(), genericSelector.selector(), surveyRun.ownerInvKindIds());
return entityRefToPeople.entrySet().stream().flatMap(e -> e.getValue().stream().map(p -> ImmutableSurveyInstanceOwner.builder().surveyInstance(ImmutableSurveyInstance.builder().surveyEntity(e.getKey()).surveyRunId(command.surveyRunId()).status(SurveyInstanceStatus.NOT_STARTED).dueDate(command.dueDate()).approvalDueDate(command.approvalDueDate()).owningRole(command.owningRole()).build()).person(p).build())).distinct().collect(toList());
}
use of org.finos.waltz.model.person.Person in project waltz by khartec.
the class SurveyRunService method findByTemplateId.
public List<SurveyRunWithOwnerAndStats> findByTemplateId(long templateId) {
List<SurveyRun> runs = surveyRunDao.findByTemplateId(templateId);
Set<Person> owners = personDao.findByIds(SetUtilities.map(runs, SurveyRun::ownerId));
Map<Long, Person> ownersById = indexBy(owners, p -> p.id().orElse(-1L));
List<SurveyRunCompletionRate> stats = surveyInstanceDao.findCompletionRateForSurveyTemplate(templateId);
Map<Long, SurveyRunCompletionRate> statsByRunId = indexBy(stats, s -> s.surveyRunId());
return map(runs, run -> {
Person owner = ownersById.get(run.ownerId());
Long runId = run.id().orElse(-1L);
SurveyRunCompletionRate completionRateStats = statsByRunId.getOrDefault(runId, SurveyRunCompletionRate.mkNoData(runId));
return ImmutableSurveyRunWithOwnerAndStats.builder().surveyRun(run).owner(owner).completionRateStats(completionRateStats).build();
});
}
Aggregations