Search in sources :

Example 1 with ScenarioAxisItem

use of org.finos.waltz.model.scenario.ScenarioAxisItem in project waltz by khartec.

the class ScenarioRatingImporter method addMissingColumns.

private void addMissingColumns(List<Measurable> measurables, List<ScenarioRatingRow> ratingRows, Roadmap roadmap, ScenarioAxisItemDao scenarioAxisItemDao, Map<String, ScenarioAxisItem> scenarioAxesByName, Scenario scenario) {
    List<String> columns = ratingRows.stream().map(r -> lower(r.column())).distinct().collect(toList());
    Map<String, Measurable> allColumnMeasurables = measurables.stream().filter(m -> m.categoryId() == roadmap.columnType().id()).collect(toMap(m -> lower(m.name()), m -> m, (m1, m2) -> m2.concrete() ? m2 : m1));
    for (String column : columns) {
        if (!scenarioAxesByName.containsKey(column)) {
            Measurable measurable = allColumnMeasurables.get(column);
            checkNotNull(measurable, String.format("measurable with name [%s] not found", column));
            scenarioAxisItemDao.add(scenario.id().get(), AxisOrientation.COLUMN, measurable.entityReference(), 0);
        }
    }
}
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)

Example 2 with ScenarioAxisItem

use of org.finos.waltz.model.scenario.ScenarioAxisItem in project waltz by khartec.

the class RoadmapGenerator method populateScenario.

private void populateScenario(ApplicationContext ctx, Scenario scenario) {
    ScenarioAxisItemDao scenarioAxisItemDao = getScenarioAxisItemDao(ctx);
    MeasurableRatingService measurableRatingService = getMeasurableRatingService(ctx);
    scenario.id().ifPresent(scenarioId -> {
        Collection<ScenarioAxisItem> axisItems = scenarioAxisItemDao.findForScenarioId(scenarioId);
        Map<AxisOrientation, Collection<ScenarioAxisItem>> byOrientation = groupBy(ScenarioAxisItem::axisOrientation, axisItems);
        IdSelectionOptions options = mkOpts(scenario.entityReference());
        Map<Long, Collection<MeasurableRating>> ratingsByMeasurableId = groupBy(MeasurableRating::measurableId, measurableRatingService.findByMeasurableIdSelector(options));
        List<ScenarioRatingItemRecord> scenarioRatingItems = IntStream.range(0, randomIntBetween(10, 300)).mapToObj(i -> tuple(randomPick(byOrientation.get(AxisOrientation.COLUMN)), randomPick(byOrientation.get(AxisOrientation.ROW)))).map(t -> t.map1(d -> d.domainItem().id()).map2(d -> d.domainItem().id())).map(t -> t.concat(tuple(randomPick(ratingsByMeasurableId.get(t.v1)), randomPick(ratingsByMeasurableId.get(t.v2))))).map(t -> {
            MeasurableRating rating = t.v3 != null ? t.v3 : t.v4;
            ScenarioRatingItemRecord record = getDsl(ctx).newRecord(SCENARIO_RATING_ITEM);
            record.setScenarioId(scenarioId);
            record.setColumnId(t.v1);
            record.setColumnKind(EntityKind.MEASURABLE.name());
            record.setRowId(t.v2);
            record.setRowKind(EntityKind.MEASURABLE.name());
            record.setDomainItemId(rating.entityReference().id());
            record.setDomainItemKind(rating.entityReference().kind().name());
            record.setRating(String.valueOf(rating.rating()));
            record.setLastUpdatedBy("admin");
            record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
            return record;
        }).collect(Collectors.toList());
        getDsl(ctx).batchInsert(scenarioRatingItems).execute();
    });
}
Also used : IntStream(java.util.stream.IntStream) ScenarioAxisItemDao(org.finos.waltz.data.scenario.ScenarioAxisItemDao) java.util(java.util) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) DSL(org.jooq.impl.DSL) MeasurableRating(org.finos.waltz.model.measurable_rating.MeasurableRating) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) RandomUtilities.randomIntBetween(org.finos.waltz.common.RandomUtilities.randomIntBetween) SetUtilities.asSet(org.finos.waltz.common.SetUtilities.asSet) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) Scenario(org.finos.waltz.model.scenario.Scenario) SelectConditionStep(org.jooq.SelectConditionStep) ObjectUtilities.any(org.finos.waltz.common.ObjectUtilities.any) MeasurableRatingDao(org.finos.waltz.data.measurable_rating.MeasurableRatingDao) Measurable(org.finos.waltz.model.measurable.Measurable) Record1(org.jooq.Record1) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) DSLContext(org.jooq.DSLContext) ROADMAP(org.finos.waltz.schema.tables.Roadmap.ROADMAP) MeasurableDao(org.finos.waltz.data.measurable.MeasurableDao) ScenarioDao(org.finos.waltz.data.scenario.ScenarioDao) IdSelectionOptions.mkOpts(org.finos.waltz.model.IdSelectionOptions.mkOpts) AxisOrientation(org.finos.waltz.model.AxisOrientation) MeasurableRatingService(org.finos.waltz.service.measurable_rating.MeasurableRatingService) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) ScenarioRatingItemRecord(org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord) ScenarioAxisItem(org.finos.waltz.model.scenario.ScenarioAxisItem) ListUtilities.filter(org.finos.waltz.common.ListUtilities.filter) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) RoadmapDao(org.finos.waltz.data.roadmap.RoadmapDao) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) EntityReference(org.finos.waltz.model.EntityReference) Roadmap(org.finos.waltz.model.roadmap.Roadmap) MeasurableIdSelectorFactory(org.finos.waltz.data.measurable.MeasurableIdSelectorFactory) MeasurableRatingService(org.finos.waltz.service.measurable_rating.MeasurableRatingService) ScenarioAxisItem(org.finos.waltz.model.scenario.ScenarioAxisItem) MeasurableRating(org.finos.waltz.model.measurable_rating.MeasurableRating) ScenarioRatingItemRecord(org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord) ScenarioAxisItemDao(org.finos.waltz.data.scenario.ScenarioAxisItemDao) AxisOrientation(org.finos.waltz.model.AxisOrientation) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Example 3 with ScenarioAxisItem

use of org.finos.waltz.model.scenario.ScenarioAxisItem 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 4 with ScenarioAxisItem

use of org.finos.waltz.model.scenario.ScenarioAxisItem 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);
        }
    }
}
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)

Aggregations

Collectors (java.util.stream.Collectors)4 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)4 MeasurableDao (org.finos.waltz.data.measurable.MeasurableDao)4 RoadmapDao (org.finos.waltz.data.roadmap.RoadmapDao)4 ScenarioAxisItemDao (org.finos.waltz.data.scenario.ScenarioAxisItemDao)4 ScenarioDao (org.finos.waltz.data.scenario.ScenarioDao)4 AxisOrientation (org.finos.waltz.model.AxisOrientation)4 EntityKind (org.finos.waltz.model.EntityKind)4 Measurable (org.finos.waltz.model.measurable.Measurable)4 Roadmap (org.finos.waltz.model.roadmap.Roadmap)4 Scenario (org.finos.waltz.model.scenario.Scenario)4 ScenarioAxisItem (org.finos.waltz.model.scenario.ScenarioAxisItem)4 ScenarioRatingItemRecord (org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord)4 DSLContext (org.jooq.DSLContext)4 IOException (java.io.IOException)3 InputStreamReader (java.io.InputStreamReader)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3