Search in sources :

Example 1 with Person

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

the class PermissionGroupService method findPermissions.

public List<Permission> findPermissions(EntityReference parentEntityRef, String username) {
    Person person = personService.getPersonByUserId(username);
    if (isNull(person)) {
        return Collections.emptyList();
    }
    List<Involvement> involvements = involvementService.findByEmployeeId(person.employeeId()).stream().filter(involvement -> involvement.entityReference().equals(parentEntityRef)).collect(Collectors.toList());
    if (involvements.isEmpty()) {
        return Collections.emptyList();
    }
    return permissionGroupDao.getDefaultPermissions();
}
Also used : Logger(org.slf4j.Logger) EntityKind(org.finos.waltz.model.EntityKind) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) PersonService(org.finos.waltz.service.person.PersonService) Collectors(java.util.stream.Collectors) Person(org.finos.waltz.model.person.Person) InvolvementService(org.finos.waltz.service.involvement.InvolvementService) List(java.util.List) Involvement(org.finos.waltz.model.involvement.Involvement) Service(org.springframework.stereotype.Service) EntityReference(org.finos.waltz.model.EntityReference) Objects.isNull(java.util.Objects.isNull) Permission(org.finos.waltz.model.permission_group.Permission) Collections(java.util.Collections) Involvement(org.finos.waltz.model.involvement.Involvement) Person(org.finos.waltz.model.person.Person)

Example 2 with Person

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

the class PersonHierarchyService method build.

public int[] build() {
    LOG.warn("Building person hierarchy");
    List<Person> all = personDao.all();
    Forest<Person, String> forest = toForest(all);
    List<PersonHierarchyRecord> records = toHierarchyRecords(forest);
    return dsl.transactionResult(configuration -> {
        DSLContext txDsl = DSL.using(configuration);
        txDsl.deleteFrom(PERSON_HIERARCHY).execute();
        return txDsl.batchStore(records).execute();
    });
}
Also used : PersonHierarchyRecord(org.finos.waltz.schema.tables.records.PersonHierarchyRecord) DSLContext(org.jooq.DSLContext) Person(org.finos.waltz.model.person.Person)

Example 3 with Person

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

the class InvolvementService method mkInvolvement.

private Involvement mkInvolvement(EntityReference entityReference, EntityInvolvementChangeCommand command) {
    checkNotNull(entityReference, "entityReference cannot be null");
    checkNotNull(command, "command cannot be null");
    Person person = personDao.getById(command.personEntityRef().id());
    return Involvement.mkInvolvement(entityReference, person.employeeId(), command.involvementKindId(), "waltz", false);
}
Also used : Person(org.finos.waltz.model.person.Person)

Example 4 with Person

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

