Search in sources :

Example 1 with PersonService

use of org.finos.waltz.service.person.PersonService 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 2 with PersonService

use of org.finos.waltz.service.person.PersonService in project waltz by khartec.

the class PersonDataGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    PersonService personService = ctx.getBean(PersonService.class);
    PersonHierarchyService personHierarchyService = ctx.getBean(PersonHierarchyService.class);
    List<Long> ouIds = getDsl(ctx).select(ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT).fetch(ORGANISATIONAL_UNIT.ID);
    Person person = fairy.person();
    ImmutablePerson root = ImmutablePerson.builder().employeeId(person.getPassportNumber()).personKind(PersonKind.EMPLOYEE).userPrincipalName(person.getUsername()).title(randomPick(SampleData.jobTitles[0])).departmentName("CEO").displayName(person.getFullName()).email(person.getEmail()).organisationalUnitId(10L).isRemoved(false).build();
    peeps.add(root);
    visit(root, 1, ouIds);
    personService.bulkSave(peeps);
    ImmutablePerson admin = randomPick(peeps);
    getDsl(ctx).update(PERSON).set(PERSON.USER_PRINCIPAL_NAME, "admin").set(PERSON.EMAIL, "admin").where(PERSON.EMPLOYEE_ID.eq(admin.employeeId())).execute();
    personHierarchyService.build();
    return MapUtilities.newHashMap("created", peeps.size());
}
Also used : PersonHierarchyService(org.finos.waltz.service.person_hierarchy.PersonHierarchyService) PersonService(org.finos.waltz.service.person.PersonService) ImmutablePerson(org.finos.waltz.model.person.ImmutablePerson) ImmutablePerson(org.finos.waltz.model.person.ImmutablePerson) Person(io.codearte.jfairy.producer.person.Person)

Aggregations

PersonService (org.finos.waltz.service.person.PersonService)2 Person (io.codearte.jfairy.producer.person.Person)1 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ArrayUtilities (org.finos.waltz.common.ArrayUtilities)1 DebugUtilities (org.finos.waltz.common.DebugUtilities)1 IOUtilities (org.finos.waltz.common.IOUtilities)1 MapUtilities.countBy (org.finos.waltz.common.MapUtilities.countBy)1 MapUtilities.indexBy (org.finos.waltz.common.MapUtilities.indexBy)1 Siphon (org.finos.waltz.common.StreamUtilities.Siphon)1 StreamUtilities.mkSiphon (org.finos.waltz.common.StreamUtilities.mkSiphon)1 Application (org.finos.waltz.model.application.Application)1 LifecyclePhase (org.finos.waltz.model.application.LifecyclePhase)1 ExternalIdValue (org.finos.waltz.model.external_identifier.ExternalIdValue)1 ImmutablePerson (org.finos.waltz.model.person.ImmutablePerson)1 Person (org.finos.waltz.model.person.Person)1 DIConfiguration (org.finos.waltz.service.DIConfiguration)1