Search in sources :

Example 16 with Application

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));
}
Also used : Application(org.finos.waltz.model.application.Application) Scenario(org.finos.waltz.model.scenario.Scenario) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem)

Example 17 with Application

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();
}
Also used : CellType(org.apache.poi.ss.usermodel.CellType) LifecyclePhase(org.finos.waltz.model.application.LifecyclePhase) java.util(java.util) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IdUtilities.getIdOrDefault(org.finos.waltz.model.utils.IdUtilities.getIdOrDefault) EntityKind(org.finos.waltz.model.EntityKind) ReportGridService(org.finos.waltz.service.report_grid.ReportGridService) org.finos.waltz.model.report_grid(org.finos.waltz.model.report_grid) SurveyQuestionService(org.finos.waltz.service.survey.SurveyQuestionService) Autowired(org.springframework.beans.factory.annotation.Autowired) Spark.post(spark.Spark.post) CollectionUtilities(org.finos.waltz.common.CollectionUtilities) CsvPreference(org.supercsv.prefs.CsvPreference) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Tuple2(org.jooq.lambda.tuple.Tuple2) Tuple3(org.jooq.lambda.tuple.Tuple3) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(org.springframework.stereotype.Service) CsvListWriter(org.supercsv.io.CsvListWriter) Cell(org.apache.poi.ss.usermodel.Cell) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet) IdUtilities.indexById(org.finos.waltz.model.utils.IdUtilities.indexById) Collectors.toSet(java.util.stream.Collectors.toSet) StringUtilities(org.finos.waltz.common.StringUtilities) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) SurveyQuestion(org.finos.waltz.model.survey.SurveyQuestion) MapUtilities(org.finos.waltz.common.MapUtilities) Application(org.finos.waltz.model.application.Application) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) NameProvider(org.finos.waltz.model.NameProvider) SettingsService(org.finos.waltz.service.settings.SettingsService) Collectors.toList(java.util.stream.Collectors.toList) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) Stream(java.util.stream.Stream) CheckedConsumer.unchecked(org.jooq.lambda.fi.util.function.CheckedConsumer.unchecked) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) ListUtilities(org.finos.waltz.common.ListUtilities) WebUtilities(org.finos.waltz.web.WebUtilities) Row(org.apache.poi.ss.usermodel.Row) EntityReference(org.finos.waltz.model.EntityReference) IdUtilities(org.finos.waltz.model.utils.IdUtilities) EntityFieldReference(org.finos.waltz.model.entity_field_reference.EntityFieldReference) StringWriter(java.io.StringWriter) CsvListWriter(org.supercsv.io.CsvListWriter)

Example 18 with Application

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

Example 19 with Application

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;
}
Also used : CostRecord(org.finos.waltz.schema.tables.records.CostRecord) DSLContext(org.jooq.DSLContext) Application(org.finos.waltz.model.application.Application) ApplicationService(org.finos.waltz.service.application.ApplicationService)

Example 20 with Application

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());
}
Also used : OrganisationalUnitDao(org.finos.waltz.data.orgunit.OrganisationalUnitDao) java.util(java.util) LogicalFlowDao(org.finos.waltz.data.logical_flow.LogicalFlowDao) DSL(org.jooq.impl.DSL) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) DIConfiguration(org.finos.waltz.service.DIConfiguration) ListUtilities.newArrayList(org.finos.waltz.common.ListUtilities.newArrayList) CsvPreference(org.supercsv.prefs.CsvPreference) Function(java.util.function.Function) Condition(org.jooq.Condition) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) DataType(org.finos.waltz.model.datatype.DataType) LOGICAL_FLOW(org.finos.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW) LOGICAL_NOT_REMOVED(org.finos.waltz.data.logical_flow.LogicalFlowDao.LOGICAL_NOT_REMOVED) Record1(org.jooq.Record1) CsvListWriter(org.supercsv.io.CsvListWriter) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) Tuple7(org.jooq.lambda.tuple.Tuple7) DSLContext(org.jooq.DSLContext) OutputStreamWriter(java.io.OutputStreamWriter) ApplicationIdSelectorFactory(org.finos.waltz.data.application.ApplicationIdSelectorFactory) Select(org.jooq.Select) StringUtilities(org.finos.waltz.common.StringUtilities) EntityLifecycleStatus(org.finos.waltz.model.EntityLifecycleStatus) OrganisationalUnit(org.finos.waltz.model.orgunit.OrganisationalUnit) Unchecked(org.jooq.lambda.Unchecked) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Application(org.finos.waltz.model.application.Application) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) Collections.emptyList(java.util.Collections.emptyList) IdUtilities.toIds(org.finos.waltz.model.utils.IdUtilities.toIds) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) NameProvider(org.finos.waltz.model.NameProvider) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) LogicalFlowDecoratorDao(org.finos.waltz.data.datatype_decorator.LogicalFlowDecoratorDao) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) Tuple(org.jooq.lambda.tuple.Tuple) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) EntityReference(org.finos.waltz.model.EntityReference) DataTypeDao(org.finos.waltz.data.data_type.DataTypeDao) IdUtilities.indexByOptId(org.finos.waltz.model.utils.IdUtilities.indexByOptId) SetUtilities.fromCollection(org.finos.waltz.common.SetUtilities.fromCollection) EntityReference(org.finos.waltz.model.EntityReference) Select(org.jooq.Select) Record1(org.jooq.Record1)

Aggregations

Application (org.finos.waltz.model.application.Application)54 DSLContext (org.jooq.DSLContext)24 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)24 EntityKind (org.finos.waltz.model.EntityKind)22 Collectors (java.util.stream.Collectors)20 ApplicationDao (org.finos.waltz.data.application.ApplicationDao)18 EntityReference (org.finos.waltz.model.EntityReference)18 DIConfiguration (org.finos.waltz.service.DIConfiguration)18 ExternalIdValue (org.finos.waltz.model.external_identifier.ExternalIdValue)16 List (java.util.List)14 IOException (java.io.IOException)12 java.util (java.util)12 Map (java.util.Map)12 DataType (org.finos.waltz.model.datatype.DataType)12 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)12 ApplicationService (org.finos.waltz.service.application.ApplicationService)12 Tuple (org.jooq.lambda.tuple.Tuple)12 LogicalFlowDao (org.finos.waltz.data.logical_flow.LogicalFlowDao)10 CsvPreference (org.supercsv.prefs.CsvPreference)10 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)8