Search in sources :

Example 1 with InvolvementRecord

use of org.finos.waltz.schema.tables.records.InvolvementRecord in project waltz by khartec.

the class PersonResolver method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIBaseConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    InvolvementNameToIdResolver involvementNameToIdResolver = new InvolvementNameToIdResolver(dsl);
    PersonNameToEmpIdResolver personNameToEmpIdResolver = new PersonNameToEmpIdResolver(dsl);
    OrgNameToIdResolver orgNameToIdResolver = new OrgNameToIdResolver(dsl);
    Siphon<Tuple4<String, String, Optional<Long>, Optional<String>>> noOrgSiphon = mkSiphon(t -> !t.v3.isPresent());
    Siphon<Tuple4<String, String, Optional<Long>, Optional<String>>> noPersonSiphon = mkSiphon(t -> !t.v4.isPresent());
    Set<Tuple3<Long, String, Long>> orgEmpInvTuples = involvementNameToIdResolver.resolve(involvementKindName).map(involvementKindId -> data.stream().flatMap(t -> Stream.of(t.v2.split(" / ")).map(name -> tuple(t.v1, name))).distinct().map(t -> t.concat(orgNameToIdResolver.resolve(t.v1))).map(t -> t.concat(personNameToEmpIdResolver.resolve(t.v2))).filter(noOrgSiphon).filter(noPersonSiphon).map(t -> t.skip2().map1(// empId
    Optional::get).map2(// orgId
    Optional::get).concat(involvementKindId)).collect(Collectors.toSet())).orElseThrow(() -> new IllegalArgumentException(format("Cannot find involvement kind: %s", involvementKindName)));
    dump("No Org", noOrgSiphon, t -> t.v1);
    dump("No Person", noPersonSiphon, t -> t.v2);
    Set<InvolvementRecord> records = map(orgEmpInvTuples, t -> new InvolvementRecord(EntityKind.ORG_UNIT.name(), t.v1, t.v2, provenance, t.v3, true));
    dsl.batchInsert(records).execute();
}
Also used : DebugUtilities.dump(org.finos.waltz.common.DebugUtilities.dump) InvolvementNameToIdResolver(org.finos.waltz.jobs.tools.resolvers.InvolvementNameToIdResolver) EntityKind(org.finos.waltz.model.EntityKind) Set(java.util.Set) StreamUtilities.mkSiphon(org.finos.waltz.common.StreamUtilities.mkSiphon) PersonNameToEmpIdResolver(org.finos.waltz.jobs.tools.resolvers.PersonNameToEmpIdResolver) DIBaseConfiguration(org.finos.waltz.service.DIBaseConfiguration) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) String.format(java.lang.String.format) InvolvementRecord(org.finos.waltz.schema.tables.records.InvolvementRecord) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) Tuple2(org.jooq.lambda.tuple.Tuple2) List(java.util.List) Tuple3(org.jooq.lambda.tuple.Tuple3) Stream(java.util.stream.Stream) Tuple4(org.jooq.lambda.tuple.Tuple4) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) ListUtilities(org.finos.waltz.common.ListUtilities) OrgNameToIdResolver(org.finos.waltz.jobs.tools.resolvers.OrgNameToIdResolver) DSLContext(org.jooq.DSLContext) Optional(java.util.Optional) Siphon(org.finos.waltz.common.StreamUtilities.Siphon) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Optional(java.util.Optional) DSLContext(org.jooq.DSLContext) PersonNameToEmpIdResolver(org.finos.waltz.jobs.tools.resolvers.PersonNameToEmpIdResolver) Tuple4(org.jooq.lambda.tuple.Tuple4) OrgNameToIdResolver(org.finos.waltz.jobs.tools.resolvers.OrgNameToIdResolver) Tuple3(org.jooq.lambda.tuple.Tuple3) InvolvementNameToIdResolver(org.finos.waltz.jobs.tools.resolvers.InvolvementNameToIdResolver) InvolvementRecord(org.finos.waltz.schema.tables.records.InvolvementRecord)

Example 2 with InvolvementRecord

use of org.finos.waltz.schema.tables.records.InvolvementRecord in project waltz by khartec.

the class EndUserAppInvolvmentGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    List<Long> appIds = dsl.select(END_USER_APPLICATION.ID).from(END_USER_APPLICATION).fetch(END_USER_APPLICATION.ID);
    List<String> empIds = dsl.select(PERSON.EMPLOYEE_ID).from(PERSON).innerJoin(PERSON_HIERARCHY).on(PERSON.EMPLOYEE_ID.eq(PERSON_HIERARCHY.EMPLOYEE_ID)).where(PERSON_HIERARCHY.LEVEL.lt(4)).fetch(PERSON.EMPLOYEE_ID);
    List<Long> invKinds = dsl.select(INVOLVEMENT_KIND.ID).from(INVOLVEMENT_KIND).fetch(INVOLVEMENT_KIND.ID);
    List<InvolvementRecord> records = ListUtilities.map(appIds, id -> {
        InvolvementRecord record = dsl.newRecord(INVOLVEMENT);
        record.setProvenance(SAMPLE_DATA_PROVENANCE);
        record.setEmployeeId(randomPick(empIds));
        record.setEntityId(id);
        record.setEntityKind(EntityKind.END_USER_APPLICATION.name());
        record.setKindId(randomPick(invKinds));
        return record;
    });
    log("---saving: " + records.size());
    dsl.batchInsert(records).execute();
    log("---done");
    return null;
}
Also used : DSLContext(org.jooq.DSLContext) InvolvementRecord(org.finos.waltz.schema.tables.records.InvolvementRecord)

Example 3 with InvolvementRecord

use of org.finos.waltz.schema.tables.records.InvolvementRecord in project waltz by khartec.

