Search in sources :

Example 21 with Person

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

Example 22 with Person

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

Example 23 with Person

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

Example 24 with Person

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());
}
Also used : org.finos.waltz.data.survey(org.finos.waltz.data.survey) java.util(java.util) org.finos.waltz.model(org.finos.waltz.model) InvolvementDao(org.finos.waltz.data.involvement.InvolvementDao) GenericSelector(org.finos.waltz.data.GenericSelector) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Autowired(org.springframework.beans.factory.annotation.Autowired) ImmutableChangeLog(org.finos.waltz.model.changelog.ImmutableChangeLog) Person(org.finos.waltz.model.person.Person) Checks.checkTrue(org.finos.waltz.common.Checks.checkTrue) GenericSelectorFactory(org.finos.waltz.data.GenericSelectorFactory) Record1(org.jooq.Record1) Service(org.springframework.stereotype.Service) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) Select(org.jooq.Select) ChangeLogService(org.finos.waltz.service.changelog.ChangeLogService) org.finos.waltz.model.survey(org.finos.waltz.model.survey) PersonDao(org.finos.waltz.data.person.PersonDao) MapUtilities.indexBy(org.finos.waltz.common.MapUtilities.indexBy) ListUtilities.map(org.finos.waltz.common.ListUtilities.map) Collectors.toList(java.util.stream.Collectors.toList) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) ListUtilities(org.finos.waltz.common.ListUtilities) LocalDate(java.time.LocalDate) SetUtilities(org.finos.waltz.common.SetUtilities) SetUtilities.fromCollection(org.finos.waltz.common.SetUtilities.fromCollection) GenericSelector(org.finos.waltz.data.GenericSelector) Collectors.toList(java.util.stream.Collectors.toList)

Example 25 with Person

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

Aggregations

Person (org.finos.waltz.model.person.Person)34 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Service (org.springframework.stereotype.Service)5 LocalDate (java.time.LocalDate)4 java.util (java.util)4 PersonDao (org.finos.waltz.data.person.PersonDao)4 EntityKind (org.finos.waltz.model.EntityKind)4 org.finos.waltz.model.survey (org.finos.waltz.model.survey)4 Record1 (org.jooq.Record1)4 Select (org.jooq.Select)4 Collectors (java.util.stream.Collectors)3 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)3 ListUtilities.map (org.finos.waltz.common.ListUtilities.map)3 MapUtilities.indexBy (org.finos.waltz.common.MapUtilities.indexBy)3 ImmutableChangeLog (org.finos.waltz.model.changelog.ImmutableChangeLog)3 IOException (java.io.IOException)2 List (java.util.List)2 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)2 Collectors.toList (java.util.stream.Collectors.toList)2 Checks.checkTrue (org.finos.waltz.common.Checks.checkTrue)2