use of org.finos.waltz.model.scenario.ScenarioAxisItem in project waltz by khartec.
the class ScenarioRatingImporter method addMissingColumns.
private void addMissingColumns(List<Measurable> measurables, List<ScenarioRatingRow> ratingRows, Roadmap roadmap, ScenarioAxisItemDao scenarioAxisItemDao, Map<String, ScenarioAxisItem> scenarioAxesByName, Scenario scenario) {
List<String> columns = ratingRows.stream().map(r -> lower(r.column())).distinct().collect(toList());
Map<String, Measurable> allColumnMeasurables = measurables.stream().filter(m -> m.categoryId() == roadmap.columnType().id()).collect(toMap(m -> lower(m.name()), m -> m, (m1, m2) -> m2.concrete() ? m2 : m1));
for (String column : columns) {
if (!scenarioAxesByName.containsKey(column)) {
Measurable measurable = allColumnMeasurables.get(column);
checkNotNull(measurable, String.format("measurable with name [%s] not found", column));
scenarioAxisItemDao.add(scenario.id().get(), AxisOrientation.COLUMN, measurable.entityReference(), 0);
}
}
}
use of org.finos.waltz.model.scenario.ScenarioAxisItem 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.model.scenario.ScenarioAxisItem 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.model.scenario.ScenarioAxisItem in project waltz by khartec.
the class ScenarioRatingImporter method addMissingRows.
private void addMissingRows(List<Measurable> measurables, List<ScenarioRatingRow> ratingRows, Roadmap roadmap, ScenarioAxisItemDao scenarioAxisItemDao, Map<String, ScenarioAxisItem> scenarioAxesByName, Scenario scenario) {
List<String> rows = ratingRows.stream().map(r -> lower(r.row())).distinct().collect(toList());
Map<String, Measurable> allRowMeasurables = measurables.stream().filter(m -> m.categoryId() == roadmap.rowType().id()).collect(toMap(m -> lower(m.name()), m -> m, (m1, m2) -> m2.concrete() ? m2 : m1));
for (String row : rows) {
if (!scenarioAxesByName.containsKey(row)) {
Measurable measurable = allRowMeasurables.get(row);
checkNotNull(measurable, String.format("measurable with name [%s] not found", row));
scenarioAxisItemDao.add(scenario.id().get(), AxisOrientation.ROW, measurable.entityReference(), 0);
}
}
}
Aggregations