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