Search in sources :

Example 1 with LOGICAL_FLOW

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

the class PhysicalFlowSearchDao method searchReports.

/**
 * A report is a physical flow which goes to an
 * external actor
 * @param query
 * @return
 */
public List<EntityReference> searchReports(String query) {
    if (isEmpty(query)) {
        return emptyList();
    }
    Field<String> nameField = DSL.concat(PHYSICAL_SPECIFICATION.NAME, DSL.value(" - "), ACTOR.NAME);
    Condition termMatcher = mkTerms(query).stream().reduce(DSL.trueCondition(), (acc, t) -> nameField.like("%" + t + "%"), (acc, t) -> acc.and(t));
    return dsl.select(PHYSICAL_FLOW.ID, nameField).from(PHYSICAL_FLOW).innerJoin(PHYSICAL_SPECIFICATION).on(PHYSICAL_FLOW.SPECIFICATION_ID.eq(PHYSICAL_SPECIFICATION.ID)).innerJoin(LOGICAL_FLOW).on(LOGICAL_FLOW.ID.eq(PHYSICAL_FLOW.LOGICAL_FLOW_ID)).innerJoin(ACTOR).on(LOGICAL_FLOW.TARGET_ENTITY_ID.eq(ACTOR.ID).and(ACTOR.IS_EXTERNAL.eq(true))).where(LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(EntityKind.ACTOR.name())).and(termMatcher).fetch().stream().map(r -> mkRef(EntityKind.PHYSICAL_FLOW, r.value1(), r.value2())).collect(Collectors.toList());
}
Also used : Condition(org.jooq.Condition) PHYSICAL_SPECIFICATION(com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION) DSL(org.jooq.impl.DSL) Checks.checkNotNull(com.khartec.waltz.common.Checks.checkNotNull) Collections.emptyList(java.util.Collections.emptyList) Autowired(org.springframework.beans.factory.annotation.Autowired) EntityReference(com.khartec.waltz.model.EntityReference) Field(org.jooq.Field) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) PHYSICAL_FLOW(com.khartec.waltz.schema.tables.PhysicalFlow.PHYSICAL_FLOW) EntityKind(com.khartec.waltz.model.EntityKind) List(java.util.List) ACTOR(com.khartec.waltz.schema.tables.Actor.ACTOR) DSLContext(org.jooq.DSLContext) StringUtilities.isEmpty(com.khartec.waltz.common.StringUtilities.isEmpty) SearchUtilities.mkTerms(com.khartec.waltz.data.SearchUtilities.mkTerms) Repository(org.springframework.stereotype.Repository) EntityReference.mkRef(com.khartec.waltz.model.EntityReference.mkRef) LOGICAL_FLOW(com.khartec.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW)

Example 2 with LOGICAL_FLOW

use of com.khartec.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 = EntityNameUtilities.mkEntityNameField(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.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) DSL(org.jooq.impl.DSL) SetUtilities(com.khartec.waltz.common.SetUtilities) ACTOR(com.khartec.waltz.model.EntityKind.ACTOR) ParseException(org.jooq.tools.json.ParseException) Collection(java.util.Collection) MapUtilities.groupBy(com.khartec.waltz.common.MapUtilities.groupBy) Set(java.util.Set) EntityReference(com.khartec.waltz.model.EntityReference) Field(org.jooq.Field) ListUtilities.newArrayList(com.khartec.waltz.common.ListUtilities.newArrayList) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityKind(com.khartec.waltz.model.EntityKind) CollectionUtilities.map(com.khartec.waltz.common.CollectionUtilities.map) DIConfiguration(com.khartec.waltz.service.DIConfiguration) LOGICAL_FLOW_DECORATOR(com.khartec.waltz.schema.tables.LogicalFlowDecorator.LOGICAL_FLOW_DECORATOR) EntityNameUtilities(com.khartec.waltz.data.EntityNameUtilities) LogicalFlowDao(com.khartec.waltz.data.logical_flow.LogicalFlowDao) Map(java.util.Map) APPLICATION(com.khartec.waltz.model.EntityKind.APPLICATION) DSLContext(org.jooq.DSLContext) EntityReference.mkRef(com.khartec.waltz.model.EntityReference.mkRef) LOGICAL_FLOW(com.khartec.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW) Collection(java.util.Collection) EntityKind(com.khartec.waltz.model.EntityKind)

Example 3 with LOGICAL_FLOW

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

