Search in sources :

Example 31 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.

the class DataTypeDecoratorService method mkDecorators.

private Collection<DataTypeDecorator> mkDecorators(String userName, EntityReference entityReference, Set<Long> dataTypeIds) {
    if (LOGICAL_DATA_FLOW.equals(entityReference.kind())) {
        Collection<DataTypeDecorator> decorators = map(dataTypeIds, dtId -> mkDecorator(userName, entityReference, dtId, Optional.of(AuthoritativenessRatingValue.NO_OPINION)));
        LogicalFlow flow = logicalFlowDao.getByFlowId(entityReference.id());
        boolean requiresRating = flow.source().kind() == APPLICATION && flow.target().kind() == APPLICATION;
        return requiresRating ? ratingsCalculator.calculate(decorators) : decorators;
    }
    return map(dataTypeIds, dtId -> mkDecorator(userName, entityReference, dtId, Optional.empty()));
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) ImmutableDataTypeDecorator(org.finos.waltz.model.datatype.ImmutableDataTypeDecorator)

Example 32 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.

the class FlowDiagramService method makeForPhysicalFlow.

private Long makeForPhysicalFlow(EntityReference ref, String userId, String providedTitle) {
    PhysicalFlow physFlow = physicalFlowDao.getById(ref.id());
    LogicalFlow logicalFlow = logicalFlowDao.getByFlowId(physFlow.logicalFlowId());
    PhysicalSpecification spec = physicalSpecificationDao.getById(physFlow.specificationId());
    String title = isEmpty(providedTitle) ? spec.name() + " flows" : providedTitle;
    ArrayList<FlowDiagramEntity> entities = newArrayList(mkDiagramEntity(logicalFlow), mkDiagramEntity(physFlow), mkDiagramEntity(spec), mkDiagramEntity(logicalFlow.source()), mkDiagramEntity(logicalFlow.target()));
    return mkNewFlowDiagram(title, userId, entities, emptyList());
}
Also used : PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow)

Example 33 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.

the class DiagramToDotExport method main.

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    FlowDiagramService flowDiagramService = ctx.getBean(FlowDiagramService.class);
    FlowDiagramEntityService flowDiagramEntityService = ctx.getBean(FlowDiagramEntityService.class);
    ApplicationService applicationService = ctx.getBean(ApplicationService.class);
    LogicalFlowService logicalFlowService = ctx.getBean(LogicalFlowService.class);
    EntityReference diagRef = mkRef(EntityKind.FLOW_DIAGRAM, 1L);
    IdSelectionOptions options = IdSelectionOptions.mkOpts(diagRef, HierarchyQueryScope.EXACT);
    List<Application> apps = applicationService.findByAppIdSelector(options);
    List<LogicalFlow> flows = logicalFlowService.findBySelector(options);
    Map<Long, Application> appsById = indexBy(a -> a.id().get(), apps);
    System.out.println("------");
    String digraph = String.format("digraph G { %s %s}", renderApplications(apps), renderFlows(flows, appsById));
    System.out.println(digraph);
    System.out.println("-----");
/*
        digraph G {
            "Welcome" -> "To"
            "To" -> "Web"
            "To" -> "GraphViz!"
        }
        */
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) LogicalFlowService(org.finos.waltz.service.logical_flow.LogicalFlowService) FlowDiagramEntityService(org.finos.waltz.service.flow_diagram.FlowDiagramEntityService) FlowDiagramService(org.finos.waltz.service.flow_diagram.FlowDiagramService) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) EntityReference(org.finos.waltz.model.EntityReference) Application(org.finos.waltz.model.application.Application) ApplicationService(org.finos.waltz.service.application.ApplicationService) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Example 34 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.

