Search in sources :

Example 6 with Person

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();
}
Also used : Person(com.khartec.waltz.model.person.Person)

Example 7 with Person

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");
}
Also used : Person(com.khartec.waltz.model.person.Person)

Example 8 with Person

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());
}
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)

Example 9 with Person

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());
}
Also used : Person(com.khartec.waltz.model.person.Person)

Example 10 with Person

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);
}
Also used : Person(com.khartec.waltz.model.person.Person)

Aggregations

Person (com.khartec.waltz.model.person.Person)12 PersonDao (com.khartec.waltz.data.person.PersonDao)2 SurveyTemplateDao (com.khartec.waltz.data.survey.SurveyTemplateDao)2 com.khartec.waltz.model.survey (com.khartec.waltz.model.survey)2 LocalDate (java.time.LocalDate)2 Record1 (org.jooq.Record1)2 Select (org.jooq.Select)2 ArrayUtilities (com.khartec.waltz.common.ArrayUtilities)1 Checks.checkFalse (com.khartec.waltz.common.Checks.checkFalse)1 Checks.checkNotNull (com.khartec.waltz.common.Checks.checkNotNull)1 Checks.checkTrue (com.khartec.waltz.common.Checks.checkTrue)1 CollectionUtilities.isEmpty (com.khartec.waltz.common.CollectionUtilities.isEmpty)1 CollectionUtilities.randomPick (com.khartec.waltz.common.CollectionUtilities.randomPick)1 DateTimeUtilities.nowUtc (com.khartec.waltz.common.DateTimeUtilities.nowUtc)1 SetUtilities.fromCollection (com.khartec.waltz.common.SetUtilities.fromCollection)1 IdSelectorFactory (com.khartec.waltz.data.IdSelectorFactory)1 IdSelectorFactoryProvider (com.khartec.waltz.data.IdSelectorFactoryProvider)1 AppGroupDao (com.khartec.waltz.data.app_group.AppGroupDao)1 InvolvementDao (com.khartec.waltz.data.involvement.InvolvementDao)1 InvolvementKindDao (com.khartec.waltz.data.involvement_kind.InvolvementKindDao)1