Search in sources :

Example 1 with MeasurableCategoryDao

use of org.finos.waltz.data.measurable_category.MeasurableCategoryDao 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 MeasurableCategoryDao

use of org.finos.waltz.data.measurable_category.MeasurableCategoryDao 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

MeasurableCategoryDao (org.finos.waltz.data.measurable_category.MeasurableCategoryDao)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 Date (java.sql.Date)1 java.util (java.util)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Collectors.collectingAndThen (java.util.stream.Collectors.collectingAndThen)1 CollectionUtilities.first (org.finos.waltz.common.CollectionUtilities.first)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 DateTimeUtilities.toSqlDate (org.finos.waltz.common.DateTimeUtilities.toSqlDate)1 DateTimeUtilities.today (org.finos.waltz.common.DateTimeUtilities.today)1 LoggingUtilities (org.finos.waltz.common.LoggingUtilities)1 MapUtilities.groupBy (org.finos.waltz.common.MapUtilities.groupBy)1 RandomUtilities (org.finos.waltz.common.RandomUtilities)1 SetUtilities.map (org.finos.waltz.common.SetUtilities.map)1 SetUtilities.minus (org.finos.waltz.common.SetUtilities.minus)1 ApplicationDao (org.finos.waltz.data.application.ApplicationDao)1 MeasurableRatingDao (org.finos.waltz.data.measurable_rating.MeasurableRatingDao)1 EntityKind (org.finos.waltz.model.EntityKind)1 AllocationScheme (org.finos.waltz.model.allocation_scheme.AllocationScheme)1