use of org.finos.waltz.model.rating.RatingSchemeItem 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.rating.RatingSchemeItem in project waltz by khartec.
the class ScenarioRatingImporter method importScenarioRatings.
public void importScenarioRatings(String filename) throws IOException {
List<Application> allApps = dsl.select().from(APPLICATION).fetch(ApplicationDao.TO_DOMAIN_MAPPER);
assetCodeToApplicationMap = indexBy(a -> ExternalIdValue.orElse(a.assetCode(), null), allApps);
List<ScenarioRatingRow> ratingRows = parseData(filename);
Map<String, Map<String, List<ScenarioRatingRow>>> rowsGroupedByRoadmapByScenario = ratingRows.stream().collect(groupingBy(ScenarioRatingRow::roadmap, groupingBy(ScenarioRatingRow::scenario)));
// get roadmap id
Map<String, Roadmap> roadmapNameToIdMap = getNameToRoadmapMap(roadmapDao);
List<Measurable> measurables = measurableDao.findAll();
rowsGroupedByRoadmapByScenario.forEach((String roadmapName, Map<String, List<ScenarioRatingRow>> scenarioAndRows) -> {
// get roadmap
Roadmap roadmap = roadmapNameToIdMap.get(lower(roadmapName));
checkNotNull(roadmap, "roadmap [" + roadmapName + "] cannot be null");
// get rating scheme
RatingScheme ratingScheme = ratingSchemeDao.getById(roadmap.ratingSchemeId());
checkNotNull(ratingScheme, "ratingScheme cannot be null");
Map<String, RatingSchemeItem> ratingsByName = indexBy(r -> lower(r.name()), ratingScheme.ratings());
// index available scenarios
Map<String, Scenario> scenariosByName = indexBy(s -> lower(s.name()), scenarioDao.findForRoadmapId(roadmap.id().get()));
scenarioAndRows.forEach((scenarioName, rows) -> updateRatingsForScenario(measurables, roadmap, ratingsByName, rows, scenariosByName, scenarioName));
});
}
Aggregations