use of org.finos.waltz.model.rating.RatingScheme 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.rating.RatingScheme in project waltz by khartec.
the class AssessmentGenerator method create.
@Override
public Map<String, Integer> create(ApplicationContext ctx) {
RatingScheme confidentialityRatingScheme = getOrCreateConfidentialityRatingScheme(ctx);
Long appDefnId = createAppAssessmentDefinition(ctx, confidentialityRatingScheme);
RatingScheme impactRatingScheme = getOrCreateImpactRatingScheme(ctx);
Long archAssessmentRating = createArchImpactAssessmentDefinition(ctx, impactRatingScheme);
Long regAssessmentRating = createRegulatoryImpactAssessmentDefinition(ctx, impactRatingScheme);
createLotsOfAssessmentDefinitions(ctx, impactRatingScheme);
createAssessmentRecords(getDsl(ctx), confidentialityRatingScheme, appDefnId, EntityKind.APPLICATION, APPLICATION.ID, 0.9);
createAssessmentRecords(getDsl(ctx), impactRatingScheme, archAssessmentRating, EntityKind.CHANGE_INITIATIVE, CHANGE_INITIATIVE.ID, 0.9);
createAssessmentRecords(getDsl(ctx), impactRatingScheme, regAssessmentRating, EntityKind.CHANGE_INITIATIVE, CHANGE_INITIATIVE.ID, 0.5);
return null;
}
use of org.finos.waltz.model.rating.RatingScheme in project waltz by khartec.
the class AssessmentGenerator method createAssessmentRecords.
private void createAssessmentRecords(DSLContext dsl, RatingScheme ratingScheme, Long assessmentDefnId, EntityKind targetKind, TableField<? extends Record, Long> targetIdField, double density) {
List<Long> targetIds = loadAllIds(dsl, targetIdField);
List<AssessmentRatingRecord> records = targetIds.stream().filter(d -> RandomUtilities.getRandom().nextDouble() < density).map(id -> tuple(id, randomPick(ratingScheme.ratings()))).filter(t -> t.v2.id().isPresent()).map(t -> {
AssessmentRatingRecord record = new AssessmentRatingRecord();
record.setAssessmentDefinitionId(assessmentDefnId);
record.setRatingId(t.v2.id().get());
record.setEntityKind(targetKind.name());
record.setEntityId(t.v1);
record.setLastUpdatedBy(SAMPLE_DATA_USER);
record.setProvenance(SAMPLE_DATA_PROVENANCE);
record.setDescription("sample data");
return record;
}).collect(toList());
log("About to store %d assessments for kind: %s", records.size(), targetIdField.getTable().getName());
dsl.batchInsert(records).execute();
}
Aggregations