Search in sources :

Example 1 with RatingScheme

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));
    });
}
Also used : ICsvMapReader(org.supercsv.io.ICsvMapReader) ScenarioAxisItemDao(org.finos.waltz.data.scenario.ScenarioAxisItemDao) APPLICATION(org.finos.waltz.schema.tables.Application.APPLICATION) EntityKind(org.finos.waltz.model.EntityKind) RatingScheme(org.finos.waltz.model.rating.RatingScheme) DIConfiguration(org.finos.waltz.service.DIConfiguration) StringUtilities.lower(org.finos.waltz.common.StringUtilities.lower) CsvPreference(org.supercsv.prefs.CsvPreference) Scenario(org.finos.waltz.model.scenario.Scenario) ArrayList(java.util.ArrayList) Checks.checkTrue(org.finos.waltz.common.Checks.checkTrue) Measurable(org.finos.waltz.model.measurable.Measurable) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) SCENARIO_RATING_ITEM(org.finos.waltz.schema.tables.ScenarioRatingItem.SCENARIO_RATING_ITEM) Map(java.util.Map) DSLContext(org.jooq.DSLContext) Application(org.finos.waltz.model.application.Application) MeasurableDao(org.finos.waltz.data.measurable.MeasurableDao) ScenarioDao(org.finos.waltz.data.scenario.ScenarioDao) Collection(java.util.Collection) IOException(java.io.IOException) AxisOrientation(org.finos.waltz.model.AxisOrientation) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MapUtilities.indexBy(org.finos.waltz.common.MapUtilities.indexBy) ScenarioRatingItemRecord(org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord) CsvMapReader(org.supercsv.io.CsvMapReader) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) ScenarioAxisItem(org.finos.waltz.model.scenario.ScenarioAxisItem) Tuple(org.jooq.lambda.tuple.Tuple) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) RatingSchemeDAO(org.finos.waltz.data.rating_scheme.RatingSchemeDAO) RoadmapDao(org.finos.waltz.data.roadmap.RoadmapDao) Roadmap(org.finos.waltz.model.roadmap.Roadmap) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) Scenario(org.finos.waltz.model.scenario.Scenario) Measurable(org.finos.waltz.model.measurable.Measurable) Roadmap(org.finos.waltz.model.roadmap.Roadmap) RatingScheme(org.finos.waltz.model.rating.RatingScheme) Application(org.finos.waltz.model.application.Application) Map(java.util.Map)

Example 2 with RatingScheme

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;
}
Also used : RatingScheme(org.finos.waltz.model.rating.RatingScheme)

Example 3 with RatingScheme

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();
}
Also used : DSL(org.jooq.impl.DSL) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) RatingScheme(org.finos.waltz.model.rating.RatingScheme) RatingSchemeItemRecord(org.finos.waltz.schema.tables.records.RatingSchemeItemRecord) RatingSchemeService(org.finos.waltz.service.rating_scheme.RatingSchemeService) ApplicationContext(org.springframework.context.ApplicationContext) ColorUtilities(org.finos.waltz.common.ColorUtilities) AssessmentDefinitionRecord(org.finos.waltz.schema.tables.records.AssessmentDefinitionRecord) RandomUtilities(org.finos.waltz.common.RandomUtilities) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Tuple3(org.jooq.lambda.tuple.Tuple3) Stream(java.util.stream.Stream) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) ListUtilities(org.finos.waltz.common.ListUtilities) org.jooq(org.jooq) Map(java.util.Map) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) AssessmentRatingRecord(org.finos.waltz.schema.tables.records.AssessmentRatingRecord) RatingSchemeRecord(org.finos.waltz.schema.tables.records.RatingSchemeRecord) AssessmentRatingRecord(org.finos.waltz.schema.tables.records.AssessmentRatingRecord)

Aggregations

RatingScheme (org.finos.waltz.model.rating.RatingScheme)3 List (java.util.List)2 Map (java.util.Map)2 EntityKind (org.finos.waltz.model.EntityKind)2 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)1 Checks.checkTrue (org.finos.waltz.common.Checks.checkTrue)1 ColorUtilities (org.finos.waltz.common.ColorUtilities)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 ListUtilities (org.finos.waltz.common.ListUtilities)1 MapUtilities.indexBy (org.finos.waltz.common.MapUtilities.indexBy)1 RandomUtilities (org.finos.waltz.common.RandomUtilities)1 RandomUtilities.randomPick (org.finos.waltz.common.RandomUtilities.randomPick)1 StringUtilities.lower (org.finos.waltz.common.StringUtilities.lower)1