use of org.finos.waltz.model.scenario.Scenario 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);
}
}
}
use of org.finos.waltz.model.scenario.Scenario 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));
});
}
use of org.finos.waltz.model.scenario.Scenario 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.model.scenario.Scenario in project waltz by khartec.
the class ScenarioDao method cloneScenario.
public Scenario cloneScenario(CloneScenarioCommand command) {
Scenario orig = getById(command.scenarioId());
Scenario clone = ImmutableScenario.copyOf(orig).withName(command.newName()).withEntityLifecycleStatus(EntityLifecycleStatus.PENDING).withReleaseStatus(ReleaseLifecycleStatus.DRAFT).withLastUpdatedAt(nowUtc()).withLastUpdatedBy(command.userId());
ScenarioRecord clonedRecord = TO_RECORD_MAPPER.apply(clone, dsl);
clonedRecord.store();
return ImmutableScenario.copyOf(clone).withId(clonedRecord.getId());
}
Aggregations