the class FlowGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    AuthoritativeSourceDao authSourceDao = ctx.getBean(AuthoritativeSourceDao.class);
    ApplicationService applicationDao = ctx.getBean(ApplicationService.class);
    LogicalFlowService dataFlowDao = ctx.getBean(LogicalFlowService.class);
    OrganisationalUnitService orgUnitDao = ctx.getBean(OrganisationalUnitService.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<AuthoritativeSource> authSources = authSourceDao.findByEntityKind(EntityKind.ORG_UNIT);
    List<Application> apps = applicationDao.findAll();
    List<OrganisationalUnit> orgUnits = orgUnitDao.findAll();
    Set<LogicalFlow> expectedFlows = authSources.stream().flatMap(a -> {
        long orgUnitId = a.parentReference().id();
        return IntStream.range(0, rnd.nextInt(40)).mapToObj(i -> ImmutableLogicalFlow.builder().source(a.applicationReference()).target(randomAppPick(apps, orgUnitId)).build());
    }).collect(toSet());
    Set<LogicalFlow> probableFlows = authSources.stream().flatMap(a -> IntStream.range(0, rnd.nextInt(30)).mapToObj(i -> ImmutableLogicalFlow.builder().source(a.applicationReference()).target(randomAppPick(apps, randomPick(orgUnits).id().get())).build())).collect(toSet());
    Set<LogicalFlow> randomFlows = apps.stream().flatMap(a -> IntStream.range(0, rnd.nextInt(5)).mapToObj(i -> {
        EntityReference target = randomAppPick(apps, randomPick(orgUnits).id().get());
        return ImmutableLogicalFlow.builder().source(a.entityReference()).target(target).lastUpdatedBy("admin").build();
    })).collect(toSet());
    dsl.deleteFrom(LOGICAL_FLOW).execute();
    Set<LogicalFlow> all = new HashSet<>();
    all.addAll(randomFlows);
    all.addAll(expectedFlows);
    all.addAll(probableFlows);
    System.out.println("--- saving: " + all.size());
    Set<LogicalFlowRecord> records = SetUtilities.map(all, df -> LogicalFlowDao.TO_RECORD_MAPPER.apply(df, dsl));
    dsl.batchStore(records).execute();
    System.out.println("--- done");
}
Also used : OrganisationalUnitService(com.khartec.waltz.service.orgunit.OrganisationalUnitService) IntStream(java.util.stream.IntStream) AuthoritativeSource(com.khartec.waltz.model.authoritativesource.AuthoritativeSource) SetUtilities(com.khartec.waltz.common.SetUtilities) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) EntityReference(com.khartec.waltz.model.EntityReference) Random(java.util.Random) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) EntityKind(com.khartec.waltz.model.EntityKind) HashSet(java.util.HashSet) ImmutableLogicalFlow(com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow) DIConfiguration(com.khartec.waltz.service.DIConfiguration) OrganisationalUnitService(com.khartec.waltz.service.orgunit.OrganisationalUnitService) LogicalFlowDao(com.khartec.waltz.data.logical_flow.LogicalFlowDao) DSLContext(org.jooq.DSLContext) ApplicationService(com.khartec.waltz.service.application.ApplicationService) LogicalFlowRecord(com.khartec.waltz.schema.tables.records.LogicalFlowRecord) Collectors.toSet(java.util.stream.Collectors.toSet) LOGICAL_FLOW(com.khartec.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW) Application(com.khartec.waltz.model.application.Application) LogicalFlowService(com.khartec.waltz.service.logical_flow.LogicalFlowService) Set(java.util.Set) AuthoritativeSourceDao(com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ListUtilities.randomPick(com.khartec.waltz.common.ListUtilities.randomPick) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) LogicalFlowRecord(com.khartec.waltz.schema.tables.records.LogicalFlowRecord) LogicalFlowService(com.khartec.waltz.service.logical_flow.LogicalFlowService) AuthoritativeSourceDao(com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao) DSLContext(org.jooq.DSLContext) AuthoritativeSource(com.khartec.waltz.model.authoritativesource.AuthoritativeSource) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) ImmutableLogicalFlow(com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow) EntityReference(com.khartec.waltz.model.EntityReference) Application(com.khartec.waltz.model.application.Application) ApplicationService(com.khartec.waltz.service.application.ApplicationService) HashSet(java.util.HashSet)

Example 4 with LOGICAL_FLOW

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

