Search in sources :

Example 41 with Application

use of org.finos.waltz.model.application.Application in project waltz by finos.

the class ShortestPath method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    LogicalFlowDao logicalFlowDao = ctx.getBean(LogicalFlowDao.class);
    ApplicationDao applicationDao = ctx.getBean(ApplicationDao.class);
    List<LogicalFlow> allActive = logicalFlowDao.findAllActive();
    Graph<EntityReference, DefaultEdge> g = createGraph(allActive);
    Application targetApp = findFirstMatchByCode(applicationDao, targetAssetCode);
    Stream.of(sourceAssetCodes).map(assetCode -> findFirstMatchByCode(applicationDao, assetCode)).filter(Objects::nonNull).map(sourceApp -> {
        System.out.printf("Route from: %s (%s)\n----------------------\n", sourceApp.name(), ExternalIdValue.orElse(sourceApp.assetCode(), ""));
        return sourceApp.entityReference();
    }).filter(sourceRef -> {
        if (!g.containsVertex(sourceRef)) {
            System.out.println("No flows defined for application\n\n");
            return false;
        }
        return true;
    }).map(sourceRef -> findShortestPath(g, sourceRef, targetApp.entityReference())).filter(route -> {
        if (route == null) {
            System.out.println("No route found\n\n");
            return false;
        }
        return true;
    }).forEach(route -> {
        List<DefaultEdge> edgeList = route.getEdgeList();
        Set<Long> appIds = edgeList.stream().flatMap(e -> Stream.of(g.getEdgeSource(e).id(), g.getEdgeTarget(e).id())).collect(toSet());
        Map<Long, Application> appsById = MapUtilities.indexBy(a -> a.id().get(), applicationDao.findByIds(appIds));
        edgeList.forEach(edge -> {
            Application source = appsById.get(g.getEdgeSource(edge).id());
            Application target = appsById.get(g.getEdgeTarget(edge).id());
            System.out.printf("%s (%s) -> %s (%s) \n", source.name(), ExternalIdValue.orElse(source.assetCode(), ""), target.name(), ExternalIdValue.orElse(target.assetCode(), ""));
        });
        System.out.println();
        System.out.println();
    });
}
Also used : MapUtilities(org.finos.waltz.common.MapUtilities) LogicalFlowDao(org.finos.waltz.data.logical_flow.LogicalFlowDao) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DefaultDirectedGraph(org.jgrapht.graph.DefaultDirectedGraph) DefaultEdge(org.jgrapht.graph.DefaultEdge) Application(org.finos.waltz.model.application.Application) Set(java.util.Set) DIConfiguration(org.finos.waltz.service.DIConfiguration) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DijkstraShortestPath(org.jgrapht.alg.shortestpath.DijkstraShortestPath) Objects(java.util.Objects) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) GraphPath(org.jgrapht.GraphPath) List(java.util.List) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) Stream(java.util.stream.Stream) SingleSourcePaths(org.jgrapht.alg.interfaces.ShortestPathAlgorithm.SingleSourcePaths) Map(java.util.Map) Graph(org.jgrapht.Graph) EntityReference(org.finos.waltz.model.EntityReference) Collectors.toSet(java.util.stream.Collectors.toSet) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DefaultEdge(org.jgrapht.graph.DefaultEdge) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) LogicalFlowDao(org.finos.waltz.data.logical_flow.LogicalFlowDao) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) EntityReference(org.finos.waltz.model.EntityReference) Application(org.finos.waltz.model.application.Application)

Example 42 with Application

use of org.finos.waltz.model.application.Application in project waltz by finos.

the class ApplicationService method findRelated.

