Search in sources :

Example 1 with MeasurableRatingService

use of org.finos.waltz.service.measurable_rating.MeasurableRatingService in project waltz by khartec.

the class AllocationHarness method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    AllocationSchemeService schemesService = ctx.getBean(AllocationSchemeService.class);
    MeasurableService measurableService = ctx.getBean(MeasurableService.class);
    MeasurableCategoryDao categoryDao = ctx.getBean(MeasurableCategoryDao.class);
    MeasurableRatingService ratingService = ctx.getBean(MeasurableRatingService.class);
    ApplicationService applicationService = ctx.getBean(ApplicationService.class);
    Tuple4<Application, MeasurableCategory, List<Measurable>, AllocationScheme> stuff = setup(dsl, schemesService, measurableService, categoryDao, applicationService);
    addRating(ratingService, stuff, 0);
    addRating(ratingService, stuff, 1);
    // addRating(ratingService, stuff, 2);
    // addAllocation(dsl, stuff, 0, 50);
    addAllocation(dsl, stuff, 1, 20);
    Long measurableCategory = stuff.v2.id().get();
    dumpRatings(dsl, stuff.v4);
    dumpAllocs(dsl, stuff.v4);
    doDiff(dsl, measurableCategory);
    System.out.println(ratingService.findByCategory(measurableCategory));
}
Also used : MeasurableRatingService(org.finos.waltz.service.measurable_rating.MeasurableRatingService) ImmutableAllocationScheme(org.finos.waltz.model.allocation_scheme.ImmutableAllocationScheme) AllocationScheme(org.finos.waltz.model.allocation_scheme.AllocationScheme) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MeasurableService(org.finos.waltz.service.measurable.MeasurableService) MeasurableCategoryDao(org.finos.waltz.data.measurable_category.MeasurableCategoryDao) AllocationSchemeService(org.finos.waltz.service.allocation_schemes.AllocationSchemeService) MeasurableCategory(org.finos.waltz.model.measurable_category.MeasurableCategory) List(java.util.List) ApplicationService(org.finos.waltz.service.application.ApplicationService)

Example 2 with MeasurableRatingService

use of org.finos.waltz.service.measurable_rating.MeasurableRatingService 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)

Aggregations

MeasurableRatingService (org.finos.waltz.service.measurable_rating.MeasurableRatingService)2 java.util (java.util)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 ListUtilities.filter (org.finos.waltz.common.ListUtilities.filter)1 MapUtilities.groupBy (org.finos.waltz.common.MapUtilities.groupBy)1 ObjectUtilities.any (org.finos.waltz.common.ObjectUtilities.any)1 RandomUtilities.randomIntBetween (org.finos.waltz.common.RandomUtilities.randomIntBetween)1 RandomUtilities.randomPick (org.finos.waltz.common.RandomUtilities.randomPick)1 SetUtilities.asSet (org.finos.waltz.common.SetUtilities.asSet)1 MeasurableDao (org.finos.waltz.data.measurable.MeasurableDao)1 MeasurableIdSelectorFactory (org.finos.waltz.data.measurable.MeasurableIdSelectorFactory)1 MeasurableCategoryDao (org.finos.waltz.data.measurable_category.MeasurableCategoryDao)1 MeasurableRatingDao (org.finos.waltz.data.measurable_rating.MeasurableRatingDao)1 RoadmapDao (org.finos.waltz.data.roadmap.RoadmapDao)1 ScenarioAxisItemDao (org.finos.waltz.data.scenario.ScenarioAxisItemDao)1 ScenarioDao (org.finos.waltz.data.scenario.ScenarioDao)1 AxisOrientation (org.finos.waltz.model.AxisOrientation)1