Search in sources :

Example 1 with CHANGE_SET

use of org.finos.waltz.schema.tables.ChangeSet.CHANGE_SET in project waltz by khartec.

the class ChangeUnitGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    LocalDateTime now = LocalDateTime.now();
    List<Long> changeSetIds = dsl.select(CHANGE_SET.ID).from(CHANGE_SET).fetch(CHANGE_SET.ID);
    List<PhysicalFlow> physicalFlows = dsl.select(PHYSICAL_FLOW.fields()).from(PHYSICAL_FLOW).fetch(PhysicalFlowDao.TO_DOMAIN_MAPPER);
    AtomicInteger counter = new AtomicInteger(0);
    List<ChangeUnitRecord> groupRecords = changeSetIds.stream().flatMap(id -> randomlySizedIntStream(0, 5).mapToObj(idx -> randomPick(physicalFlows)).distinct().map(flow -> {
        ChangeUnitRecord record = dsl.newRecord(CHANGE_UNIT);
        record.setChangeSetId(id);
        record.setSubjectEntityKind(EntityKind.PHYSICAL_FLOW.name());
        record.setSubjectEntityId(flow.id().get());
        record.setSubjectInitialStatus(flow.entityLifecycleStatus().name());
        record.setExecutionStatus(ExecutionStatus.PENDING.name());
        record.setLastUpdatedAt(Timestamp.valueOf(now));
        record.setLastUpdatedBy("admin");
        record.setExternalId(String.format("change-unit-ext-%s", counter.addAndGet(1)));
        record.setProvenance(SAMPLE_DATA_PROVENANCE);
        // if flow pending -> activate, activating flow, desc
        // if flow active -> retire or modify
        // if modify -> create attribute changes
        ChangeAction action = mkChangeAction(flow);
        record.setAction(action.name());
        record.setName(mkName(flow, action));
        record.setDescription("Description: " + mkName(flow, action));
        return record;
    })).collect(toList());
    dsl.batchStore(groupRecords).execute();
    List<AttributeChangeRecord> attributeChangeRecords = mkAttributeChanges(dsl, physicalFlows);
    dsl.batchStore(attributeChangeRecords).execute();
    return null;
}
Also used : LocalDateTime(java.time.LocalDateTime) ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) ChangeUnitRecord(org.finos.waltz.schema.tables.records.ChangeUnitRecord) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) LocalDateTime(java.time.LocalDateTime) PhysicalFlowDao(org.finos.waltz.data.physical_flow.PhysicalFlowDao) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) DataType(org.finos.waltz.model.datatype.DataType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) StringUtilities.joinUsing(org.finos.waltz.common.StringUtilities.joinUsing) CHANGE_SET(org.finos.waltz.schema.tables.ChangeSet.CHANGE_SET) DSLContext(org.jooq.DSLContext) ChangeUnitDao(org.finos.waltz.data.change_unit.ChangeUnitDao) AttributeChangeRecord(org.finos.waltz.schema.tables.records.AttributeChangeRecord) StringUtilities(org.finos.waltz.common.StringUtilities) EntityLifecycleStatus(org.finos.waltz.model.EntityLifecycleStatus) MapUtilities(org.finos.waltz.common.MapUtilities) Criticality(org.finos.waltz.model.Criticality) Timestamp(java.sql.Timestamp) ExecutionStatus(org.finos.waltz.model.change_unit.ExecutionStatus) CHANGE_UNIT(org.finos.waltz.schema.tables.ChangeUnit.CHANGE_UNIT) ApplicationContext(org.springframework.context.ApplicationContext) RandomUtilities(org.finos.waltz.common.RandomUtilities) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) FrequencyKind(org.finos.waltz.model.physical_flow.FrequencyKind) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) ListUtilities(org.finos.waltz.common.ListUtilities) ChangeAction(org.finos.waltz.model.change_unit.ChangeAction) DataTypeDao(org.finos.waltz.data.data_type.DataTypeDao) ChangeAction(org.finos.waltz.model.change_unit.ChangeAction) DSLContext(org.jooq.DSLContext) AttributeChangeRecord(org.finos.waltz.schema.tables.records.AttributeChangeRecord) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) ChangeUnitRecord(org.finos.waltz.schema.tables.records.ChangeUnitRecord)

Example 2 with CHANGE_SET

use of org.finos.waltz.schema.tables.ChangeSet.CHANGE_SET in project waltz by khartec.

the class ChangeSetGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    LocalDateTime now = LocalDateTime.now();
    List<Long> ciIds = dsl.select(CHANGE_INITIATIVE.ID).from(CHANGE_INITIATIVE).fetch(CHANGE_INITIATIVE.ID);
    AtomicInteger counter = new AtomicInteger(0);
    List<ChangeSetRecord> groupRecords = Arrays.stream(names).map(n -> {
        ChangeSetRecord record = dsl.newRecord(CHANGE_SET);
        record.setParentEntityKind(EntityKind.CHANGE_INITIATIVE.name());
        record.setParentEntityId(randomPick(ciIds));
        record.setPlannedDate(Timestamp.valueOf(now));
        record.setEntityLifecycleStatus(EntityLifecycleStatus.ACTIVE.name());
        record.setName(n);
        record.setDescription(format("%s : Description of %s", SAMPLE_DATA_PROVENANCE, n));
        record.setLastUpdatedAt(Timestamp.valueOf(now));
        record.setLastUpdatedBy("admin");
        record.setExternalId(format("change-set-ext-%s", counter.addAndGet(1)));
        record.setProvenance(SAMPLE_DATA_PROVENANCE);
        return record;
    }).collect(Collectors.toList());
    dsl.batchStore(groupRecords).execute();
    return null;
}
Also used : LocalDateTime(java.time.LocalDateTime) ChangeSetRecord(org.finos.waltz.schema.tables.records.ChangeSetRecord) ChangeSetRecord(org.finos.waltz.schema.tables.records.ChangeSetRecord) Arrays(java.util.Arrays) EntityKind(org.finos.waltz.model.EntityKind) Timestamp(java.sql.Timestamp) LocalDateTime(java.time.LocalDateTime) Random(java.util.Random) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) RandomUtilities(org.finos.waltz.common.RandomUtilities) List(java.util.List) INVOLVEMENT(org.finos.waltz.schema.tables.Involvement.INVOLVEMENT) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CHANGE_INITIATIVE(org.finos.waltz.schema.tables.ChangeInitiative.CHANGE_INITIATIVE) Map(java.util.Map) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) CHANGE_SET(org.finos.waltz.schema.tables.ChangeSet.CHANGE_SET) DSLContext(org.jooq.DSLContext) EntityLifecycleStatus(org.finos.waltz.model.EntityLifecycleStatus) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DSLContext(org.jooq.DSLContext)

Aggregations

Timestamp (java.sql.Timestamp)2 LocalDateTime (java.time.LocalDateTime)2 List (java.util.List)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 RandomUtilities (org.finos.waltz.common.RandomUtilities)2 EntityKind (org.finos.waltz.model.EntityKind)2 EntityLifecycleStatus (org.finos.waltz.model.EntityLifecycleStatus)2 CHANGE_SET (org.finos.waltz.schema.tables.ChangeSet.CHANGE_SET)2 DSLContext (org.jooq.DSLContext)2 ApplicationContext (org.springframework.context.ApplicationContext)2 String.format (java.lang.String.format)1 Arrays (java.util.Arrays)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 ListUtilities (org.finos.waltz.common.ListUtilities)1 MapUtilities (org.finos.waltz.common.MapUtilities)1 RandomUtilities.randomPick (org.finos.waltz.common.RandomUtilities.randomPick)1