public Map<AssetCodeRelationshipKind, List<Application>> findRelated(long appId) {
    List<Application> related = applicationDao.findRelatedByApplicationId(appId);
    Optional<Application> foundApp = related.stream().filter(app -> app.id().equals(Optional.of(appId))).findFirst();
    if (foundApp.isPresent()) {
        Application app = foundApp.get();
        Function<Application, AssetCodeRelationshipKind> classifier = relatedApp -> {
            boolean sameParent = relatedApp.parentAssetCode().equals(app.parentAssetCode());
            boolean sameCode = relatedApp.assetCode().equals(app.assetCode());
            boolean isParent = relatedApp.assetCode().equals(app.parentAssetCode());
            boolean isChild = relatedApp.parentAssetCode().equals(app.assetCode());
            if (sameCode) {
                return AssetCodeRelationshipKind.SHARING;
            } else if (isParent) {
                return AssetCodeRelationshipKind.PARENT;
            } else if (isChild) {
                return AssetCodeRelationshipKind.CHILD;
            } else if (sameParent && app.parentAssetCode().isPresent()) {
                return AssetCodeRelationshipKind.SIBLING;
            } else {
                return AssetCodeRelationshipKind.NONE;
            }
        };
        return related.stream().filter(// can do simple ref check here
        relatedApp -> relatedApp != app).collect(Collectors.groupingBy(classifier));
    } else {
        return emptyMap();
    }
}
Also used : IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) EntityKind(org.finos.waltz.model.EntityKind) ImmutableEntityReference(org.finos.waltz.model.ImmutableEntityReference) AssetCodeRelationshipKind(org.finos.waltz.model.application.AssetCodeRelationshipKind) Tally(org.finos.waltz.model.tally.Tally) Autowired(org.springframework.beans.factory.annotation.Autowired) Function(java.util.function.Function) EntitySearchOptions(org.finos.waltz.model.entity_search.EntitySearchOptions) StringUtilities.isEmpty(org.finos.waltz.common.StringUtilities.isEmpty) Record1(org.jooq.Record1) Service(org.springframework.stereotype.Service) Map(java.util.Map) EntityAliasDao(org.finos.waltz.data.entity_alias.EntityAliasDao) ApplicationIdSelectorFactory(org.finos.waltz.data.application.ApplicationIdSelectorFactory) Select(org.jooq.Select) Collections.emptyMap(java.util.Collections.emptyMap) Checks.checkNotEmpty(org.finos.waltz.common.Checks.checkNotEmpty) AppRegistrationResponse(org.finos.waltz.model.application.AppRegistrationResponse) Application(org.finos.waltz.model.application.Application) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) TagService(org.finos.waltz.service.tag.TagService) ApplicationSearchDao(org.finos.waltz.data.application.search.ApplicationSearchDao) Collectors(java.util.stream.Collectors) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) EntityReference(org.finos.waltz.model.EntityReference) Optional(java.util.Optional) AppRegistrationRequest(org.finos.waltz.model.application.AppRegistrationRequest) AssetCodeRelationshipKind(org.finos.waltz.model.application.AssetCodeRelationshipKind) Application(org.finos.waltz.model.application.Application)

Example 43 with Application

use of org.finos.waltz.model.application.Application in project waltz by finos.

the class ScenarioRatingImporter method mkScenarioRatingRecords.

