Search in sources :

Example 1 with LOGICAL_FLOW

use of org.finos.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW in project waltz by khartec.

the class LogicalFlowDecoratorDao method updateDecoratorsForFlowClassificationRule.

public int updateDecoratorsForFlowClassificationRule(FlowClassificationRuleVantagePoint flowClassificationRuleVantagePoint) {
    LogicalFlowDecorator lfd = LOGICAL_FLOW_DECORATOR.as("lfd");
    EntityReference vantagePoint = flowClassificationRuleVantagePoint.vantagePoint();
    Long appId = flowClassificationRuleVantagePoint.applicationId();
    EntityReference dataType = flowClassificationRuleVantagePoint.dataType();
    String classificationCode = flowClassificationRuleVantagePoint.classificationCode();
    SelectConditionStep<Record1<Long>> orgUnitSubselect = DSL.select(ENTITY_HIERARCHY.ID).from(ENTITY_HIERARCHY).where(ENTITY_HIERARCHY.KIND.eq(vantagePoint.kind().name())).and(ENTITY_HIERARCHY.ANCESTOR_ID.eq(vantagePoint.id()));
    SelectConditionStep<Record1<Long>> dataTypeSubselect = DSL.select(ENTITY_HIERARCHY.ID).from(ENTITY_HIERARCHY).where(ENTITY_HIERARCHY.KIND.eq(DATA_TYPE.name())).and(ENTITY_HIERARCHY.ANCESTOR_ID.eq(dataType.id()));
    Condition usingFlowClassificationRule = LOGICAL_FLOW.SOURCE_ENTITY_ID.eq(appId);
    Condition notUsingFlowClassificationRule = LOGICAL_FLOW.SOURCE_ENTITY_ID.ne(appId);
    Function2<Condition, String, Update<LogicalFlowDecoratorRecord>> mkQuery = (appScopingCondition, ratingName) -> dsl.update(LOGICAL_FLOW_DECORATOR).set(LOGICAL_FLOW_DECORATOR.RATING, ratingName).set(LOGICAL_FLOW_DECORATOR.FLOW_CLASSIFICATION_RULE_ID, flowClassificationRuleVantagePoint.ruleId()).where(LOGICAL_FLOW_DECORATOR.ID.in(DSL.select(lfd.ID).from(lfd).innerJoin(LOGICAL_FLOW).on(LOGICAL_FLOW.ID.eq(lfd.LOGICAL_FLOW_ID)).innerJoin(APPLICATION).on(APPLICATION.ID.eq(LOGICAL_FLOW.TARGET_ENTITY_ID).and(LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name()))).where(LOGICAL_FLOW.SOURCE_ENTITY_KIND.eq(EntityKind.APPLICATION.name()).and(appScopingCondition).and(APPLICATION.ORGANISATIONAL_UNIT_ID.in(orgUnitSubselect)).and(lfd.DECORATOR_ENTITY_KIND.eq(DATA_TYPE.name())).and(lfd.DECORATOR_ENTITY_ID.in(dataTypeSubselect))).and(lfd.RATING.in(AuthoritativenessRatingValue.NO_OPINION.value(), AuthoritativenessRatingValue.DISCOURAGED.value()))));
    Update<LogicalFlowDecoratorRecord> updateAuthSources = mkQuery.apply(usingFlowClassificationRule, classificationCode);
    Update<LogicalFlowDecoratorRecord> updateNonAuthSources = mkQuery.apply(notUsingFlowClassificationRule, AuthoritativenessRatingValue.DISCOURAGED.value());
    int authSourceUpdateCount = updateAuthSources.execute();
    int nonAuthSourceUpdateCount = updateNonAuthSources.execute();
    return authSourceUpdateCount + nonAuthSourceUpdateCount;
}
Also used : AuthoritativenessRatingValue(org.finos.waltz.model.rating.AuthoritativenessRatingValue) DSL(org.jooq.impl.DSL) APPLICATION(org.finos.waltz.schema.tables.Application.APPLICATION) LogicalFlowDecoratorRecord(org.finos.waltz.schema.tables.records.LogicalFlowDecoratorRecord) EntityKind(org.finos.waltz.model.EntityKind) LOGICAL_DATA_FLOW(org.finos.waltz.model.EntityKind.LOGICAL_DATA_FLOW) Autowired(org.springframework.beans.factory.annotation.Autowired) ListUtilities.newArrayList(org.finos.waltz.common.ListUtilities.newArrayList) Function(java.util.function.Function) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) LOGICAL_FLOW(org.finos.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW) LOGICAL_NOT_REMOVED(org.finos.waltz.data.logical_flow.LogicalFlowDao.LOGICAL_NOT_REMOVED) FlowClassificationRuleVantagePoint(org.finos.waltz.model.flow_classification_rule.FlowClassificationRuleVantagePoint) Function2(org.jooq.lambda.function.Function2) org.jooq(org.jooq) PHYSICAL_FLOW(org.finos.waltz.schema.Tables.PHYSICAL_FLOW) LogicalFlowDecorator(org.finos.waltz.schema.tables.LogicalFlowDecorator) Repository(org.springframework.stereotype.Repository) ENTITY_HIERARCHY(org.finos.waltz.schema.tables.EntityHierarchy.ENTITY_HIERARCHY) EntityLifecycleStatus(org.finos.waltz.model.EntityLifecycleStatus) LOGICAL_FLOW_DECORATOR(org.finos.waltz.schema.tables.LogicalFlowDecorator.LOGICAL_FLOW_DECORATOR) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) DataTypeUsageCharacteristics(org.finos.waltz.model.datatype.DataTypeUsageCharacteristics) Set(java.util.Set) ImmutableDataTypeUsageCharacteristics(org.finos.waltz.model.datatype.ImmutableDataTypeUsageCharacteristics) ImmutableDataTypeDecorator(org.finos.waltz.model.datatype.ImmutableDataTypeDecorator) String.format(java.lang.String.format) PHYSICAL_SPEC_DATA_TYPE(org.finos.waltz.schema.tables.PhysicalSpecDataType.PHYSICAL_SPEC_DATA_TYPE) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) InlineSelectFieldFactory(org.finos.waltz.data.InlineSelectFieldFactory) SetUtilities(org.finos.waltz.common.SetUtilities) EntityReference(org.finos.waltz.model.EntityReference) Optional(java.util.Optional) DATA_TYPE(org.finos.waltz.model.EntityKind.DATA_TYPE) LogicalFlowDecoratorRecord(org.finos.waltz.schema.tables.records.LogicalFlowDecoratorRecord) LogicalFlowDecorator(org.finos.waltz.schema.tables.LogicalFlowDecorator) FlowClassificationRuleVantagePoint(org.finos.waltz.model.flow_classification_rule.FlowClassificationRuleVantagePoint) EntityReference(org.finos.waltz.model.EntityReference)

