Search in sources :

Example 1 with ChangeInitiativeRecord

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

the class ChangeInitiativeGenerator method createCiRecords.

private List<ChangeInitiativeRecord> createCiRecords(List<Long> ouIds) {
    AtomicLong idCtr = new AtomicLong();
    return IntStream.range(0, NUM_CHANGE_INITIATIVES).boxed().flatMap(i -> {
        long initiativeId = idCtr.incrementAndGet();
        Tuple4<Long, ChangeInitiativeKind, Long, String> initiative = tuple(initiativeId, INITIATIVE, null, mkName());
        Stream<Tuple4<Long, ChangeInitiativeKind, Long, String>> children = IntStream.range(0, RND.nextInt(4)).boxed().flatMap(x -> {
            long programmeId = idCtr.incrementAndGet();
            Stream<Tuple4<Long, ChangeInitiativeKind, Long, String>> programmes = Stream.of(tuple(programmeId, PROGRAMME, initiativeId, mkName()));
            Stream<Tuple4<Long, ChangeInitiativeKind, Long, String>> projects = IntStream.range(0, RND.nextInt(4)).boxed().map(y -> tuple(idCtr.incrementAndGet(), PROJECT, programmeId, mkName()));
            return Stream.concat(programmes, projects);
        });
        return Stream.concat(Stream.of(initiative), children);
    }).map(t -> buildChangeInitiativeRecord(t, ouIds)).collect(toList());
}
Also used : Tuple4(org.jooq.lambda.tuple.Tuple4) IntStream(java.util.stream.IntStream) LifecyclePhase(org.finos.waltz.model.application.LifecyclePhase) DSL(org.jooq.impl.DSL) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) EntityRelationshipRecord(org.finos.waltz.schema.tables.records.EntityRelationshipRecord) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) InvolvementRecord(org.finos.waltz.schema.tables.records.InvolvementRecord) Tuple2(org.jooq.lambda.tuple.Tuple2) Tuple4(org.jooq.lambda.tuple.Tuple4) CHANGE_INITIATIVE(org.finos.waltz.schema.tables.ChangeInitiative.CHANGE_INITIATIVE) org.jooq(org.jooq) Map(java.util.Map) APPLICATION_GROUP(org.finos.waltz.schema.tables.ApplicationGroup.APPLICATION_GROUP) StreamUtilities(org.finos.waltz.common.StreamUtilities) EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService) Logger(org.slf4j.Logger) ChangeInitiativeRecord(org.finos.waltz.schema.tables.records.ChangeInitiativeRecord) ChangeInitiativeKind(org.finos.waltz.model.change_initiative.ChangeInitiativeKind) Instant(java.time.Instant) ApplicationContext(org.springframework.context.ApplicationContext) Date(java.sql.Date) RandomUtilities(org.finos.waltz.common.RandomUtilities) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) INVOLVEMENT(org.finos.waltz.schema.tables.Involvement.INVOLVEMENT) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) PERSON(org.finos.waltz.schema.tables.Person.PERSON) AtomicLong(java.util.concurrent.atomic.AtomicLong) ChangeInitiativeKind(org.finos.waltz.model.change_initiative.ChangeInitiativeKind) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 2 with ChangeInitiativeRecord

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

the class ChangeInitiativeGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    List<Long> appIds = loadAllIds(dsl, APPLICATION.ID);
    List<Long> ouIds = loadAllIds(dsl, ORGANISATIONAL_UNIT.ID);
    List<Long> groupIds = loadAllIds(dsl, APPLICATION_GROUP.ID);
    List<String> employeeIds = loadAllIds(dsl, PERSON.EMPLOYEE_ID);
    List<ChangeInitiativeRecord> ciRecords = createCiRecords(ouIds);
    dsl.batchInsert(ciRecords).execute();
    LOG.info("Created: {} ci records", ciRecords.size());
    List<Long> ciIds = loadAllIds(dsl, CHANGE_INITIATIVE.ID, CHANGE_INITIATIVE.PROVENANCE.eq(SAMPLE_DATA_PROVENANCE));
    List<TableRecord<?>> relationships = StreamUtilities.concat(buildPersonLinks(ciIds, employeeIds), buildEntityRelationships(EntityKind.APP_GROUP, "RELATES_TO", ciIds, groupIds, 0.5, 2), buildEntityRelationships(EntityKind.APPLICATION, "SUPPORTS", ciIds, appIds, 0.6, 3)).collect(toList());
    LOG.info("Storing {} relationships", relationships.size());
    dsl.batchInsert(relationships).execute();
    EntityHierarchyService ehSvc = ctx.getBean(EntityHierarchyService.class);
    ehSvc.buildFor(EntityKind.CHANGE_INITIATIVE);
    return null;
}
Also used : EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService) AtomicLong(java.util.concurrent.atomic.AtomicLong) ChangeInitiativeRecord(org.finos.waltz.schema.tables.records.ChangeInitiativeRecord)

Example 3 with ChangeInitiativeRecord

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

the class ChangeInitiativeGenerator method buildChangeInitiativeRecord.

private static ChangeInitiativeRecord buildChangeInitiativeRecord(Tuple4<Long, ChangeInitiativeKind, Long, String> t, List<Long> ouIds) {
    ChangeInitiativeRecord record = new ChangeInitiativeRecord();
    record.setDescription(t.v4);
    record.setName(t.v4);
    record.setProvenance("dummy");
    record.setExternalId("EXT" + t.v1 + (t.v3 != null ? "_" + t.v3 : ""));
    record.setKind(t.v2.name());
    record.setLifecyclePhase(randomPick(LifecyclePhase.values()).name());
    record.setId(t.v1);
    record.setParentId(t.v3);
    record.setStartDate(new Date(Instant.now().toEpochMilli()));
    record.setEndDate(new Date(Instant.now().plusSeconds(RND.nextInt(60 * 60 * 24 * 365 * 2)).toEpochMilli()));
    record.setOrganisationalUnitId(randomPick(ouIds));
    record.setProvenance(SAMPLE_DATA_PROVENANCE);
    return record;
}
Also used : ChangeInitiativeRecord(org.finos.waltz.schema.tables.records.ChangeInitiativeRecord) Date(java.sql.Date)

Aggregations

ChangeInitiativeRecord (org.finos.waltz.schema.tables.records.ChangeInitiativeRecord)3 Date (java.sql.Date)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 EntityHierarchyService (org.finos.waltz.service.entity_hierarchy.EntityHierarchyService)2 Instant (java.time.Instant)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Collectors.toList (java.util.stream.Collectors.toList)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 RandomUtilities (org.finos.waltz.common.RandomUtilities)1 RandomUtilities.randomPick (org.finos.waltz.common.RandomUtilities.randomPick)1 StreamUtilities (org.finos.waltz.common.StreamUtilities)1 EntityKind (org.finos.waltz.model.EntityKind)1 LifecyclePhase (org.finos.waltz.model.application.LifecyclePhase)1 ChangeInitiativeKind (org.finos.waltz.model.change_initiative.ChangeInitiativeKind)1 Tables (org.finos.waltz.schema.Tables)1 APPLICATION_GROUP (org.finos.waltz.schema.tables.ApplicationGroup.APPLICATION_GROUP)1 CHANGE_INITIATIVE (org.finos.waltz.schema.tables.ChangeInitiative.CHANGE_INITIATIVE)1