private List<ScenarioRatingItemRecord> mkScenarioRatingRecords(List<Measurable> measurables, Map<String, RatingSchemeItem> ratingsByName, List<ScenarioRatingRow> rows, Scenario scenario) {
    Collection<ScenarioAxisItem> scenarioAxes = scenarioAxisItemDao.findForScenarioId(scenario.id().get());
    Map<Long, Measurable> measurablesById = indexBy(m -> m.id().get(), measurables);
    Map<String, ScenarioAxisItem> scenarioAxesByName = scenarioAxes.stream().map(sa -> Tuple.tuple(lower(measurablesById.get(sa.domainItem().id()).name()), sa)).collect(toMap(t -> t.v1(), t -> t.v2()));
    return rows.stream().map(r -> {
        ScenarioAxisItem columnAxis = scenarioAxesByName.get(lower(r.column()));
        checkNotNull(columnAxis, "columnAxis cannot be null");
        checkTrue(columnAxis.axisOrientation().equals(AxisOrientation.COLUMN), "column does not match a oolumn axis");
        ScenarioAxisItem rowAxis = scenarioAxesByName.get(lower(r.row()));
        checkNotNull(rowAxis, "rowAxis cannot be null");
        checkTrue(rowAxis.axisOrientation().equals(AxisOrientation.ROW), "row does not match a row axis");
        Application app = assetCodeToApplicationMap.get(r.assetCode());
        checkNotNull(app, String.format("Application with asset code[%s] cannot be null", r.assetCode()));
        RatingSchemeItem rating = ratingsByName.get(lower(r.rating()));
        checkNotNull(rating, String.format("rating [%s] cannot be null", r.rating()));
        ScenarioRatingItemRecord record = new ScenarioRatingItemRecord();
        record.setScenarioId(scenario.id().get());
        record.setRating(rating.rating().toString());
        record.setDomainItemKind(EntityKind.APPLICATION.name());
        record.setDomainItemId(app.id().get());
        record.setRowKind(rowAxis.domainItem().kind().name());
        record.setRowId(rowAxis.domainItem().id());
        record.setColumnKind(columnAxis.domainItem().kind().name());
        record.setColumnId(columnAxis.domainItem().id());
        record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
        record.setLastUpdatedBy(r.providedBy());
        record.setDescription(r.description());
        return record;
    }).collect(toList());
}
Also used : ICsvMapReader(org.supercsv.io.ICsvMapReader) ScenarioAxisItemDao(org.finos.waltz.data.scenario.ScenarioAxisItemDao) APPLICATION(org.finos.waltz.schema.tables.Application.APPLICATION) EntityKind(org.finos.waltz.model.EntityKind) RatingScheme(org.finos.waltz.model.rating.RatingScheme) DIConfiguration(org.finos.waltz.service.DIConfiguration) StringUtilities.lower(org.finos.waltz.common.StringUtilities.lower) CsvPreference(org.supercsv.prefs.CsvPreference) Scenario(org.finos.waltz.model.scenario.Scenario) ArrayList(java.util.ArrayList) Checks.checkTrue(org.finos.waltz.common.Checks.checkTrue) Measurable(org.finos.waltz.model.measurable.Measurable) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) SCENARIO_RATING_ITEM(org.finos.waltz.schema.tables.ScenarioRatingItem.SCENARIO_RATING_ITEM) Map(java.util.Map) DSLContext(org.jooq.DSLContext) Application(org.finos.waltz.model.application.Application) MeasurableDao(org.finos.waltz.data.measurable.MeasurableDao) ScenarioDao(org.finos.waltz.data.scenario.ScenarioDao) Collection(java.util.Collection) IOException(java.io.IOException) AxisOrientation(org.finos.waltz.model.AxisOrientation) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MapUtilities.indexBy(org.finos.waltz.common.MapUtilities.indexBy) ScenarioRatingItemRecord(org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord) CsvMapReader(org.supercsv.io.CsvMapReader) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) ScenarioAxisItem(org.finos.waltz.model.scenario.ScenarioAxisItem) Tuple(org.jooq.lambda.tuple.Tuple) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) RatingSchemeDAO(org.finos.waltz.data.rating_scheme.RatingSchemeDAO) RoadmapDao(org.finos.waltz.data.roadmap.RoadmapDao) Roadmap(org.finos.waltz.model.roadmap.Roadmap) Measurable(org.finos.waltz.model.measurable.Measurable) ScenarioAxisItem(org.finos.waltz.model.scenario.ScenarioAxisItem) ScenarioRatingItemRecord(org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord) Application(org.finos.waltz.model.application.Application) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem)

Example 44 with Application

use of org.finos.waltz.model.application.Application in project waltz by finos.

the class ScenarioRatingImporter method importScenarioRatings.