the class AdditiveFlowGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    AuthoritativeSourceDao authSourceDao = ctx.getBean(AuthoritativeSourceDao.class);
    ApplicationService applicationDao = ctx.getBean(ApplicationService.class);
    LogicalFlowService dataFlowDao = ctx.getBean(LogicalFlowService.class);
    OrganisationalUnitService orgUnitDao = ctx.getBean(OrganisationalUnitService.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<AuthoritativeSource> authSources = authSourceDao.findByEntityKind(EntityKind.ORG_UNIT);
    List<Application> apps = applicationDao.findAll();
    Application referenceApplication = applicationDao.getById(APPLICATION_ID);
    List<OrganisationalUnit> orgUnits = orgUnitDao.findAll();
    Set<LogicalFlow> expectedFlows = authSources.stream().map(a -> {
        long orgUnitId = a.parentReference().id();
        if (referenceApplication.organisationalUnitId().equals(orgUnitId)) {
            return Optional.of(ImmutableLogicalFlow.builder().source(a.applicationReference()).target(referenceApplication.entityReference()).build());
        } else {
            return Optional.<LogicalFlow>empty();
        }
    }).filter(o -> o.isPresent()).map(o -> o.get()).collect(toSet());
    Set<LogicalFlow> randomTargetFlows = IntStream.range(0, rnd.nextInt(APPROX_FLOW_GENERATION_COUNT / 2)).mapToObj(i -> {
        EntityReference target = randomAppPick(apps, randomPick(orgUnits).id().get());
        return ImmutableLogicalFlow.builder().source(referenceApplication.entityReference()).target(target).build();
    }).collect(toSet());
    Set<LogicalFlow> randomSourceFlows = IntStream.range(0, rnd.nextInt(APPROX_FLOW_GENERATION_COUNT / 2)).mapToObj(i -> {
        EntityReference source = randomAppPick(apps, randomPick(orgUnits).id().get());
        return ImmutableLogicalFlow.builder().source(source).target(referenceApplication.entityReference()).build();
    }).collect(toSet());
    dsl.delete(LOGICAL_FLOW).where(LOGICAL_FLOW.SOURCE_ENTITY_ID.eq(APPLICATION_ID)).or(LOGICAL_FLOW.TARGET_ENTITY_ID.eq(APPLICATION_ID)).execute();
    Set<LogicalFlow> all = new HashSet<>();
    all.addAll(randomTargetFlows);
    all.addAll(randomSourceFlows);
    all.addAll(expectedFlows);
    System.out.println("--- saving: " + all.size());
    Set<LogicalFlowRecord> records = SetUtilities.map(all, df -> LogicalFlowDao.TO_RECORD_MAPPER.apply(df, dsl));
    dsl.batchStore(records).execute();
    System.out.println("--- done");
}
Also used : OrganisationalUnitService(com.khartec.waltz.service.orgunit.OrganisationalUnitService) Application(com.khartec.waltz.model.application.Application) IntStream(java.util.stream.IntStream) java.util(java.util) AuthoritativeSource(com.khartec.waltz.model.authoritativesource.AuthoritativeSource) SetUtilities(com.khartec.waltz.common.SetUtilities) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) LogicalFlowService(com.khartec.waltz.service.logical_flow.LogicalFlowService) EntityReference(com.khartec.waltz.model.EntityReference) AuthoritativeSourceDao(com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityKind(com.khartec.waltz.model.EntityKind) ListUtilities.randomPick(com.khartec.waltz.common.ListUtilities.randomPick) Collectors.toList(java.util.stream.Collectors.toList) ImmutableLogicalFlow(com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow) DIConfiguration(com.khartec.waltz.service.DIConfiguration) OrganisationalUnitService(com.khartec.waltz.service.orgunit.OrganisationalUnitService) LogicalFlowDao(com.khartec.waltz.data.logical_flow.LogicalFlowDao) DSLContext(org.jooq.DSLContext) ApplicationService(com.khartec.waltz.service.application.ApplicationService) LogicalFlowRecord(com.khartec.waltz.schema.tables.records.LogicalFlowRecord) Collectors.toSet(java.util.stream.Collectors.toSet) LOGICAL_FLOW(com.khartec.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) LogicalFlowRecord(com.khartec.waltz.schema.tables.records.LogicalFlowRecord) LogicalFlowService(com.khartec.waltz.service.logical_flow.LogicalFlowService) AuthoritativeSourceDao(com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao) DSLContext(org.jooq.DSLContext) AuthoritativeSource(com.khartec.waltz.model.authoritativesource.AuthoritativeSource) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) ImmutableLogicalFlow(com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow) EntityReference(com.khartec.waltz.model.EntityReference) Application(com.khartec.waltz.model.application.Application) ApplicationService(com.khartec.waltz.service.application.ApplicationService)

Aggregations

EntityKind (com.khartec.waltz.model.EntityKind)4 EntityReference (com.khartec.waltz.model.EntityReference)4 LOGICAL_FLOW (com.khartec.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW)4 DSLContext (org.jooq.DSLContext)4 SetUtilities (com.khartec.waltz.common.SetUtilities)3 LogicalFlowDao (com.khartec.waltz.data.logical_flow.LogicalFlowDao)3 DIConfiguration (com.khartec.waltz.service.DIConfiguration)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 ListUtilities.randomPick (com.khartec.waltz.common.ListUtilities.randomPick)2 AuthoritativeSourceDao (com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao)2 EntityReference.mkRef (com.khartec.waltz.model.EntityReference.mkRef)2 Application (com.khartec.waltz.model.application.Application)2 AuthoritativeSource (com.khartec.waltz.model.authoritativesource.AuthoritativeSource)2 ImmutableLogicalFlow (com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow)2 LogicalFlow (com.khartec.waltz.model.logical_flow.LogicalFlow)2 OrganisationalUnit (com.khartec.waltz.model.orgunit.OrganisationalUnit)2 LogicalFlowRecord (com.khartec.waltz.schema.tables.records.LogicalFlowRecord)2 ApplicationService (com.khartec.waltz.service.application.ApplicationService)2 LogicalFlowService (com.khartec.waltz.service.logical_flow.LogicalFlowService)2 OrganisationalUnitService (com.khartec.waltz.service.orgunit.OrganisationalUnitService)2