the class FlowSummaryWithTypesAndPhysicalsExport method main.

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    ApplicationIdSelectorFactory appIdSelectorFactory = new ApplicationIdSelectorFactory();
    ApplicationDao applicationDao = ctx.getBean(ApplicationDao.class);
    OrganisationalUnitDao organisationalUnitDao = ctx.getBean(OrganisationalUnitDao.class);
    LogicalFlowDao logicalFlowDao = ctx.getBean(LogicalFlowDao.class);
    LogicalFlowDecoratorDao decoratorDao = ctx.getBean(LogicalFlowDecoratorDao.class);
    DataTypeDao dataTypeDao = ctx.getBean(DataTypeDao.class);
    Select<Record1<Long>> appSelector = mkAppIdSelector(appIdSelectorFactory);
    Select<Record1<Long>> logicalFlowSelector = mkLogicalFlowSelectorFromAppSelector(appSelector);
    System.out.println("Loading apps");
    Set<Application> allApps = fromCollection(applicationDao.findAll());
    System.out.println("Loading in scope apps");
    Set<Long> inScopeAppIds = toIds(applicationDao.findByAppIdSelector(appSelector));
    System.out.println("Loading OUs");
    List<OrganisationalUnit> allOUs = organisationalUnitDao.findAll();
    System.out.println("Loading DTs");
    List<DataType> allDataTypes = dataTypeDao.findAll();
    System.out.println("Loading Logical Flows");
    List<LogicalFlow> logicalFlows = logicalFlowDao.findBySelector(logicalFlowSelector);
    System.out.println("Loading decorators");
    List<DataTypeDecorator> decorators = decoratorDao.findByAppIdSelector(appSelector);
    System.out.println("Loading phys flows");
    Map<Long, Collection<Tuple7<Long, String, String, String, String, String, String>>> physicalsByLogical = loadPhysicalsByLogical(dsl, logicalFlowSelector);
    System.out.println("Indexing");
    Map<Optional<Long>, Application> appsById = indexByOptId(allApps);
    Map<Optional<Long>, DataType> dataTypesById = indexByOptId(allDataTypes);
    Map<Optional<Long>, OrganisationalUnit> ousById = indexByOptId(allOUs);
    Map<Long, Collection<DataTypeDecorator>> decoratorsByLogicalFlowId = groupBy(DataTypeDecorator::dataFlowId, decorators);
    System.out.println("Processing");
    CsvListWriter csvWriter = setupCSVWriter();
    logicalFlows.stream().filter(lf -> lf.source().kind() == EntityKind.APPLICATION && lf.target().kind() == EntityKind.APPLICATION).map(Tuple::tuple).map(t -> t.concat(appsById.get(Optional.of(t.v1.source().id())))).map(t -> t.concat(appsById.get(Optional.of(t.v1.target().id())))).filter(t -> t.v2 != null && t.v3 != null).map(t -> t.concat(ousById.get(Optional.of(t.v2.organisationalUnitId())))).map(t -> t.concat(ousById.get(Optional.of(t.v3.organisationalUnitId())))).map(t -> t.concat(decoratorsByLogicalFlowId.getOrDefault(t.v1.id().orElse(-1L), emptyList()).stream().filter(d -> d.decoratorEntity().kind() == EntityKind.DATA_TYPE).map(d -> dataTypesById.get(Optional.of(d.decoratorEntity().id()))).sorted(Comparator.comparing(NameProvider::name)).collect(Collectors.toList()))).map(t -> t.concat(inScopeAppIds.contains(t.v2.id().get()))).map(t -> t.concat(inScopeAppIds.contains(t.v3.id().get()))).flatMap(t -> physicalsByLogical.getOrDefault(t.v1.id().orElse(-1L), newArrayList(tuple(-1L, "-", "-", "-", "-", "-", "-"))).stream().map(p -> t.concat(p.skip1()))).map(t -> newArrayList(// src
    t.v2.name(), t.v2.assetCode().map(ExternalIdValue::value).orElse(""), t.v2.applicationKind().name(), t.v2.entityLifecycleStatus().name(), // src OU
    Optional.ofNullable(t.v4).map(NameProvider::name).orElse("?"), t.v7.toString(), // trg
    t.v3.name(), t.v3.assetCode().map(ExternalIdValue::value).orElse(""), t.v3.applicationKind().name(), t.v3.entityLifecycleStatus().name(), // trg OU
    Optional.ofNullable(t.v5).map(NameProvider::name).orElse("?"), t.v8.toString(), StringUtilities.joinUsing(t.v6, NameProvider::name, ","), t.v9, t.v10, t.v11, t.v12, t.v13, t.v14)).forEach(Unchecked.consumer(csvWriter::write));
}
Also used : OrganisationalUnitDao(org.finos.waltz.data.orgunit.OrganisationalUnitDao) 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) DataTypeDao(org.finos.waltz.data.data_type.DataTypeDao) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) OrganisationalUnit(org.finos.waltz.model.orgunit.OrganisationalUnit) LogicalFlowDao(org.finos.waltz.data.logical_flow.LogicalFlowDao) LogicalFlowDecoratorDao(org.finos.waltz.data.datatype_decorator.LogicalFlowDecoratorDao) DataType(org.finos.waltz.model.datatype.DataType) Record1(org.jooq.Record1) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) ApplicationIdSelectorFactory(org.finos.waltz.data.application.ApplicationIdSelectorFactory) NameProvider(org.finos.waltz.model.NameProvider) SetUtilities.fromCollection(org.finos.waltz.common.SetUtilities.fromCollection) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) Application(org.finos.waltz.model.application.Application) CsvListWriter(org.supercsv.io.CsvListWriter)

Example 35 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.

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)

Aggregations

LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)72 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)52 Test (org.junit.jupiter.api.Test)52 EntityReference (org.finos.waltz.model.EntityReference)40 PhysicalSpecification (org.finos.waltz.model.physical_specification.PhysicalSpecification)21 ImmutablePhysicalSpecification (org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification)15 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)13 DataTypeDecorator (org.finos.waltz.model.datatype.DataTypeDecorator)13 LogicalFlowService (org.finos.waltz.service.logical_flow.LogicalFlowService)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13 Collections.emptyList (java.util.Collections.emptyList)12 List (java.util.List)12 SetUtilities.map (org.finos.waltz.common.SetUtilities.map)12 Collection (java.util.Collection)11 IdSelectionOptions.mkOpts (org.finos.waltz.model.IdSelectionOptions.mkOpts)11 Collections.emptySet (java.util.Collections.emptySet)10 SetUtilities.asSet (org.finos.waltz.common.SetUtilities.asSet)10 Assertions (org.junit.jupiter.api.Assertions)10 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)9 org.finos.waltz.integration_test.inmem.helpers (org.finos.waltz.integration_test.inmem.helpers)9