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;
}
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;
}
}
Aggregations