Search in sources :

Example 6 with RatingSchemeItem

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());
}
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) Measurable(org.finos.waltz.model.measurable.Measurable) ScenarioAxisItem(org.finos.waltz.model.scenario.ScenarioAxisItem) ScenarioRatingItemRecord(org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord) Application(org.finos.waltz.model.application.Application) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem)

Example 7 with RatingSchemeItem

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));
    });
}
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)

Aggregations

RatingSchemeItem (org.finos.waltz.model.rating.RatingSchemeItem)7 Collectors (java.util.stream.Collectors)5 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)5 RatingSchemeDAO (org.finos.waltz.data.rating_scheme.RatingSchemeDAO)4 EntityKind (org.finos.waltz.model.EntityKind)4 Application (org.finos.waltz.model.application.Application)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 MapUtilities.indexBy (org.finos.waltz.common.MapUtilities.indexBy)3 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)3 ExternalIdValue (org.finos.waltz.model.external_identifier.ExternalIdValue)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 CsvPreference (org.supercsv.prefs.CsvPreference)3 InputStreamReader (java.io.InputStreamReader)2 String.format (java.lang.String.format)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2