use of org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord in project waltz by khartec.
the class ScenarioPopulator method mkRecordsFromRow.
/**
* Each row may potentially yeild up to two records to be inserted:
* <ul>
* <li>Current app (if scenario is before decomm date)</li>
* <li>Replacement app (if after scenario effective date)</li>
* </ul>
*
* Note: We rely upon the equivalence of records to prevent duplicates (hence passing
* in a single copy of now).
*
* @param tx Transactional DSL context
* @param r Row from the initial query
* @param now timestamp representing now
* @return Stream of 0-2 records
*/
private static Stream<ScenarioRatingItemRecord> mkRecordsFromRow(DSLContext tx, Record r, Timestamp now) {
Stream.Builder<ScenarioRatingItemRecord> sbuilder = Stream.builder();
if (r.get(inclCurrent)) {
ScenarioRatingItemRecord item = mkBaseRecord(tx, r, now);
item.setDomainItemKind(r.get(mr.ENTITY_KIND));
item.setDomainItemId(r.get(mr.ENTITY_ID));
item.setRating(r.get(mr.RATING));
item.setDescription(mkDecomMessage(r));
sbuilder.add(item);
}
if (r.get(inclReplacement)) {
ScenarioRatingItemRecord item = mkBaseRecord(tx, r, now);
item.setDomainItemKind(r.get(repl.ENTITY_KIND));
item.setDomainItemId(r.get(repl.ENTITY_ID));
item.setRating("G");
item.setDescription(mkCommMessage(r));
sbuilder.add(item);
}
return sbuilder.build();
}
use of org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord in project waltz by khartec.
the class RoadmapGenerator method populateScenario.
private void populateScenario(ApplicationContext ctx, Scenario scenario) {
ScenarioAxisItemDao scenarioAxisItemDao = getScenarioAxisItemDao(ctx);
MeasurableRatingService measurableRatingService = getMeasurableRatingService(ctx);
scenario.id().ifPresent(scenarioId -> {
Collection<ScenarioAxisItem> axisItems = scenarioAxisItemDao.findForScenarioId(scenarioId);
Map<AxisOrientation, Collection<ScenarioAxisItem>> byOrientation = groupBy(ScenarioAxisItem::axisOrientation, axisItems);
IdSelectionOptions options = mkOpts(scenario.entityReference());
Map<Long, Collection<MeasurableRating>> ratingsByMeasurableId = groupBy(MeasurableRating::measurableId, measurableRatingService.findByMeasurableIdSelector(options));
List<ScenarioRatingItemRecord> scenarioRatingItems = IntStream.range(0, randomIntBetween(10, 300)).mapToObj(i -> tuple(randomPick(byOrientation.get(AxisOrientation.COLUMN)), randomPick(byOrientation.get(AxisOrientation.ROW)))).map(t -> t.map1(d -> d.domainItem().id()).map2(d -> d.domainItem().id())).map(t -> t.concat(tuple(randomPick(ratingsByMeasurableId.get(t.v1)), randomPick(ratingsByMeasurableId.get(t.v2))))).map(t -> {
MeasurableRating rating = t.v3 != null ? t.v3 : t.v4;
ScenarioRatingItemRecord record = getDsl(ctx).newRecord(SCENARIO_RATING_ITEM);
record.setScenarioId(scenarioId);
record.setColumnId(t.v1);
record.setColumnKind(EntityKind.MEASURABLE.name());
record.setRowId(t.v2);
record.setRowKind(EntityKind.MEASURABLE.name());
record.setDomainItemId(rating.entityReference().id());
record.setDomainItemKind(rating.entityReference().kind().name());
record.setRating(String.valueOf(rating.rating()));
record.setLastUpdatedBy("admin");
record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
return record;
}).collect(Collectors.toList());
getDsl(ctx).batchInsert(scenarioRatingItems).execute();
});
}
use of org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord in project waltz by khartec.
the class ScenarioRatingImporter method mkScenarioRatingRecords.
private List<ScenarioRatingItemRecord> mkScenarioRatingRecords(List<Measurable> measurables, Map<String, RatingSchemeItem> ratingsByName, List<ScenarioRatingRow> rows, Scenario scenario) {
Collection<ScenarioAxisItem> scenarioAxes = scenarioAxisItemDao.findForScenarioId(scenario.id().get());
Map<Long, Measurable> measurablesById = indexBy(m -> m.id().get(), measurables);
Map<String, ScenarioAxisItem> scenarioAxesByName = scenarioAxes.stream().map(sa -> Tuple.tuple(lower(measurablesById.get(sa.domainItem().id()).name()), sa)).collect(toMap(t -> t.v1(), t -> t.v2()));
return rows.stream().map(r -> {
ScenarioAxisItem columnAxis = scenarioAxesByName.get(lower(r.column()));
checkNotNull(columnAxis, "columnAxis cannot be null");
checkTrue(columnAxis.axisOrientation().equals(AxisOrientation.COLUMN), "column does not match a oolumn axis");
ScenarioAxisItem rowAxis = scenarioAxesByName.get(lower(r.row()));
checkNotNull(rowAxis, "rowAxis cannot be null");
checkTrue(rowAxis.axisOrientation().equals(AxisOrientation.ROW), "row does not match a row axis");
Application app = assetCodeToApplicationMap.get(r.assetCode());
checkNotNull(app, String.format("Application with asset code[%s] cannot be null", r.assetCode()));
RatingSchemeItem rating = ratingsByName.get(lower(r.rating()));
checkNotNull(rating, String.format("rating [%s] cannot be null", r.rating()));
ScenarioRatingItemRecord record = new ScenarioRatingItemRecord();
record.setScenarioId(scenario.id().get());
record.setRating(rating.rating().toString());
record.setDomainItemKind(EntityKind.APPLICATION.name());
record.setDomainItemId(app.id().get());
record.setRowKind(rowAxis.domainItem().kind().name());
record.setRowId(rowAxis.domainItem().id());
record.setColumnKind(columnAxis.domainItem().kind().name());
record.setColumnId(columnAxis.domainItem().id());
record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
record.setLastUpdatedBy(r.providedBy());
record.setDescription(r.description());
return record;
}).collect(toList());
}
use of org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord in project waltz by khartec.
the class ScenarioRatingImporter method updateRatingsForScenario.
private void updateRatingsForScenario(List<Measurable> measurables, Roadmap roadmap, Map<String, RatingSchemeItem> ratingsByName, List<ScenarioRatingRow> rows, Map<String, Scenario> scenariosByName, String scenarioName) {
// fetch scenario and axis items
Scenario scenario = scenariosByName.get(lower(scenarioName));
checkNotNull(scenario, "scenario [" + scenarioName + "] cannot be null");
// ensure all scenario axes
ensureScenarioAxes(measurables, roadmap, scenario, rows);
// convert rows to scenario rating items
List<ScenarioRatingItemRecord> records = mkScenarioRatingRecords(measurables, ratingsByName, rows, scenario);
removeExistingRatings(dsl, scenario);
// insert new ones
int[] inserts = dsl.batchInsert(records).execute();
System.out.printf("Inserted %s records for scenario %s \n", inserts.length, scenarioName);
}
use of org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord in project waltz by khartec.
the class ScenarioPopulator method mkBaseRecord.
/**
* Creates a new scenario rating item record and populates the base fields
* from the given query result row.
*
* @param tx Transactional dsl context
* @param r Query result row
* @param now timestamp representing now
* @return Paritally completed ScenarioRatingItemRecord
*/
private static ScenarioRatingItemRecord mkBaseRecord(DSLContext tx, Record r, Timestamp now) {
ScenarioRatingItemRecord item = tx.newRecord(SCENARIO_RATING_ITEM);
item.setScenarioId(r.get(s.ID));
item.setRowKind(r.get(rai.DOMAIN_ITEM_KIND));
item.setRowId(r.get(rai.DOMAIN_ITEM_ID));
item.setColumnKind(r.get(cai.DOMAIN_ITEM_KIND));
item.setColumnId(r.get(cai.DOMAIN_ITEM_ID));
item.setLastUpdatedAt(now);
item.setLastUpdatedBy("admin");
return item;
}
Aggregations