the class InvolvementImporter method main.

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    ApplicationService applicationService = ctx.getBean(ApplicationService.class);
    PersonService personService = ctx.getBean(PersonService.class);
    Map<String, Application> appsByExtId = indexBy(a -> ExternalIdValue.orElse(a.assetCode(), null), applicationService.findAll());
    Map<String, Person> peopleByName = indexBy(p -> toSurnameFirstname(p.displayName()).toLowerCase(), personService.all());
    Siphon<String[]> incorrectSizeSiphon = mkSiphon(arr -> arr.length != 3);
    Siphon<Tuple2<String, ?>> unknownAppSiphon = mkSiphon(t -> !appsByExtId.containsKey(t.v1));
    Siphon<Tuple2<?, String>> unknownPersonSiphon = mkSiphon(t -> !peopleByName.containsKey(t.v2.toLowerCase()));
    Siphon<Tuple2<Application, ?>> retiredAppSiphon = mkSiphon(t -> t.v1.lifecyclePhase() == LifecyclePhase.RETIRED);
    List<Tuple2<Application, Person>> r = IOUtilities.streamLines(classLoader.getResourceAsStream(fileName)).map(line -> line.split("\t")).filter(d -> incorrectSizeSiphon.test(d)).map(arr -> Tuple.tuple(arr[1], arr[0])).filter(t -> unknownAppSiphon.test(t)).map(t -> t.map1(extId -> appsByExtId.get(extId))).filter(t -> retiredAppSiphon.test(t)).filter(t -> unknownPersonSiphon.test(t)).map(t -> t.map2(n -> peopleByName.get(n.toLowerCase()))).collect(Collectors.toList());
    Set<Application> distinctApps = r.stream().map(t -> t.v1).distinct().collect(Collectors.toSet());
    Set<Person> distinctPeople = r.stream().map(t -> t.v2).distinct().collect(Collectors.toSet());
    System.out.println("----");
    System.out.println("Wrong size count: " + incorrectSizeSiphon.getResults().size());
    System.out.println("Apps not found count: " + unknownAppSiphon.getResults().size());
    System.out.println("Retired app count: " + retiredAppSiphon.getResults().size());
    System.out.println("Person not found count: " + unknownPersonSiphon.getResults().size());
    System.out.println("----");
    System.out.println("Good record count: " + r.size());
    System.out.println("Distinct App count: " + distinctApps.size());
    System.out.println("Distinct People count: " + distinctPeople.size());
    Map<String, Long> unknownPersonCounts = countBy(Tuple2::v2, unknownPersonSiphon.getResults());
    DebugUtilities.dump(unknownPersonCounts);
}
Also used : LifecyclePhase(org.finos.waltz.model.application.LifecyclePhase) ApplicationService(org.finos.waltz.service.application.ApplicationService) Application(org.finos.waltz.model.application.Application) ArrayUtilities(org.finos.waltz.common.ArrayUtilities) Set(java.util.Set) StreamUtilities.mkSiphon(org.finos.waltz.common.StreamUtilities.mkSiphon) DIConfiguration(org.finos.waltz.service.DIConfiguration) IOException(java.io.IOException) PersonService(org.finos.waltz.service.person.PersonService) MapUtilities.countBy(org.finos.waltz.common.MapUtilities.countBy) Collectors(java.util.stream.Collectors) IOUtilities(org.finos.waltz.common.IOUtilities) Person(org.finos.waltz.model.person.Person) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MapUtilities.indexBy(org.finos.waltz.common.MapUtilities.indexBy) Tuple2(org.jooq.lambda.tuple.Tuple2) List(java.util.List) DebugUtilities(org.finos.waltz.common.DebugUtilities) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) Tuple(org.jooq.lambda.tuple.Tuple) Map(java.util.Map) Siphon(org.finos.waltz.common.StreamUtilities.Siphon) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PersonService(org.finos.waltz.service.person.PersonService) Tuple2(org.jooq.lambda.tuple.Tuple2) Application(org.finos.waltz.model.application.Application) Person(org.finos.waltz.model.person.Person) ApplicationService(org.finos.waltz.service.application.ApplicationService)

Example 5 with Person

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

