use of org.finos.waltz.schema.tables.records.MeasurableRatingPlannedDecommissionRecord in project waltz by khartec.
the class MeasurableRatingPlannedDecommissionDao method save.
public Tuple2<Operation, Boolean> save(EntityReference entityReference, long measurableId, DateFieldChange dateChange, String userName) {
checkIfReadOnly(entityReference, measurableId);
MeasurableRatingPlannedDecommissionRecord existingRecord = dsl.select(MEASURABLE_RATING_PLANNED_DECOMMISSION.fields()).from(MEASURABLE_RATING_PLANNED_DECOMMISSION).where(mkRefCondition(entityReference).and(MEASURABLE_RATING_PLANNED_DECOMMISSION.MEASURABLE_ID.eq(measurableId))).fetchOne().into(MEASURABLE_RATING_PLANNED_DECOMMISSION);
if (existingRecord != null) {
updateDecommDateOnRecord(existingRecord, dateChange, userName);
boolean updatedRecord = existingRecord.update() == 1;
return Tuple.tuple(Operation.UPDATE, updatedRecord);
} else {
MeasurableRatingPlannedDecommissionRecord record = dsl.newRecord(MEASURABLE_RATING_PLANNED_DECOMMISSION);
updateDecommDateOnRecord(record, dateChange, userName);
record.setCreatedAt(DateTimeUtilities.nowUtcTimestamp());
record.setCreatedBy(userName);
record.setEntityId(entityReference.id());
record.setEntityKind(entityReference.kind().name());
record.setMeasurableId(measurableId);
boolean recordsInserted = record.insert() == 1;
return Tuple.tuple(Operation.ADD, recordsInserted);
}
}
use of org.finos.waltz.schema.tables.records.MeasurableRatingPlannedDecommissionRecord 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