Search in sources :

Example 16 with Person

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

the class SurveyRunService method validateUser.

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

Example 17 with Person

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

the class SurveyTemplateEndpoint method ensureUserIsOwnerOrAdmin.

private void ensureUserIsOwnerOrAdmin(Request request, Long templateId, String username) {
    Person person = personService.getPersonByUserId(username);
    if (person == null) {
        throw new IllegalArgumentException("User not found");
    }
    SurveyTemplate template = surveyTemplateService.getById(templateId);
    // if person record found id is always present
    person.id().ifPresent(id -> {
        if (template.ownerId().equals(id)) {
            WebUtilities.requireRole(userRoleService, request, SystemRole.SURVEY_TEMPLATE_ADMIN);
        } else {
            WebUtilities.requireRole(userRoleService, request, SystemRole.ADMIN);
        }
    });
}
Also used : SurveyTemplate(org.finos.waltz.model.survey.SurveyTemplate) Person(org.finos.waltz.model.person.Person)

Example 18 with Person

use of org.finos.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.getByUserEmail(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(org.finos.waltz.model.person.Person)

Example 19 with Person

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

the class AttestationInstanceEndpoint method register.

@Override
public void register() {
    String attestInstancePath = mkPath(BASE_URL, "attest", ":id");
    String attestEntityForUserPath = mkPath(BASE_URL, "attest-entity");
    String findByEntityRefPath = mkPath(BASE_URL, "entity", ":kind", ":id");
    String findByRunIdPath = mkPath(BASE_URL, "run", ":id");
    String findUnattestedByUserPath = mkPath(BASE_URL, "unattested", "user");
    String findAllByUserPath = mkPath(BASE_URL, "all", "user");
    String findHistoricalForPendingByUserPath = mkPath(BASE_URL, "historical", "user");
    String findPersonsByInstancePath = mkPath(BASE_URL, ":id", "person");
    String findBySelectorPath = mkPath(BASE_URL, "selector");
    String findLatestMeasurableAttestationsPath = mkPath(BASE_URL, "latest", "measurable-category", "entity", ":kind", ":id");
    String findApplicationAttestationInstancesForKindAndSelectorPath = mkPath(BASE_URL, "applications", "attested-entity", ":kind", ":id");
    String findApplicationAttestationSummaryForSelectorPath = mkPath(BASE_URL, "app-summary");
    String cleanupOrphansPath = mkPath(BASE_URL, "cleanup-orphans");
    String reassignRecipientsPath = mkPath(BASE_URL, "reassign-recipients");
    String getCountsOfRecipientsToReassignPath = mkPath(BASE_URL, "reassign-counts");
    DatumRoute<Boolean> attestInstanceRoute = (req, res) -> attestationInstanceService.attestInstance(getId(req), getUsername(req));
    ListRoute<AttestationInstance> findByEntityRefRoute = (req, res) -> attestationInstanceService.findByEntityReference(getEntityReference(req));
    ListRoute<AttestationInstance> findUnattestedByRecipientRoute = (req, res) -> attestationInstanceService.findByRecipient(getUsername(req), true);
    ListRoute<AttestationInstance> findAllByRecipientRoute = (req, res) -> attestationInstanceService.findByRecipient(getUsername(req), false);
    ListRoute<AttestationInstance> findHistoricalForPendingByRecipientRoute = (req, res) -> attestationInstanceService.findHistoricalForPendingByUserId(getUsername(req));
    ListRoute<AttestationInstance> findByRunIdRoute = (req, res) -> attestationInstanceService.findByRunId(getId(req));
    ListRoute<Person> findPersonsByInstanceRoute = (request, response) -> {
        long id = Long.valueOf(request.params("id"));
        return attestationInstanceService.findPersonsByInstanceId(id);
    };
    ListRoute<AttestationInstance> findBySelectorRoute = ((request, response) -> attestationInstanceService.findByIdSelector(readIdSelectionOptionsFromBody(request)));
    ListRoute<LatestMeasurableAttestationInfo> findLatestMeasurableAttestationsRoute = ((request, response) -> attestationInstanceService.findLatestMeasurableAttestations(getEntityReference(request)));
    ListRoute<ApplicationAttestationInstanceSummary> findApplicationAttestationInstancesForKindAndSelectorRoute = ((request, response) -> {
        EntityKind attestedKind = getKind(request);
        Long attestedId = StringUtilities.parseLong(request.params("id"), null);
        ApplicationAttestationInstanceInfo applicationAttestationInstanceInfo = readBody(request, ApplicationAttestationInstanceInfo.class);
        return attestationInstanceService.findApplicationAttestationInstancesForKindAndSelector(attestedKind, attestedId, applicationAttestationInstanceInfo);
    });
    ListRoute<ApplicationAttestationSummaryCounts> findApplicationAttestationSummaryForSelectorRoute = ((request, response) -> attestationInstanceService.findAttestationInstanceSummaryForSelector(readBody(request, ApplicationAttestationInstanceInfo.class)));
    DatumRoute<Boolean> attestEntityForUserRoute = (req, res) -> attestationInstanceService.attestForEntity(getUsername(req), readCreateCommand(req));
    postForDatum(attestInstancePath, attestInstanceRoute);
    postForDatum(attestEntityForUserPath, attestEntityForUserRoute);
    getForList(findByEntityRefPath, findByEntityRefRoute);
    getForList(findUnattestedByUserPath, findUnattestedByRecipientRoute);
    getForList(findAllByUserPath, findAllByRecipientRoute);
    getForList(findHistoricalForPendingByUserPath, findHistoricalForPendingByRecipientRoute);
    getForList(findByRunIdPath, findByRunIdRoute);
    getForList(findPersonsByInstancePath, findPersonsByInstanceRoute);
    getForList(findLatestMeasurableAttestationsPath, findLatestMeasurableAttestationsRoute);
    postForList(findBySelectorPath, findBySelectorRoute);
    postForList(findApplicationAttestationInstancesForKindAndSelectorPath, findApplicationAttestationInstancesForKindAndSelectorRoute);
    postForList(findApplicationAttestationSummaryForSelectorPath, findApplicationAttestationSummaryForSelectorRoute);
    getForDatum(cleanupOrphansPath, this::cleanupOrphansRoute);
    postForDatum(reassignRecipientsPath, this::reassignRecipientsRoute);
    getForDatum(getCountsOfRecipientsToReassignPath, this::getCountsOfRecipientsToReassign);
}
Also used : ListRoute(org.finos.waltz.web.ListRoute) Logger(org.slf4j.Logger) Endpoint(org.finos.waltz.web.endpoints.Endpoint) EntityKind(org.finos.waltz.model.EntityKind) DatumRoute(org.finos.waltz.web.DatumRoute) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) Person(org.finos.waltz.model.person.Person) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) UserRoleService(org.finos.waltz.service.user.UserRoleService) Service(org.springframework.stereotype.Service) Request(spark.Request) AttestationInstanceService(org.finos.waltz.service.attestation.AttestationInstanceService) WebUtilities(org.finos.waltz.web.WebUtilities) SystemRole(org.finos.waltz.model.user.SystemRole) Response(spark.Response) org.finos.waltz.model.attestation(org.finos.waltz.model.attestation) EndpointUtilities(org.finos.waltz.web.endpoints.EndpointUtilities) StringUtilities(org.finos.waltz.common.StringUtilities) Person(org.finos.waltz.model.person.Person) EntityKind(org.finos.waltz.model.EntityKind)

Example 20 with Person

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

the class PersonHierarchyService method toHierarchyRecords.

private List<PersonHierarchyRecord> toHierarchyRecords(Forest<Person, String> forest) {
    List<PersonHierarchyRecord> records = new LinkedList<>();
    for (Node<Person, String> node : forest.getAllNodes().values()) {
        List<Person> ancestors = ListUtilities.reverse(HierarchyUtilities.parents(node).stream().map(Node::getData).collect(Collectors.toList()));
        for (int i = 0; i < ancestors.size(); i++) {
            String ancestorId = ancestors.get(i).employeeId();
            String selfId = node.getData().employeeId();
            PersonHierarchyRecord record = new PersonHierarchyRecord(ancestorId, selfId, i + 1);
            records.add(record);
        }
    }
    return records;
}
Also used : Node(org.finos.waltz.common.hierarchy.Node) FlatNode(org.finos.waltz.common.hierarchy.FlatNode) PersonHierarchyRecord(org.finos.waltz.schema.tables.records.PersonHierarchyRecord) Person(org.finos.waltz.model.person.Person) LinkedList(java.util.LinkedList)

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