Search in sources :

Example 1 with MeasurableRating

use of org.finos.waltz.model.measurable_rating.MeasurableRating 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 2 with MeasurableRating

use of org.finos.waltz.model.measurable_rating.MeasurableRating in project waltz by khartec.

the class AppMeasurableDecommGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    MeasurableCategoryDao categoryDao = ctx.getBean(MeasurableCategoryDao.class);
    ApplicationDao applicationDao = ctx.getBean(ApplicationDao.class);
    MeasurableRatingDao ratingDao = ctx.getBean(MeasurableRatingDao.class);
    first(categoryDao.findByExternalId("CAPABILITY")).id().ifPresent(categoryId -> {
        Collection<MeasurableRating> ratings = ratingDao.findByCategory(categoryId);
        int[] rc = ratings.stream().filter(e -> randomTrue(0.1)).map(r -> {
            MeasurableRatingPlannedDecommissionRecord record = dsl.newRecord(MEASURABLE_RATING_PLANNED_DECOMMISSION);
            record.setEntityId(r.entityReference().id());
            record.setEntityKind(r.entityReference().kind().name());
            record.setMeasurableId(r.measurableId());
            record.setPlannedDecommissionDate(mkFutureDate());
            record.setCreatedBy("test");
            record.setCreatedAt(DateTimeUtilities.nowUtcTimestamp());
            record.setUpdatedBy("test");
            record.setUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
            return record;
        }).collect(collectingAndThen(Collectors.toSet(), dsl::batchInsert)).execute();
        List<Application> allApps = applicationDao.findAll();
        Map<Long, Collection<MeasurableRating>> allRatingsByMeasurableId = groupBy(ratings, MeasurableRating::measurableId);
        dsl.selectFrom(MEASURABLE_RATING_PLANNED_DECOMMISSION).fetchGroups(r -> r.get(MEASURABLE_RATING_PLANNED_DECOMMISSION.MEASURABLE_ID)).entrySet().stream().flatMap(e -> {
            Set<Long> appIdsForMeasurable = map(allRatingsByMeasurableId.get(e.getValue()), r -> r.entityReference().id());
            Set<Long> decommingAppIds = map(e.getValue(), MeasurableRatingPlannedDecommissionRecord::getEntityId);
            Set<Long> possibleReplacements = minus(appIdsForMeasurable, decommingAppIds);
            Set<Long> replacementAppIds = new HashSet<>();
            if (possibleReplacements.size() > 1) {
                Tuple2<Long, List<Long>> firstPick = pickAndRemove(new ArrayList<>(possibleReplacements));
                Tuple2<Long, List<Long>> secondPick = pickAndRemove(firstPick.v2);
                replacementAppIds.add(firstPick.v1);
                replacementAppIds.add(secondPick.v1);
            }
            replacementAppIds.add(randomPick(allApps).id().get());
            return e.getValue().stream().filter(r -> randomTrue(0.7)).map(r -> {
                MeasurableRatingReplacementRecord record = dsl.newRecord(MEASURABLE_RATING_REPLACEMENT);
                record.setDecommissionId(r.getId());
                record.setEntityId(randomPick(replacementAppIds));
                record.setEntityKind(EntityKind.APPLICATION.name());
                record.setPlannedCommissionDate(mkFutureDate());
                record.setCreatedBy("test");
                record.setCreatedAt(DateTimeUtilities.nowUtcTimestamp());
                record.setUpdatedBy("test");
                record.setUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
                return record;
            });
        }).collect(collectingAndThen(Collectors.toSet(), dsl::batchInsert)).execute();
    });
    log("hello %s", "world");
    return null;
}
Also used : MeasurableCategoryDao(org.finos.waltz.data.measurable_category.MeasurableCategoryDao) java.util(java.util) MeasurableRatingPlannedDecommissionRecord(org.finos.waltz.schema.tables.records.MeasurableRatingPlannedDecommissionRecord) MeasurableRating(org.finos.waltz.model.measurable_rating.MeasurableRating) EntityKind(org.finos.waltz.model.EntityKind) SetUtilities.minus(org.finos.waltz.common.SetUtilities.minus) LoggingUtilities(org.finos.waltz.common.LoggingUtilities) DIConfiguration(org.finos.waltz.service.DIConfiguration) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) DateTimeUtilities.toSqlDate(org.finos.waltz.common.DateTimeUtilities.toSqlDate) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) MeasurableRatingDao(org.finos.waltz.data.measurable_rating.MeasurableRatingDao) Tuple2(org.jooq.lambda.tuple.Tuple2) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) DSLContext(org.jooq.DSLContext) MEASURABLE_RATING_REPLACEMENT(org.finos.waltz.schema.Tables.MEASURABLE_RATING_REPLACEMENT) CollectionUtilities.first(org.finos.waltz.common.CollectionUtilities.first) Application(org.finos.waltz.model.application.Application) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) MeasurableRatingReplacementRecord(org.finos.waltz.schema.tables.records.MeasurableRatingReplacementRecord) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Date(java.sql.Date) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) RandomUtilities(org.finos.waltz.common.RandomUtilities) MEASURABLE_RATING_PLANNED_DECOMMISSION(org.finos.waltz.schema.Tables.MEASURABLE_RATING_PLANNED_DECOMMISSION) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) DateTimeUtilities.today(org.finos.waltz.common.DateTimeUtilities.today) MeasurableRatingDao(org.finos.waltz.data.measurable_rating.MeasurableRatingDao) DSLContext(org.jooq.DSLContext) MeasurableRatingPlannedDecommissionRecord(org.finos.waltz.schema.tables.records.MeasurableRatingPlannedDecommissionRecord) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) MeasurableRating(org.finos.waltz.model.measurable_rating.MeasurableRating) MeasurableCategoryDao(org.finos.waltz.data.measurable_category.MeasurableCategoryDao) MeasurableRatingReplacementRecord(org.finos.waltz.schema.tables.records.MeasurableRatingReplacementRecord) Application(org.finos.waltz.model.application.Application)

Aggregations

java.util (java.util)2 Collectors (java.util.stream.Collectors)2 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)2 MapUtilities.groupBy (org.finos.waltz.common.MapUtilities.groupBy)2 MeasurableRatingDao (org.finos.waltz.data.measurable_rating.MeasurableRatingDao)2 EntityKind (org.finos.waltz.model.EntityKind)2 MeasurableRating (org.finos.waltz.model.measurable_rating.MeasurableRating)2 DSLContext (org.jooq.DSLContext)2 ApplicationContext (org.springframework.context.ApplicationContext)2 Date (java.sql.Date)1 Collectors.collectingAndThen (java.util.stream.Collectors.collectingAndThen)1 IntStream (java.util.stream.IntStream)1 CollectionUtilities.first (org.finos.waltz.common.CollectionUtilities.first)1 DateTimeUtilities.toSqlDate (org.finos.waltz.common.DateTimeUtilities.toSqlDate)1 DateTimeUtilities.today (org.finos.waltz.common.DateTimeUtilities.today)1 ListUtilities.filter (org.finos.waltz.common.ListUtilities.filter)1 LoggingUtilities (org.finos.waltz.common.LoggingUtilities)1 ObjectUtilities.any (org.finos.waltz.common.ObjectUtilities.any)1 RandomUtilities (org.finos.waltz.common.RandomUtilities)1 RandomUtilities.randomIntBetween (org.finos.waltz.common.RandomUtilities.randomIntBetween)1