Search in sources :

Example 16 with EntityReference

use of com.khartec.waltz.model.EntityReference in project waltz by khartec.

the class PerspectiveRatingEndpoint method findForEntityAxis.

private Collection<PerspectiveRating> findForEntityAxis(Request request, Response z) {
    EntityReference ref = getEntityReference(request);
    long categoryX = getLong(request, "x");
    long categoryY = getLong(request, "y");
    return perspectiveRatingService.findForEntity(categoryX, categoryY, ref);
}
Also used : EntityReference(com.khartec.waltz.model.EntityReference)

Example 17 with EntityReference

use of com.khartec.waltz.model.EntityReference 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 18 with EntityReference

use of com.khartec.waltz.model.EntityReference in project waltz by khartec.

the class PhysicalFlowGenerator method main.

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<PhysicalSpecification> specifications = dsl.select(PHYSICAL_SPECIFICATION.fields()).select(owningEntityNameField).from(PHYSICAL_SPECIFICATION).fetch(PhysicalSpecificationDao.TO_DOMAIN_MAPPER);
    List<Tuple2<Long, EntityReference>> allLogicalFLows = dsl.select(LOGICAL_FLOW.ID, LOGICAL_FLOW.SOURCE_ENTITY_ID, LOGICAL_FLOW.SOURCE_ENTITY_KIND).from(LOGICAL_FLOW).fetch(r -> Tuple.tuple(r.getValue(LOGICAL_FLOW.ID), mkRef(EntityKind.valueOf(r.getValue(LOGICAL_FLOW.SOURCE_ENTITY_KIND)), r.getValue(LOGICAL_FLOW.SOURCE_ENTITY_ID))));
    Map<EntityReference, Collection<Long>> flowIdsBySource = groupBy(t -> t.v2(), t -> t.v1(), allLogicalFLows);
    System.out.println("---removing demo records");
    dsl.deleteFrom(PHYSICAL_FLOW).where(PHYSICAL_FLOW.PROVENANCE.eq(provenance)).execute();
    final int flowBatchSize = 100000;
    List<PhysicalFlowRecord> flowBatch = new ArrayList<PhysicalFlowRecord>((int) (flowBatchSize * 1.2));
    for (PhysicalSpecification spec : specifications) {
        Collection<Long> flowIds = flowIdsBySource.get(spec.owningEntity());
        if (!isEmpty(flowIds)) {
            List<PhysicalFlowRecord> physicalFlowRecords = mkPhysicalFlowRecords(spec, new LinkedList<>(flowIds));
            flowBatch.addAll(physicalFlowRecords);
        }
        if (flowBatch.size() >= flowBatchSize) {
            System.out.println(String.format("--- saving records: count: %s", flowBatch.size()));
            dsl.batchInsert(flowBatch).execute();
            flowBatch.clear();
        }
    }
    System.out.println(String.format("--- saving records: count: %s", flowBatch.size()));
    dsl.batchInsert(flowBatch).execute();
    flowBatch.clear();
    System.out.println("---done");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PhysicalSpecification(com.khartec.waltz.model.physical_specification.PhysicalSpecification) PhysicalFlowRecord(com.khartec.waltz.schema.tables.records.PhysicalFlowRecord) ListUtilities.newArrayList(com.khartec.waltz.common.ListUtilities.newArrayList) DSLContext(org.jooq.DSLContext) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Tuple2(org.jooq.lambda.tuple.Tuple2) EntityReference(com.khartec.waltz.model.EntityReference)

Example 19 with EntityReference

use of com.khartec.waltz.model.EntityReference in project waltz by khartec.

the class AppViewService method getAppView.

public AppView getAppView(long id) {
    EntityReference ref = ImmutableEntityReference.builder().kind(EntityKind.APPLICATION).id(id).build();
    Future<Application> application = dbExecutorPool.submit(() -> applicationService.getById(id));
    Future<OrganisationalUnit> orgUnit = dbExecutorPool.submit(() -> organisationalUnitService.getByAppId(id));
    Future<List<String>> tags = dbExecutorPool.submit(() -> entityTagService.findTagsForEntityReference(mkRef(EntityKind.APPLICATION, id)));
    Future<List<String>> aliases = dbExecutorPool.submit(() -> entityAliasService.findAliasesForEntityReference(ref));
    Future<ComplexityRating> complexity = dbExecutorPool.submit(() -> complexityRatingService.getForApp(id));
    return Unchecked.supplier(() -> ImmutableAppView.builder().app(application.get()).organisationalUnit(orgUnit.get()).tags(tags.get()).aliases(aliases.get()).complexity(complexity.get()).build()).get();
}
Also used : ImmutableEntityReference(com.khartec.waltz.model.ImmutableEntityReference) EntityReference(com.khartec.waltz.model.EntityReference) List(java.util.List) ComplexityRating(com.khartec.waltz.model.complexity.ComplexityRating) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) Application(com.khartec.waltz.model.application.Application)

Example 20 with EntityReference

use of com.khartec.waltz.model.EntityReference in project waltz by khartec.

the class ApplicationService method registerApp.

public AppRegistrationResponse registerApp(AppRegistrationRequest request, String username) {
    checkNotEmpty(request.name(), "Cannot register app with no name");
    AppRegistrationResponse response = applicationDao.registerApp(request);
    if (response.registered()) {
        EntityReference entityReference = ImmutableEntityReference.builder().id(response.id().get()).kind(EntityKind.APPLICATION).build();
        entityAliasDao.updateAliases(entityReference, request.aliases());
        entityTagDao.updateTags(entityReference, request.tags(), username);
    }
    return response;
}
Also used : AppRegistrationResponse(com.khartec.waltz.model.application.AppRegistrationResponse) ImmutableEntityReference(com.khartec.waltz.model.ImmutableEntityReference) EntityReference(com.khartec.waltz.model.EntityReference)

Aggregations

EntityReference (com.khartec.waltz.model.EntityReference)33 EntityKind (com.khartec.waltz.model.EntityKind)11 DSLContext (org.jooq.DSLContext)9 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)9 List (java.util.List)8 ListUtilities.newArrayList (com.khartec.waltz.common.ListUtilities.newArrayList)6 Collection (java.util.Collection)6 LogicalFlowDao (com.khartec.waltz.data.logical_flow.LogicalFlowDao)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Checks.checkNotNull (com.khartec.waltz.common.Checks.checkNotNull)4 SetUtilities (com.khartec.waltz.common.SetUtilities)4 IdSelectionOptions (com.khartec.waltz.model.IdSelectionOptions)4 LogicalFlow (com.khartec.waltz.model.logical_flow.LogicalFlow)4 LOGICAL_FLOW (com.khartec.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW)4 DIConfiguration (com.khartec.waltz.service.DIConfiguration)4 EntityReference.mkRef (com.khartec.waltz.model.EntityReference.mkRef)3 ImmutableEntityReference (com.khartec.waltz.model.ImmutableEntityReference)3 Application (com.khartec.waltz.model.application.Application)3 OrganisationalUnit (com.khartec.waltz.model.orgunit.OrganisationalUnit)3 LogicalFlowService (com.khartec.waltz.service.logical_flow.LogicalFlowService)3