the class SurveyRunGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    final DSLContext dsl = ctx.getBean(DSLContext.class);
    List<Person> owners = dsl.selectFrom(PERSON).limit(NUMBER_OF_RUNS).fetch().map(PersonDao.personMapper);
    checkFalse(isEmpty(owners), "No person found, please generate person data first");
    final SurveyTemplateDao surveyTemplateDao = ctx.getBean(SurveyTemplateDao.class);
    List<SurveyTemplate> surveyTemplates = surveyTemplateDao.findAllActive();
    checkFalse(isEmpty(surveyTemplates), "No template found, please generate templates first");
    final AppGroupDao appGroupDao = ctx.getBean(AppGroupDao.class);
    List<AppGroup> appGroups = appGroupDao.findPublicGroups();
    checkFalse(isEmpty(appGroups), "No public app group found, please generate app groups first");
    final InvolvementKindDao involvementKindDao = ctx.getBean(InvolvementKindDao.class);
    List<InvolvementKind> involvementKinds = involvementKindDao.findAll();
    final SurveyRunService surveyRunService = ctx.getBean(SurveyRunService.class);
    final SurveyInstanceService surveyInstanceService = ctx.getBean(SurveyInstanceService.class);
    final SurveyQuestionService surveyQuestionService = ctx.getBean(SurveyQuestionService.class);
    AtomicInteger surveyCompletedCount = new AtomicInteger(0);
    IntStream.range(0, NUMBER_OF_RUNS).forEach(idx -> {
        SurveyTemplate surveyTemplate = surveyTemplates.get(random.nextInt(surveyTemplates.size()));
        Person owner = owners.get(random.nextInt(owners.size()));
        SurveyRunRecord surveyRunRecord = mkRandomSurveyRunRecord(dsl, appGroups, involvementKinds, surveyTemplate, owner);
        surveyRunRecord.store();
        long surveyRunId = surveyRunRecord.getId();
        LOG.debug("Survey Run: {} / {} / {}", surveyRunRecord.getStatus(), surveyRunId, surveyRunRecord.getName());
        ImmutableInstancesAndRecipientsCreateCommand createCmd = ImmutableInstancesAndRecipientsCreateCommand.builder().surveyRunId(surveyRunId).dueDate(toLocalDate(nowUtcTimestamp())).approvalDueDate(toLocalDate(nowUtcTimestamp())).excludedRecipients(emptySet()).build();
        surveyRunService.createSurveyInstancesAndRecipients(createCmd);
        List<SurveyInstanceQuestionResponse> surveyInstanceQuestionResponses = mkRandomSurveyRunResponses(surveyRunId, surveyInstanceService, surveyQuestionService);
        Map<SurveyInstanceStatus, Set<Long>> surveyInstanceStatusMap = surveyInstanceQuestionResponses.stream().mapToLong(response -> response.surveyInstanceId()).distinct().mapToObj(id -> tuple(randomPick(SurveyInstanceStatus.NOT_STARTED, SurveyInstanceStatus.IN_PROGRESS, SurveyInstanceStatus.COMPLETED), id)).collect(groupingBy(t -> t.v1, mapping(t -> t.v2, toSet())));
        dsl.batchInsert(surveyInstanceQuestionResponses.stream().map(r -> {
            if (surveyInstanceStatusMap.containsKey(SurveyInstanceStatus.NOT_STARTED) && surveyInstanceStatusMap.get(SurveyInstanceStatus.NOT_STARTED).contains(r.surveyInstanceId())) {
                // don't create response for NOT_STARTED
                return null;
            }
            SurveyQuestionResponse questionResponse = r.questionResponse();
            SurveyQuestionResponseRecord record = new SurveyQuestionResponseRecord();
            record.setSurveyInstanceId(r.surveyInstanceId());
            record.setPersonId(r.personId());
            record.setQuestionId(questionResponse.questionId());
            record.setBooleanResponse(questionResponse.booleanResponse().orElse(null));
            record.setNumberResponse(questionResponse.numberResponse().map(BigDecimal::valueOf).orElse(null));
            record.setStringResponse(questionResponse.stringResponse().orElse(null));
            record.setComment(r.questionResponse().comment().orElse(null));
            record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
            return record;
        }).filter(Objects::nonNull).collect(toList())).execute();
        if (SurveyRunStatus.valueOf(surveyRunRecord.getStatus()) == SurveyRunStatus.COMPLETED) {
            surveyRunRecord.setStatus(SurveyRunStatus.COMPLETED.name());
            surveyRunRecord.store();
            surveyCompletedCount.incrementAndGet();
            // update instances to COMPLETED
            if (surveyInstanceStatusMap.containsKey(SurveyInstanceStatus.COMPLETED)) {
                Set<Long> completedInstanceIds = surveyInstanceStatusMap.get(SurveyInstanceStatus.COMPLETED);
                dsl.update(SURVEY_INSTANCE).set(SURVEY_INSTANCE.STATUS, SurveyInstanceStatus.COMPLETED.name()).where(SURVEY_INSTANCE.ID.in(completedInstanceIds)).execute();
                LOG.debug(" --- {} instances: {}", SurveyInstanceStatus.COMPLETED, completedInstanceIds);
            }
        } else {
            surveyInstanceStatusMap.forEach(((status, instanceIds) -> {
                dsl.update(SURVEY_INSTANCE).set(SURVEY_INSTANCE.STATUS, status.name()).where(SURVEY_INSTANCE.ID.in(instanceIds)).execute();
                LOG.debug(" --- {} instances: {}", status.name(), instanceIds);
            }));
        }
    });
    LOG.debug("Generated: {} survey runs, in which {} are completed", NUMBER_OF_RUNS, surveyCompletedCount.get());
    return null;
}
Also used : SurveyQuestionService(org.finos.waltz.service.survey.SurveyQuestionService) IntStream(java.util.stream.IntStream) SurveyRunService(org.finos.waltz.service.survey.SurveyRunService) java.util(java.util) DSL(org.jooq.impl.DSL) SURVEY_INSTANCE_RECIPIENT(org.finos.waltz.schema.tables.SurveyInstanceRecipient.SURVEY_INSTANCE_RECIPIENT) EntityKind(org.finos.waltz.model.EntityKind) InvolvementKindDao(org.finos.waltz.data.involvement_kind.InvolvementKindDao) LoggerFactory(org.slf4j.LoggerFactory) AppGroup(org.finos.waltz.model.app_group.AppGroup) SurveyQuestionService(org.finos.waltz.service.survey.SurveyQuestionService) AppGroupDao(org.finos.waltz.data.app_group.AppGroupDao) Person(org.finos.waltz.model.person.Person) Condition(org.jooq.Condition) SurveyRunRecord(org.finos.waltz.schema.tables.records.SurveyRunRecord) BigDecimal(java.math.BigDecimal) Tuple2(org.jooq.lambda.tuple.Tuple2) Checks.checkFalse(org.finos.waltz.common.Checks.checkFalse) Record1(org.jooq.Record1) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvolvementKind(org.finos.waltz.model.involvement_kind.InvolvementKind) DSLContext(org.jooq.DSLContext) SURVEY_QUESTION_RESPONSE(org.finos.waltz.schema.tables.SurveyQuestionResponse.SURVEY_QUESTION_RESPONSE) Select(org.jooq.Select) SurveyTemplateDao(org.finos.waltz.data.survey.SurveyTemplateDao) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) CollectionUtilities.isEmpty(org.finos.waltz.common.CollectionUtilities.isEmpty) org.finos.waltz.model.survey(org.finos.waltz.model.survey) SURVEY_INSTANCE(org.finos.waltz.schema.Tables.SURVEY_INSTANCE) PersonDao(org.finos.waltz.data.person.PersonDao) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) SURVEY_RUN(org.finos.waltz.schema.Tables.SURVEY_RUN) RandomUtilities(org.finos.waltz.common.RandomUtilities) ListUtilities.map(org.finos.waltz.common.ListUtilities.map) SurveyQuestionResponseRecord(org.finos.waltz.schema.tables.records.SurveyQuestionResponseRecord) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) LocalDate(java.time.LocalDate) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) SurveyInstanceService(org.finos.waltz.service.survey.SurveyInstanceService) PERSON(org.finos.waltz.schema.tables.Person.PERSON) HierarchyQueryScope(org.finos.waltz.model.HierarchyQueryScope) SurveyQuestionResponseRecord(org.finos.waltz.schema.tables.records.SurveyQuestionResponseRecord) Collections.emptySet(java.util.Collections.emptySet) InvolvementKindDao(org.finos.waltz.data.involvement_kind.InvolvementKindDao) AppGroup(org.finos.waltz.model.app_group.AppGroup) SurveyInstanceService(org.finos.waltz.service.survey.SurveyInstanceService) AppGroupDao(org.finos.waltz.data.app_group.AppGroupDao) InvolvementKind(org.finos.waltz.model.involvement_kind.InvolvementKind) SurveyTemplateDao(org.finos.waltz.data.survey.SurveyTemplateDao) DSLContext(org.jooq.DSLContext) BigDecimal(java.math.BigDecimal) SurveyRunService(org.finos.waltz.service.survey.SurveyRunService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SurveyRunRecord(org.finos.waltz.schema.tables.records.SurveyRunRecord) 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