Search in sources :

Example 1 with MeasurableRatingRecord

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

Example 2 with MeasurableRatingRecord

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

the class MeasurableRatingDao method save.

// --- save
public Operation save(SaveMeasurableRatingCommand command, boolean ignoreReadOnly) {
    MeasurableRatingRecord record = TO_RECORD_MAPPER.apply(command);
    boolean exists = dsl.fetchExists(DSL.select(MEASURABLE_RATING.fields()).from(MEASURABLE_RATING).where(MEASURABLE_RATING.MEASURABLE_ID.eq(command.measurableId())).and(MEASURABLE_RATING.ENTITY_ID.eq(command.entityReference().id())).and(MEASURABLE_RATING.ENTITY_KIND.eq(command.entityReference().kind().name())));
    if (exists) {
        int updateCount = dsl.update(MEASURABLE_RATING).set(MEASURABLE_RATING.RATING, String.valueOf(command.rating())).set(MEASURABLE_RATING.DESCRIPTION, command.description()).set(MEASURABLE_RATING.LAST_UPDATED_BY, command.lastUpdate().by()).set(MEASURABLE_RATING.LAST_UPDATED_AT, command.lastUpdate().atTimestamp()).set(MEASURABLE_RATING.PROVENANCE, command.provenance()).where(MEASURABLE_RATING.ENTITY_ID.eq(command.entityReference().id())).and(MEASURABLE_RATING.ENTITY_KIND.eq(command.entityReference().kind().name())).and(MEASURABLE_RATING.MEASURABLE_ID.eq(command.measurableId())).and(ignoreReadOnly ? DSL.trueCondition() : MEASURABLE_RATING.IS_READONLY.isFalse()).execute();
        if (updateCount == 0) {
            throw new NotFoundException("MR_SAVE_UPDATE_FAILED", format("Could find writable associated record to update for rating: %s", command));
        }
        ;
        return Operation.UPDATE;
    } else {
        if (dsl.executeInsert(record) != 1) {
            throw new NotFoundException("MR_SAVE_INSERT_FAILED", format("Creation of record failed: %s", command));
        }
        ;
        return Operation.ADD;
    }
}
Also used : MeasurableRatingRecord(org.finos.waltz.schema.tables.records.MeasurableRatingRecord) NotFoundException(org.finos.waltz.common.exception.NotFoundException)

Aggregations

MeasurableRatingRecord (org.finos.waltz.schema.tables.records.MeasurableRatingRecord)2 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 NotFoundException (org.finos.waltz.common.exception.NotFoundException)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 DSLContext (org.jooq.DSLContext)1 Tuple (org.jooq.lambda.tuple.Tuple)1 ApplicationContext (org.springframework.context.ApplicationContext)1