Search in sources :

Example 1 with AttributeChangeRecord

use of org.finos.waltz.schema.tables.records.AttributeChangeRecord 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 AttributeChangeRecord

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

the class ChangeUnitGenerator method mkFrequencyChange.

private AttributeChangeRecord mkFrequencyChange(DSLContext dsl, ChangeUnit cu, PhysicalFlow flow, String name) {
    AttributeChangeRecord record = dsl.newRecord(ATTRIBUTE_CHANGE);
    record.setChangeUnitId(cu.id().get());
    record.setType("string");
    record.setOldValue(flow.frequency().name());
    record.setNewValue(randomPick(FrequencyKind.values()).name());
    record.setName(name);
    record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
    record.setLastUpdatedBy("admin");
    record.setProvenance(SAMPLE_DATA_PROVENANCE);
    return record;
}
Also used : AttributeChangeRecord(org.finos.waltz.schema.tables.records.AttributeChangeRecord)

Example 3 with AttributeChangeRecord

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

the class ChangeUnitGenerator method mkDataTypeChange.

private AttributeChangeRecord mkDataTypeChange(DSLContext dsl, ChangeUnit cu, PhysicalFlow flow, String name) {
    List<DataType> allDataTypes = dsl.selectFrom(DATA_TYPE).fetch(DataTypeDao.TO_DOMAIN);
    List<DataType> newDataTypes = randomPick(allDataTypes, randomIntBetween(1, 5));
    String json = "[" + joinUsing(newDataTypes, d -> String.format("{\"dataTypeId\": %s}", d.id().get()), ",") + "]";
    AttributeChangeRecord record = dsl.newRecord(ATTRIBUTE_CHANGE);
    record.setChangeUnitId(cu.id().get());
    record.setType("json");
    record.setOldValue("[]");
    record.setNewValue(json);
    record.setName(name);
    record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
    record.setLastUpdatedBy("admin");
    record.setProvenance(SAMPLE_DATA_PROVENANCE);
    return record;
}
Also used : AttributeChangeRecord(org.finos.waltz.schema.tables.records.AttributeChangeRecord) DataType(org.finos.waltz.model.datatype.DataType)

Example 4 with AttributeChangeRecord

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

the class ChangeUnitGenerator method mkAttributeChanges.

private List<AttributeChangeRecord> mkAttributeChanges(DSLContext dsl, List<PhysicalFlow> physicalFlows) {
    List<ChangeUnit> modifyCUs = dsl.selectFrom(CHANGE_UNIT).where(CHANGE_UNIT.ACTION.eq(ChangeAction.MODIFY.name())).fetch(ChangeUnitDao.TO_DOMAIN_MAPPER);
    List<String> attributes = ListUtilities.asList("criticality", "frequency", "DataType");
    Map<Long, PhysicalFlow> flowsById = MapUtilities.indexBy(f -> f.id().get(), physicalFlows);
    List<AttributeChangeRecord> attributeChanges = modifyCUs.stream().flatMap(cu -> randomlySizedIntStream(1, 2).mapToObj(idx -> randomPick(attributes)).map(attribute -> {
        PhysicalFlow flow = flowsById.get(cu.subjectEntity().id());
        switch(attribute) {
            case "criticality":
                return mkCriticalityChange(dsl, cu, flow, attribute);
            case "frequency":
                return mkFrequencyChange(dsl, cu, flow, attribute);
            case "DataType":
                return mkDataTypeChange(dsl, cu, flow, attribute);
            default:
                throw new UnsupportedOperationException("Attribute change not supported: " + attribute);
        }
    })).collect(toList());
    return attributeChanges;
}
Also used : 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) AttributeChangeRecord(org.finos.waltz.schema.tables.records.AttributeChangeRecord) ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow)

Example 5 with AttributeChangeRecord

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

the class ChangeUnitGenerator method mkCriticalityChange.

private AttributeChangeRecord mkCriticalityChange(DSLContext dsl, ChangeUnit cu, PhysicalFlow flow, String name) {
    AttributeChangeRecord record = dsl.newRecord(ATTRIBUTE_CHANGE);
    record.setChangeUnitId(cu.id().get());
    record.setType("string");
    record.setOldValue(flow.criticality().name());
    record.setNewValue(randomPick(Criticality.values()).name());
    record.setName(name);
    record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
    record.setLastUpdatedBy("admin");
    record.setProvenance(SAMPLE_DATA_PROVENANCE);
    return record;
}
Also used : AttributeChangeRecord(org.finos.waltz.schema.tables.records.AttributeChangeRecord)

Aggregations

AttributeChangeRecord (org.finos.waltz.schema.tables.records.AttributeChangeRecord)5 DataType (org.finos.waltz.model.datatype.DataType)3 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 Collectors.toList (java.util.stream.Collectors.toList)2 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)2 ListUtilities (org.finos.waltz.common.ListUtilities)2 MapUtilities (org.finos.waltz.common.MapUtilities)2 RandomUtilities (org.finos.waltz.common.RandomUtilities)2 StringUtilities (org.finos.waltz.common.StringUtilities)2 StringUtilities.joinUsing (org.finos.waltz.common.StringUtilities.joinUsing)2 ChangeUnitDao (org.finos.waltz.data.change_unit.ChangeUnitDao)2 DataTypeDao (org.finos.waltz.data.data_type.DataTypeDao)2 PhysicalFlowDao (org.finos.waltz.data.physical_flow.PhysicalFlowDao)2 Criticality (org.finos.waltz.model.Criticality)2 EntityKind (org.finos.waltz.model.EntityKind)2 EntityLifecycleStatus (org.finos.waltz.model.EntityLifecycleStatus)2