use of org.finos.waltz.model.application.Application in project waltz by khartec.
the class ScenarioRatingItemService method writeUpdateRatingLog.
private void writeUpdateRatingLog(ChangeScenarioCommand command, String userId) {
String message;
Application application = applicationService.getById(command.appId());
Scenario scenario = scenarioService.getById(command.scenarioId());
List<RatingSchemeItem> ratings = ratingSchemeService.getById(command.ratingSchemeId()).ratings();
message = String.format("Application %s (%s), moved from %s to %s for %s", ExternalIdValue.orElse(application.assetCode(), "Unknown"), application.name(), getRatingName(ratings, command.previousRating()), getRatingName(ratings, command.rating()), scenario.name());
changeLogService.write(mkBasicLogEntry(command.scenarioId(), message, userId));
}
use of org.finos.waltz.model.application.Application in project waltz by khartec.
the class ReportGridExtractor method mkCSVReport.
private byte[] mkCSVReport(Set<Tuple2<ReportGridColumnDefinition, Boolean>> columnDefinitions, List<Tuple2<Application, ArrayList<Object>>> reportRows) throws IOException {
List<String> headers = mkHeaderStrings(columnDefinitions);
StringWriter writer = new StringWriter();
CsvListWriter csvWriter = new CsvListWriter(writer, CsvPreference.EXCEL_PREFERENCE);
csvWriter.write(headers);
reportRows.forEach(unchecked(row -> csvWriter.write(simplify(row))));
csvWriter.flush();
return writer.toString().getBytes();
}
use of org.finos.waltz.model.application.Application in project waltz by finos.
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;
}
use of org.finos.waltz.model.application.Application in project waltz by finos.
the class AssetCostGenerator method create.
@Override
public Map<String, Integer> create(ApplicationContext ctx) {
ApplicationService applicationService = ctx.getBean(ApplicationService.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
dsl.transaction(c -> {
DSLContext tx = c.dsl();
List<Application> apps = applicationService.findAll();
List<CostRecord> appDevCosts = generateRecords(apps, WaltzUtilities.getOrCreateCostKind(tx, "Application Development", "APPLICATION_DEVELOPMENT"), 900_000);
List<CostRecord> infraCosts = generateRecords(apps, WaltzUtilities.getOrCreateCostKind(tx, "Infrastructure", "INFRASTRUCTURE"), 50_000);
List<CostRecord> cloudMigrationCosts = generateRecords(randomPickSome(apps, 0.4), WaltzUtilities.getOrCreateCostKind(tx, "Cloud Migration", "CLOUD"), 200_000);
List<CostRecord> depreciationCosts = generateRecords(randomPickSome(apps, 0.6), WaltzUtilities.getOrCreateCostKind(tx, "Depreciation", "DEPRECIATION"), 100_000);
tx.batchInsert(appDevCosts).execute();
tx.batchInsert(infraCosts).execute();
tx.batchInsert(cloudMigrationCosts).execute();
tx.batchInsert(depreciationCosts).execute();
});
return null;
}
use of org.finos.waltz.model.application.Application in project waltz by finos.
the class FlowSummaryWithTypesAndPhysicalsExport method mkAppIdSelector.
private static Select<Record1<Long>> mkAppIdSelector(ApplicationIdSelectorFactory appIdSelectorFactory) {
EntityReference infraRef = mkRef(EntityKind.ORG_UNIT, 6811);
EntityReference entRiskRef = mkRef(EntityKind.ORG_UNIT, 3125);
EntityReference regCtrlRef = mkRef(EntityKind.ORG_UNIT, 2761);
Function<EntityReference, Select<Record1<Long>>> mkOrgUnitSelector = (ref) -> DSL.select(ENTITY_HIERARCHY.ID).from(ENTITY_HIERARCHY).where(ENTITY_HIERARCHY.ANCESTOR_ID.eq(ref.id())).and(ENTITY_HIERARCHY.KIND.eq(ref.kind().name()));
Select<Record1<Long>> ouSelector = DSL.selectFrom(mkOrgUnitSelector.apply(infraRef).unionAll(mkOrgUnitSelector.apply(entRiskRef)).unionAll(mkOrgUnitSelector.apply(regCtrlRef)).asTable());
return DSL.select(APPLICATION.ID).from(APPLICATION).where(APPLICATION.ORGANISATIONAL_UNIT_ID.in(ouSelector)).and(APPLICATION.LIFECYCLE_PHASE.notEqual(EntityLifecycleStatus.REMOVED.name())).and(APPLICATION.IS_REMOVED.isFalse());
}
Aggregations