Search in sources :

Example 1 with MEASURABLE_RATING

use of org.finos.waltz.schema.Tables.MEASURABLE_RATING in project waltz by khartec.

the class MeasurableRatingGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    List<Long> appIds = getAppIds(dsl);
    List<Long> mIds = dsl.select(MEASURABLE.ID).from(MEASURABLE).where(MEASURABLE.CONCRETE.isTrue()).fetch().getValues(MEASURABLE.ID);
    List<MeasurableRatingRecord> records = appIds.stream().flatMap(appId -> randomlySizedIntStream(0, MAX_RATINGS_PER_APP).mapToObj(idx -> Tuple.tuple(appId, randomPick(mIds)))).map(t -> {
        MeasurableRatingRecord record = dsl.newRecord(MEASURABLE_RATING);
        record.setEntityId(t.v1);
        record.setEntityKind(EntityKind.APPLICATION.name());
        record.setRating(randomPick("R", "A", "G"));
        record.setMeasurableId(t.v2);
        record.setLastUpdatedBy("admin");
        record.setProvenance(SAMPLE_DATA_PROVENANCE);
        return record;
    }).collect(Collectors.toList());
    Set<MeasurableRatingRecord> dedupedRecords = uniqBy(records, r -> Tuple.tuple(r.getMeasurableId(), r.getEntityId()));
    dsl.batchStore(dedupedRecords).execute();
    return null;
}
Also used : EntityKind(org.finos.waltz.model.EntityKind) SetUtilities.uniqBy(org.finos.waltz.common.SetUtilities.uniqBy) Set(java.util.Set) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) List(java.util.List) Tuple(org.jooq.lambda.tuple.Tuple) Map(java.util.Map) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) RandomUtilities.randomlySizedIntStream(org.finos.waltz.common.RandomUtilities.randomlySizedIntStream) DSLContext(org.jooq.DSLContext) MeasurableRatingRecord(org.finos.waltz.schema.tables.records.MeasurableRatingRecord) MEASURABLE_RATING(org.finos.waltz.schema.Tables.MEASURABLE_RATING) MEASURABLE(org.finos.waltz.schema.Tables.MEASURABLE) MeasurableRatingRecord(org.finos.waltz.schema.tables.records.MeasurableRatingRecord) DSLContext(org.jooq.DSLContext)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 RandomUtilities.randomPick (org.finos.waltz.common.RandomUtilities.randomPick)1 RandomUtilities.randomlySizedIntStream (org.finos.waltz.common.RandomUtilities.randomlySizedIntStream)1 SetUtilities.uniqBy (org.finos.waltz.common.SetUtilities.uniqBy)1 EntityKind (org.finos.waltz.model.EntityKind)1 MEASURABLE (org.finos.waltz.schema.Tables.MEASURABLE)1 MEASURABLE_RATING (org.finos.waltz.schema.Tables.MEASURABLE_RATING)1 MeasurableRatingRecord (org.finos.waltz.schema.tables.records.MeasurableRatingRecord)1 DSLContext (org.jooq.DSLContext)1 Tuple (org.jooq.lambda.tuple.Tuple)1 ApplicationContext (org.springframework.context.ApplicationContext)1