use of com.khartec.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.getByUserName(userName);
checkNotNull(owner, "userName " + userName + " cannot be resolved");
long surveyRunId = surveyRunDao.create(owner.id().get(), command);
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 com.khartec.waltz.model.person.Person in project waltz by khartec.
the class SurveyRunService method validateSurveyRunUpdate.
private void validateSurveyRunUpdate(String userName, long surveyRunId) {
Person owner = personDao.getByUserName(userName);
checkNotNull(owner, "userName " + userName + " cannot be resolved");
SurveyRun surveyRun = surveyRunDao.getById(surveyRunId);
checkNotNull(surveyRun, "surveyRun " + surveyRunId + " not found");
checkTrue(Objects.equals(surveyRun.ownerId(), owner.id().get()), "Permission denied");
checkTrue(surveyRun.status() == SurveyRunStatus.DRAFT, "survey run can only be updated when it's still in DRAFT mode");
}
use of com.khartec.waltz.model.person.Person 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());
}
use of com.khartec.waltz.model.person.Person in project waltz by khartec.
the class SurveyTemplateService method findAll.
public List<SurveyTemplate> findAll(String userName) {
checkNotNull(userName, "userName cannot be null");
Person owner = personDao.getByUserName(userName);
checkNotNull(owner, "userName " + userName + " cannot be resolved");
return surveyTemplateDao.findAll(owner.id().get());
}
use of com.khartec.waltz.model.person.Person in project waltz by khartec.
the class UserContributionService method findScoresForDirectReports.
public List<Tally<String>> findScoresForDirectReports(String userId) {
checkNotEmpty(userId, "userId cannot be empty");
Person person = personDao.findPersonByUserId(userId);
if (person == null) {
return Collections.emptyList();
}
List<Person> directs = personDao.findDirectsByEmployeeId(person.employeeId());
List<String> directUserIds = map(directs, p -> p.userId());
return changeLogDao.getContributionScoresForUsers(directUserIds);
}
Aggregations