public void importScenarioRatings(String filename) throws IOException {
    List<Application> allApps = dsl.select().from(APPLICATION).fetch(ApplicationDao.TO_DOMAIN_MAPPER);
    assetCodeToApplicationMap = indexBy(a -> ExternalIdValue.orElse(a.assetCode(), null), allApps);
    List<ScenarioRatingRow> ratingRows = parseData(filename);
    Map<String, Map<String, List<ScenarioRatingRow>>> rowsGroupedByRoadmapByScenario = ratingRows.stream().collect(groupingBy(ScenarioRatingRow::roadmap, groupingBy(ScenarioRatingRow::scenario)));
    // get roadmap id
    Map<String, Roadmap> roadmapNameToIdMap = getNameToRoadmapMap(roadmapDao);
    List<Measurable> measurables = measurableDao.findAll();
    rowsGroupedByRoadmapByScenario.forEach((String roadmapName, Map<String, List<ScenarioRatingRow>> scenarioAndRows) -> {
        // get roadmap
        Roadmap roadmap = roadmapNameToIdMap.get(lower(roadmapName));
        checkNotNull(roadmap, "roadmap [" + roadmapName + "] cannot be null");
        // get rating scheme
        RatingScheme ratingScheme = ratingSchemeDao.getById(roadmap.ratingSchemeId());
        checkNotNull(ratingScheme, "ratingScheme cannot be null");
        Map<String, RatingSchemeItem> ratingsByName = indexBy(r -> lower(r.name()), ratingScheme.ratings());
        // index available scenarios
        Map<String, Scenario> scenariosByName = indexBy(s -> lower(s.name()), scenarioDao.findForRoadmapId(roadmap.id().get()));
        scenarioAndRows.forEach((scenarioName, rows) -> updateRatingsForScenario(measurables, roadmap, ratingsByName, rows, scenariosByName, scenarioName));
    });
}
Also used : ICsvMapReader(org.supercsv.io.ICsvMapReader) ScenarioAxisItemDao(org.finos.waltz.data.scenario.ScenarioAxisItemDao) APPLICATION(org.finos.waltz.schema.tables.Application.APPLICATION) EntityKind(org.finos.waltz.model.EntityKind) RatingScheme(org.finos.waltz.model.rating.RatingScheme) DIConfiguration(org.finos.waltz.service.DIConfiguration) StringUtilities.lower(org.finos.waltz.common.StringUtilities.lower) CsvPreference(org.supercsv.prefs.CsvPreference) Scenario(org.finos.waltz.model.scenario.Scenario) ArrayList(java.util.ArrayList) Checks.checkTrue(org.finos.waltz.common.Checks.checkTrue) Measurable(org.finos.waltz.model.measurable.Measurable) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) SCENARIO_RATING_ITEM(org.finos.waltz.schema.tables.ScenarioRatingItem.SCENARIO_RATING_ITEM) Map(java.util.Map) DSLContext(org.jooq.DSLContext) Application(org.finos.waltz.model.application.Application) MeasurableDao(org.finos.waltz.data.measurable.MeasurableDao) ScenarioDao(org.finos.waltz.data.scenario.ScenarioDao) Collection(java.util.Collection) IOException(java.io.IOException) AxisOrientation(org.finos.waltz.model.AxisOrientation) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MapUtilities.indexBy(org.finos.waltz.common.MapUtilities.indexBy) ScenarioRatingItemRecord(org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord) CsvMapReader(org.supercsv.io.CsvMapReader) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) ScenarioAxisItem(org.finos.waltz.model.scenario.ScenarioAxisItem) Tuple(org.jooq.lambda.tuple.Tuple) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) RatingSchemeDAO(org.finos.waltz.data.rating_scheme.RatingSchemeDAO) RoadmapDao(org.finos.waltz.data.roadmap.RoadmapDao) Roadmap(org.finos.waltz.model.roadmap.Roadmap) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) Scenario(org.finos.waltz.model.scenario.Scenario) Measurable(org.finos.waltz.model.measurable.Measurable) Roadmap(org.finos.waltz.model.roadmap.Roadmap) RatingScheme(org.finos.waltz.model.rating.RatingScheme) Application(org.finos.waltz.model.application.Application) Map(java.util.Map)