the class InvolvementGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<String> developers = getEmployeeIdsByTitle(dsl, "%Developer%");
    List<String> managers = getEmployeeIdsByTitle(dsl, "%Manager%");
    List<String> analysts = getEmployeeIdsByTitle(dsl, "%Analyst%");
    List<String> administrators = getEmployeeIdsByTitle(dsl, "%Administrator%");
    List<String> qa = getEmployeeIdsByTitle(dsl, "%QA%");
    List<String> directors = getEmployeeIdsByTitle(dsl, "%Director%");
    List<Long> orgUnitIds = dsl.select(ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT).fetch(ORGANISATIONAL_UNIT.ID);
    Map<String, Long> involvementKindMap = dsl.select(INVOLVEMENT_KIND.NAME, INVOLVEMENT_KIND.ID).from(INVOLVEMENT_KIND).fetch().stream().collect(toMap(r -> r.getValue(INVOLVEMENT_KIND.NAME), r -> r.getValue(INVOLVEMENT_KIND.ID)));
    List<Long> inHouseApps = getAppIdsByKind(dsl, ApplicationKind.IN_HOUSE);
    List<Long> hostedApps = getAppIdsByKind(dsl, ApplicationKind.INTERNALLY_HOSTED);
    List<Long> externalApps = getAppIdsByKind(dsl, ApplicationKind.EXTERNALLY_HOSTED);
    List<Long> eucApps = getAppIdsByKind(dsl, ApplicationKind.EUC);
    List<InvolvementRecord> devInvolvements = inHouseApps.stream().map(id -> toAppRef(id)).flatMap(appRef -> mkInvolvments(appRef, developers, involvementKindMap.get("Developer"), 7)).collect(Collectors.toList());
    List<InvolvementRecord> qaInvolvements = concat(inHouseApps, hostedApps).stream().map(id -> toAppRef(id)).flatMap(appRef -> mkInvolvments(appRef, qa, involvementKindMap.get("Quality Assurance"), 3)).collect(Collectors.toList());
    List<InvolvementRecord> projectManagerInvolvements = concat(inHouseApps, externalApps, hostedApps, eucApps).stream().map(id -> toAppRef(id)).flatMap(appRef -> mkInvolvments(appRef, managers, involvementKindMap.get("Project Manager"), 1)).collect(Collectors.toList());
    List<InvolvementRecord> supportManagerInvolvments = concat(inHouseApps, externalApps, hostedApps).stream().map(id -> toAppRef(id)).flatMap(appRef -> mkInvolvments(appRef, managers, involvementKindMap.get("Support Manager"), 1)).collect(Collectors.toList());
    List<InvolvementRecord> analystInvolvments = concat(inHouseApps, externalApps, hostedApps).stream().map(id -> toAppRef(id)).flatMap(appRef -> mkInvolvments(appRef, analysts, involvementKindMap.get("Business Analyst"), 3)).collect(Collectors.toList());
    List<InvolvementRecord> ouArchitects = orgUnitIds.stream().map(id -> new InvolvementRecord(EntityKind.ORG_UNIT.name(), id, randomPick(directors), SAMPLE_DATA_PROVENANCE, Long.valueOf(rnd.nextInt(13) + 1), true)).collect(Collectors.toList());
    List<InvolvementRecord> ouSponsors = orgUnitIds.stream().map(id -> new InvolvementRecord(EntityKind.ORG_UNIT.name(), id, randomPick(directors), SAMPLE_DATA_PROVENANCE, Long.valueOf(rnd.nextInt(13) + 1), true)).collect(Collectors.toList());
    List<InvolvementRecord> categoryInvolvements = dsl.select(MEASURABLE_CATEGORY.ID).from(MEASURABLE_CATEGORY).fetch(MEASURABLE_CATEGORY.ID).stream().map(id -> new InvolvementRecord(EntityKind.MEASURABLE_CATEGORY.name(), id, randomPick(directors), SAMPLE_DATA_PROVENANCE, Long.valueOf(rnd.nextInt(13) + 1), true)).collect(Collectors.toList());
    dsl.batchInsert(devInvolvements).execute();
    dsl.batchInsert(qaInvolvements).execute();
    dsl.batchInsert(supportManagerInvolvments).execute();
    dsl.batchInsert(projectManagerInvolvements).execute();
    dsl.batchInsert(analystInvolvments).execute();
    dsl.batchInsert(ouArchitects).execute();
    dsl.batchInsert(ouSponsors).execute();
    dsl.batchInsert(categoryInvolvements).execute();
    System.out.println("Done");
    return null;
}
Also used : IntStream(java.util.stream.IntStream) APPLICATION(org.finos.waltz.schema.tables.Application.APPLICATION) INVOLVEMENT_KIND(org.finos.waltz.schema.tables.InvolvementKind.INVOLVEMENT_KIND) EntityKind(org.finos.waltz.model.EntityKind) ImmutableEntityReference(org.finos.waltz.model.ImmutableEntityReference) Random(java.util.Random) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) InvolvementRecord(org.finos.waltz.schema.tables.records.InvolvementRecord) MEASURABLE_CATEGORY(org.finos.waltz.schema.Tables.MEASURABLE_CATEGORY) RandomUtilities(org.finos.waltz.common.RandomUtilities) List(java.util.List) Stream(java.util.stream.Stream) ORGANISATIONAL_UNIT(org.finos.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) Collectors.toMap(java.util.stream.Collectors.toMap) INVOLVEMENT(org.finos.waltz.schema.tables.Involvement.INVOLVEMENT) Map(java.util.Map) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) EntityReference(org.finos.waltz.model.EntityReference) DSLContext(org.jooq.DSLContext) ApplicationKind(org.finos.waltz.model.application.ApplicationKind) ListUtilities.concat(org.finos.waltz.common.ListUtilities.concat) PERSON(org.finos.waltz.schema.tables.Person.PERSON) DSLContext(org.jooq.DSLContext) InvolvementRecord(org.finos.waltz.schema.tables.records.InvolvementRecord)

Aggregations

InvolvementRecord (org.finos.waltz.schema.tables.records.InvolvementRecord)3 DSLContext (org.jooq.DSLContext)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 EntityKind (org.finos.waltz.model.EntityKind)2 String.format (java.lang.String.format)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Set (java.util.Set)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 IntStream (java.util.stream.IntStream)1 DebugUtilities.dump (org.finos.waltz.common.DebugUtilities.dump)1 ListUtilities (org.finos.waltz.common.ListUtilities)1 ListUtilities.concat (org.finos.waltz.common.ListUtilities.concat)1 RandomUtilities (org.finos.waltz.common.RandomUtilities)1 RandomUtilities.randomPick (org.finos.waltz.common.RandomUtilities.randomPick)1 SetUtilities.map (org.finos.waltz.common.SetUtilities.map)1 Siphon (org.finos.waltz.common.StreamUtilities.Siphon)1