Search in sources :

Example 11 with Person

use of org.finos.waltz.model.person.Person in project waltz by khartec.

the class SurveyInstanceService method findForRecipient.

public Set<SurveyInstance> findForRecipient(String userName) {
    checkNotNull(userName, "userName cannot be null");
    Person person = getPersonByUsername(userName);
    return surveyInstanceDao.findForRecipient(person.id().get());
}
Also used : Person(org.finos.waltz.model.person.Person)

Example 12 with Person

use of org.finos.waltz.model.person.Person in project waltz by khartec.

the class SurveyInstanceService method checkPersonIsOwnerOrAdmin.

public Person checkPersonIsOwnerOrAdmin(String userName, long instanceId) {
    Person person = getPersonByUsername(userName);
    checkTrue(isAdmin(userName) || isOwner(instanceId, person) || hasOwningRole(instanceId, person), "Permission denied");
    return person;
}
Also used : Person(org.finos.waltz.model.person.Person)

Example 13 with Person

use of org.finos.waltz.model.person.Person in project waltz by khartec.

the class SurveyInstanceService method checkPersonIsRecipient.

public Person checkPersonIsRecipient(String userName, long instanceId) {
    Person person = getPersonByUsername(userName);
    boolean isPersonInstanceRecipient = surveyInstanceRecipientDao.isPersonInstanceRecipient(person.id().get(), instanceId);
    checkTrue(isPersonInstanceRecipient, "Permission denied");
    return person;
}
Also used : Person(org.finos.waltz.model.person.Person)

Example 14 with Person

use of org.finos.waltz.model.person.Person in project waltz by khartec.

the class SurveyRunService method generateSurveyInstanceRecipients.

public List<SurveyInstanceRecipient> generateSurveyInstanceRecipients(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.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(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 15 with Person

use of org.finos.waltz.model.person.Person in project waltz by khartec.

the class SurveyRunService method validateSurveyRunUpdate.

private void validateSurveyRunUpdate(String userName, long surveyRunId) {
    Person owner = validateUser(userName);
    SurveyRun surveyRun = validateSurveyRun(surveyRunId);
    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(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