Example 2 with LOGICAL_FLOW

use of org.finos.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW in project waltz by khartec.

the class PhysicalFlowParticipantGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    log("---creating demo records");
    Map<Criticality, Integer> criticalityCompletionProbabilities = newHashMap(Criticality.VERY_HIGH, 80, Criticality.HIGH, 70, Criticality.MEDIUM, 50, Criticality.LOW, 30, Criticality.NONE, 10, Criticality.UNKNOWN, 10);
    Map<Long, List<Long>> serverIdsByAppId = dsl.select(SERVER_USAGE.ENTITY_ID, SERVER_USAGE.SERVER_ID).from(SERVER_USAGE).where(SERVER_USAGE.ENTITY_KIND.eq(EntityKind.APPLICATION.name())).fetch().intoGroups(SERVER_USAGE.ENTITY_ID, SERVER_USAGE.SERVER_ID);
    Collection<Long> allServerIds = SetUtilities.unionAll(serverIdsByAppId.values());
    List<PhysicalFlowParticipantRecord> records = dsl.select(PHYSICAL_FLOW.ID, PHYSICAL_FLOW.CRITICALITY, LOGICAL_FLOW.SOURCE_ENTITY_ID, LOGICAL_FLOW.TARGET_ENTITY_ID).from(PHYSICAL_FLOW).innerJoin(LOGICAL_FLOW).on(LOGICAL_FLOW.ID.eq(PHYSICAL_FLOW.LOGICAL_FLOW_ID)).where(PHYSICAL_FLOW.IS_REMOVED.isFalse()).and(LOGICAL_FLOW.ENTITY_LIFECYCLE_STATUS.ne(EntityLifecycleStatus.REMOVED.name())).fetch().stream().map(r -> tuple(r.get(PHYSICAL_FLOW.ID), Criticality.parse(r.get(PHYSICAL_FLOW.CRITICALITY), x -> Criticality.UNKNOWN), r.get(LOGICAL_FLOW.SOURCE_ENTITY_ID), r.get(LOGICAL_FLOW.TARGET_ENTITY_ID))).filter(// filter based on criticality probability
    t -> criticalityCompletionProbabilities.get(t.v2) > rnd.nextInt(100)).flatMap(t -> // flat map to tuples of (flow_id, source_id/target_id, server_ids, p_kind)
    Stream.of(tuple(t.v1, t.v3, serverIdsByAppId.getOrDefault(t.v3, emptyList()), ParticipationKind.SOURCE), tuple(t.v1, t.v4, serverIdsByAppId.getOrDefault(t.v4, emptyList()), ParticipationKind.TARGET))).filter(// no servers therefore filter
    t -> !t.v3.isEmpty()).filter(// even if we have servers some may not be mapped
    t -> rnd.nextInt(100) < 80).map(t -> t.map3(associatedServerIds -> randomPick(rnd.nextInt(100) < 90 ? // most of the time we'll go with associated servers
    associatedServerIds : // ... but occasionally we'll go with anything to simulate messy data
    allServerIds))).map(t -> {
        PhysicalFlowParticipantRecord r = new PhysicalFlowParticipantRecord();
        r.setPhysicalFlowId(t.v1);
        r.setParticipantEntityId(t.v3);
        r.setParticipantEntityKind(EntityKind.SERVER.name());
        r.setKind(t.v4.name());
        r.setDescription("Test data");
        r.setLastUpdatedAt(nowUtcTimestamp());
        r.setLastUpdatedBy("admin");
        r.setProvenance(SAMPLE_DATA_PROVENANCE);
        return r;
    }).collect(toList());
    log("About to insert %d records", records.size());
    int[] rcs = dsl.batchInsert(records).execute();
    log("Inserted %d records", rcs.length);
    return null;
}
Also used : PHYSICAL_FLOW_PARTICIPANT(org.finos.waltz.schema.tables.PhysicalFlowParticipant.PHYSICAL_FLOW_PARTICIPANT) Criticality(org.finos.waltz.model.Criticality) Collections.emptyList(java.util.Collections.emptyList) EntityKind(org.finos.waltz.model.EntityKind) Collection(java.util.Collection) Random(java.util.Random) MapUtilities.newHashMap(org.finos.waltz.common.MapUtilities.newHashMap) ApplicationContext(org.springframework.context.ApplicationContext) PHYSICAL_FLOW(org.finos.waltz.schema.tables.PhysicalFlow.PHYSICAL_FLOW) RandomUtilities(org.finos.waltz.common.RandomUtilities) LOGICAL_FLOW(org.finos.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) DateTimeUtilities.nowUtcTimestamp(org.finos.waltz.common.DateTimeUtilities.nowUtcTimestamp) SERVER_USAGE(org.finos.waltz.schema.tables.ServerUsage.SERVER_USAGE) Stream(java.util.stream.Stream) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) Map(java.util.Map) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) SetUtilities(org.finos.waltz.common.SetUtilities) DSLContext(org.jooq.DSLContext) PhysicalFlowParticipantRecord(org.finos.waltz.schema.tables.records.PhysicalFlowParticipantRecord) ParticipationKind(org.finos.waltz.model.physical_flow_participant.ParticipationKind) EntityLifecycleStatus(org.finos.waltz.model.EntityLifecycleStatus) PhysicalFlowParticipantRecord(org.finos.waltz.schema.tables.records.PhysicalFlowParticipantRecord) DSLContext(org.jooq.DSLContext) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Criticality(org.finos.waltz.model.Criticality)

