use of org.finos.waltz.schema.tables.records.FlowClassificationRecord in project waltz by khartec.
the class FlowClassificationRuleGenerator method create.
@Override
public Map<String, Integer> create(ApplicationContext ctx) {
DSLContext dsl = getDsl(ctx);
List<Long> appIds = getAppIds(dsl);
List<Long> ouIds = dsl.select(ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT).fetch(ORGANISATIONAL_UNIT.ID);
List<Long> typeIds = dsl.select(DATA_TYPE.ID).from(DATA_TYPE).fetch(DATA_TYPE.ID);
List<AuthoritativenessRatingValue> classificationValues = asList(AuthoritativenessRatingValue.of("PRIMARY"), AuthoritativenessRatingValue.of("SECONDARY"), AuthoritativenessRatingValue.DISCOURAGED, AuthoritativenessRatingValue.NO_OPINION);
List<String> colors = asList(HexStrings.AMBER, HexStrings.RED, HexStrings.GREEN);
Set<FlowClassificationRecord> classificationRecords = classificationValues.stream().map(v -> {
FlowClassificationRecord record = dsl.newRecord(FLOW_CLASSIFICATION);
record.setCode(v.value());
record.setName(capitalise(v.value()));
record.setColor(randomPick(colors));
return record;
}).collect(toSet());
dsl.batchInsert(classificationRecords).execute();
List<Long> classificationIds = dsl.select(FLOW_CLASSIFICATION.ID).from(FLOW_CLASSIFICATION).where(FLOW_CLASSIFICATION.CODE.notIn(AuthoritativenessRatingValue.DISCOURAGED.value(), AuthoritativenessRatingValue.NO_OPINION.value())).fetch(FLOW_CLASSIFICATION.ID);
List<FlowClassificationRuleRecord> records = typeIds.stream().flatMap(t -> IntStream.range(0, 2 + rnd.nextInt(2)).mapToObj(i -> {
FlowClassificationRuleRecord record = dsl.newRecord(FLOW_CLASSIFICATION_RULE);
record.setDataTypeId(t);
record.setFlowClassificationId(randomPick(classificationIds));
record.setApplicationId(randomPick(appIds));
record.setParentId(randomPick(ouIds));
record.setParentKind(EntityKind.ORG_UNIT.name());
record.setProvenance(SAMPLE_DATA_PROVENANCE);
record.setLastUpdatedAt(nowUtcTimestamp());
record.setLastUpdatedBy(SAMPLE_DATA_USER);
return record;
})).collect(Collectors.toList());
dsl.batchStore(records).execute();
return null;
}
Aggregations