Search in sources :

Example 26 with Person

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

the class SurveyInstanceViewService method getPersonByUsername.

private Person getPersonByUsername(String userName) {
    Person person = personDao.getActiveByUserEmail(userName);
    checkNotNull(person, "userName %s cannot be resolved", userName);
    return person;
}
Also used : Person(org.finos.waltz.model.person.Person)

Example 27 with Person

use of org.finos.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.getActiveByUserEmail(userName);
    checkNotNull(owner, "userName " + userName + " cannot be resolved");
    return surveyTemplateDao.findAll(owner.id().get());
}
Also used : Person(org.finos.waltz.model.person.Person)

Example 28 with Person

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

the class InvolvementViewService method findAllByEmployeeId.

public Set<InvolvementViewItem> findAllByEmployeeId(String employeeId) {
    List<Involvement> involvements = involvementService.findAllByEmployeeId(employeeId);
    Set<String> employeeIds = map(involvements, Involvement::employeeId);
    Set<Person> involvedPeople = personService.findByEmployeeIds(employeeIds);
    Map<String, Person> peopleByEmployeeId = indexBy(involvedPeople, Person::employeeId);
    return involvements.stream().map(d -> {
        Person person = peopleByEmployeeId.getOrDefault(d.employeeId(), null);
        if (person == null) {
            return null;
        }
        return mkInvolvementViewItem(d, person);
    }).filter(Objects::nonNull).collect(toSet());
}
Also used : Person(org.finos.waltz.model.person.Person)

Example 29 with Person

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

the class UserRoleService method updateRoles.

public boolean updateRoles(String userName, String targetUserName, UpdateRolesCommand command) {
    LOG.info("Updating roles for userName: {}, new roles: {}", targetUserName, command.roles());
    Person person = personService.getPersonByUserId(targetUserName);
    if (person == null) {
        LOG.warn("{} does not exist, cannot create audit log for role updates", targetUserName);
    } else {
        ImmutableChangeLog logEntry = ImmutableChangeLog.builder().parentReference(mkRef(EntityKind.PERSON, person.id().get())).severity(Severity.INFORMATION).userId(userName).message(format("Roles for %s updated to %s.  Comment: %s", targetUserName, sort(command.roles()), StringUtilities.ifEmpty(command.comment(), "none"))).childKind(Optional.empty()).operation(Operation.UPDATE).build();
        changeLogService.write(logEntry);
    }
    return userRoleDao.updateRoles(targetUserName, command.roles());
}
Also used : ImmutableChangeLog(org.finos.waltz.model.changelog.ImmutableChangeLog) Person(org.finos.waltz.model.person.Person)

Example 30 with Person

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

the class SurveyInstanceService method getPermissions.

public SurveyInstancePermissions getPermissions(String userName, Long instanceId) {
    Person person = personDao.getActiveByUserEmail(userName);
    SurveyInstance instance = surveyInstanceDao.getById(instanceId);
    SurveyRun run = surveyRunDao.getById(instance.surveyRunId());
    boolean isAdmin = userRoleService.hasRole(userName, SystemRole.SURVEY_ADMIN);
    boolean isParticipant = surveyInstanceRecipientDao.isPersonInstanceRecipient(person.id().get(), instanceId);
    boolean isOwner = person.id().map(pid -> surveyInstanceOwnerDao.isPersonInstanceOwner(pid, instanceId) || Objects.equals(run.ownerId(), pid)).orElse(false);
    boolean hasOwningRole = userRoleService.hasRole(person.email(), instance.owningRole());
    boolean isLatest = instance.originalInstanceId() == null;
    boolean editableStatus = instance.status() == SurveyInstanceStatus.NOT_STARTED || instance.status() == SurveyInstanceStatus.IN_PROGRESS;
    return ImmutableSurveyInstancePermissions.builder().isAdmin(isAdmin).isParticipant(isParticipant).isOwner(isOwner).hasOwnerRole(hasOwningRole).isMetaEdit(isLatest && (isAdmin || isOwner || hasOwningRole)).canEdit(isLatest && isParticipant && editableStatus).build();
}
Also used : org.finos.waltz.data.survey(org.finos.waltz.data.survey) java.util(java.util) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) EntityKind(org.finos.waltz.model.EntityKind) Autowired(org.springframework.beans.factory.annotation.Autowired) ImmutableChangeLog(org.finos.waltz.model.changelog.ImmutableChangeLog) Person(org.finos.waltz.model.person.Person) SurveyInstanceStateMachineFactory.simple(org.finos.waltz.model.survey.SurveyInstanceStateMachineFactory.simple) UserRoleService(org.finos.waltz.service.user.UserRoleService) Record1(org.jooq.Record1) Service(org.springframework.stereotype.Service) StringUtilities.joinUsing(org.finos.waltz.common.StringUtilities.joinUsing) Select(org.jooq.Select) IdUtilities.indexByOptionalId(org.finos.waltz.model.utils.IdUtilities.indexByOptionalId) ChangeLogService(org.finos.waltz.service.changelog.ChangeLogService) CollectionUtilities.isEmpty(org.finos.waltz.common.CollectionUtilities.isEmpty) org.finos.waltz.model.survey(org.finos.waltz.model.survey) PersonDao(org.finos.waltz.data.person.PersonDao) String.format(java.lang.String.format) Operation(org.finos.waltz.model.Operation) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) LocalDate(java.time.LocalDate) SetUtilities(org.finos.waltz.common.SetUtilities) CollectionUtilities.find(org.finos.waltz.common.CollectionUtilities.find) EntityReference(org.finos.waltz.model.EntityReference) SystemRole(org.finos.waltz.model.user.SystemRole) Checks(org.finos.waltz.common.Checks) IdUtilities(org.finos.waltz.model.utils.IdUtilities) 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