use of org.finos.waltz.schema.tables.records.ChangeUnitRecord 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;
}
Aggregations