Example 3 with LOGICAL_FLOW

use of org.finos.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW in project waltz by khartec.

the class FlowLineageHarness method findIncomingByRefs.

private static void findIncomingByRefs(DSLContext dsl, Set<EntityReference> entityReferences) {
    Map<EntityKind, Collection<EntityReference>> refsByKind = groupBy(ref -> ref.kind(), entityReferences);
    Condition anyTargetMatches = refsByKind.entrySet().stream().map(entry -> LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(entry.getKey().name()).and(LOGICAL_FLOW.TARGET_ENTITY_ID.in(map(entry.getValue(), ref -> ref.id())))).collect(Collectors.reducing(DSL.falseCondition(), (acc, c) -> acc.or(c)));
    System.out.println(anyTargetMatches);
    Field<String> SOURCE_NAME_FIELD = InlineSelectFieldFactory.mkNameField(LOGICAL_FLOW.SOURCE_ENTITY_ID, LOGICAL_FLOW.SOURCE_ENTITY_KIND, newArrayList(EntityKind.APPLICATION, EntityKind.ACTOR));
    dsl.select(LOGICAL_FLOW.fields()).select(SOURCE_NAME_FIELD).from(LOGICAL_FLOW).where(anyTargetMatches.and(LogicalFlowDao.LOGICAL_NOT_REMOVED)).forEach(System.out::println);
    dsl.select().from(LOGICAL_FLOW_DECORATOR).innerJoin(LOGICAL_FLOW).on(LOGICAL_FLOW.ID.eq(LOGICAL_FLOW_DECORATOR.LOGICAL_FLOW_ID)).where(anyTargetMatches).forEach(System.out::println);
}
Also used : Condition(org.jooq.Condition) ACTOR(org.finos.waltz.model.EntityKind.ACTOR) LOGICAL_FLOW_DECORATOR(org.finos.waltz.schema.tables.LogicalFlowDecorator.LOGICAL_FLOW_DECORATOR) LogicalFlowDao(org.finos.waltz.data.logical_flow.LogicalFlowDao) DSL(org.jooq.impl.DSL) EntityKind(org.finos.waltz.model.EntityKind) ParseException(org.jooq.tools.json.ParseException) Collection(java.util.Collection) Set(java.util.Set) DIConfiguration(org.finos.waltz.service.DIConfiguration) Field(org.jooq.Field) CollectionUtilities.map(org.finos.waltz.common.CollectionUtilities.map) ListUtilities.newArrayList(org.finos.waltz.common.ListUtilities.newArrayList) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) LOGICAL_FLOW(org.finos.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW) InlineSelectFieldFactory(org.finos.waltz.data.InlineSelectFieldFactory) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) Map(java.util.Map) SetUtilities(org.finos.waltz.common.SetUtilities) EntityReference(org.finos.waltz.model.EntityReference) DSLContext(org.jooq.DSLContext) APPLICATION(org.finos.waltz.model.EntityKind.APPLICATION) Collection(java.util.Collection) EntityKind(org.finos.waltz.model.EntityKind)

Aggregations

Collection (java.util.Collection)3 SetUtilities (org.finos.waltz.common.SetUtilities)3 EntityKind (org.finos.waltz.model.EntityKind)3 LOGICAL_FLOW (org.finos.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW)3 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors.toList (java.util.stream.Collectors.toList)2 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)2 InlineSelectFieldFactory (org.finos.waltz.data.InlineSelectFieldFactory)2 EntityLifecycleStatus (org.finos.waltz.model.EntityLifecycleStatus)2 EntityReference (org.finos.waltz.model.EntityReference)2 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)2 LOGICAL_FLOW_DECORATOR (org.finos.waltz.schema.tables.LogicalFlowDecorator.LOGICAL_FLOW_DECORATOR)2 DSLContext (org.jooq.DSLContext)2 DSL (org.jooq.impl.DSL)2 String.format (java.lang.String.format)1 Timestamp (java.sql.Timestamp)1 Collections.emptyList (java.util.Collections.emptyList)1 Optional (java.util.Optional)1