Search in sources :

Example 1 with FlowClassificationRuleRecord

use of org.finos.waltz.schema.tables.records.FlowClassificationRuleRecord 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;
}
Also used : IntStream(java.util.stream.IntStream) AuthoritativenessRatingValue(org.finos.waltz.model.rating.AuthoritativenessRatingValue) FLOW_CLASSIFICATION(org.finos.waltz.schema.Tables.FLOW_CLASSIFICATION) StringUtilities.capitalise(org.finos.waltz.common.StringUtilities.capitalise) HexStrings(org.finos.waltz.common.ColorUtilities.HexStrings) EntityKind(org.finos.waltz.model.EntityKind) Set(java.util.Set) Random(java.util.Random) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) RandomUtilities(org.finos.waltz.common.RandomUtilities) FLOW_CLASSIFICATION_RULE(org.finos.waltz.schema.Tables.FLOW_CLASSIFICATION_RULE) List(java.util.List) DateTimeUtilities.nowUtcTimestamp(org.finos.waltz.common.DateTimeUtilities.nowUtcTimestamp) FlowClassificationRecord(org.finos.waltz.schema.tables.records.FlowClassificationRecord) FlowClassificationRuleRecord(org.finos.waltz.schema.tables.records.FlowClassificationRuleRecord) ORGANISATIONAL_UNIT(org.finos.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) ListUtilities.asList(org.finos.waltz.common.ListUtilities.asList) Map(java.util.Map) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) DSLContext(org.jooq.DSLContext) Collectors.toSet(java.util.stream.Collectors.toSet) DATA_TYPE(org.finos.waltz.schema.tables.DataType.DATA_TYPE) FlowClassificationRuleRecord(org.finos.waltz.schema.tables.records.FlowClassificationRuleRecord) FlowClassificationRecord(org.finos.waltz.schema.tables.records.FlowClassificationRecord) AuthoritativenessRatingValue(org.finos.waltz.model.rating.AuthoritativenessRatingValue) DSLContext(org.jooq.DSLContext)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 IntStream (java.util.stream.IntStream)1 HexStrings (org.finos.waltz.common.ColorUtilities.HexStrings)1 DateTimeUtilities.nowUtcTimestamp (org.finos.waltz.common.DateTimeUtilities.nowUtcTimestamp)1 ListUtilities.asList (org.finos.waltz.common.ListUtilities.asList)1 RandomUtilities (org.finos.waltz.common.RandomUtilities)1 RandomUtilities.randomPick (org.finos.waltz.common.RandomUtilities.randomPick)1 StringUtilities.capitalise (org.finos.waltz.common.StringUtilities.capitalise)1 EntityKind (org.finos.waltz.model.EntityKind)1 AuthoritativenessRatingValue (org.finos.waltz.model.rating.AuthoritativenessRatingValue)1 FLOW_CLASSIFICATION (org.finos.waltz.schema.Tables.FLOW_CLASSIFICATION)1 FLOW_CLASSIFICATION_RULE (org.finos.waltz.schema.Tables.FLOW_CLASSIFICATION_RULE)1 DATA_TYPE (org.finos.waltz.schema.tables.DataType.DATA_TYPE)1 ORGANISATIONAL_UNIT (org.finos.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT)1 FlowClassificationRecord (org.finos.waltz.schema.tables.records.FlowClassificationRecord)1