Example 45 with Application

use of org.finos.waltz.model.application.Application in project waltz by khartec.

the class LogicalFlowDecoratorRatingsCalculator method calculate.

public Collection<DataTypeDecorator> calculate(Collection<DataTypeDecorator> decorators) {
    List<LogicalFlow> appToAppFlows = filter(IS_APP_TO_APP_FLOW, loadFlows(decorators));
    if (isEmpty(appToAppFlows))
        return Collections.emptyList();
    List<Application> targetApps = loadTargetApplications(appToAppFlows);
    List<DataType> dataTypes = dataTypeDao.findAll();
    Set<FlowClassification> flowClassifications = flowClassificationDao.findAll();
    Map<Long, DataType> typesById = indexById(dataTypes);
    Map<Long, LogicalFlow> flowsById = indexById(appToAppFlows);
    Map<Long, Application> targetAppsById = indexById(targetApps);
    FlowClassificationRuleResolver resolver = createResolver(targetApps);
    return decorators.stream().filter(d -> flowsById.containsKey(d.dataFlowId())).map(decorator -> {
        try {
            if (decorator.decoratorEntity().kind() != EntityKind.DATA_TYPE) {
                return decorator;
            } else {
                AuthoritativenessRatingValue rating = lookupRating(flowsById, targetAppsById, resolver, decorator);
                Optional<Long> ruleId = lookupFlowClassificationRule(typesById, flowsById, targetAppsById, resolver, decorator);
                return ImmutableDataTypeDecorator.copyOf(decorator).withRating(rating).withFlowClassificationRuleId(ruleId);
            }
        } catch (Exception e) {
            LOG.warn("Failed to calculate rating for decorator: {}, reason: {}", decorator, e.getMessage());
            return null;
        }
    }).filter(Objects::nonNull).collect(Collectors.toSet());
}
Also used : AuthoritativenessRatingValue(org.finos.waltz.model.rating.AuthoritativenessRatingValue) java.util(java.util) LogicalFlowDao(org.finos.waltz.data.logical_flow.LogicalFlowDao) FlowClassification(org.finos.waltz.model.flow_classification.FlowClassification) ApplicationService(org.finos.waltz.service.application.ApplicationService) EntityKind(org.finos.waltz.model.EntityKind) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FlowClassificationDao(org.finos.waltz.data.flow_classification_rule.FlowClassificationDao) DataType(org.finos.waltz.model.datatype.DataType) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) FlowClassificationRuleVantagePoint(org.finos.waltz.model.flow_classification_rule.FlowClassificationRuleVantagePoint) FlowClassificationRuleDao(org.finos.waltz.data.flow_classification_rule.FlowClassificationRuleDao) Service(org.springframework.stereotype.Service) IdUtilities.indexById(org.finos.waltz.model.utils.IdUtilities.indexById) Logger(org.slf4j.Logger) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Application(org.finos.waltz.model.application.Application) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) Predicate(java.util.function.Predicate) ListUtilities.isEmpty(org.finos.waltz.common.ListUtilities.isEmpty) ImmutableDataTypeDecorator(org.finos.waltz.model.datatype.ImmutableDataTypeDecorator) Collectors(java.util.stream.Collectors) FlowClassificationRuleResolver(org.finos.waltz.service.flow_classification_rule.FlowClassificationRuleResolver) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) ListUtilities.filter(org.finos.waltz.common.ListUtilities.filter) EntityReference(org.finos.waltz.model.EntityReference) DataTypeDao(org.finos.waltz.data.data_type.DataTypeDao) FlowClassification(org.finos.waltz.model.flow_classification.FlowClassification) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) AuthoritativenessRatingValue(org.finos.waltz.model.rating.AuthoritativenessRatingValue) DataType(org.finos.waltz.model.datatype.DataType) Application(org.finos.waltz.model.application.Application) FlowClassificationRuleResolver(org.finos.waltz.service.flow_classification_rule.FlowClassificationRuleResolver)

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