use of com.khartec.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class LogicalFlowEndpoint method addFlowRoute.
private LogicalFlow addFlowRoute(Request request, Response response) throws IOException {
ensureUserHasEditRights(request);
String username = getUsername(request);
AddLogicalFlowCommand addCmd = readBody(request, AddLogicalFlowCommand.class);
LOG.info("User: {}, adding new logical flow: {}", username, addCmd);
LogicalFlow savedFlow = logicalFlowService.addFlow(addCmd, username);
return savedFlow;
}
use of com.khartec.waltz.model.logical_flow.LogicalFlow 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");
}
use of com.khartec.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class LogicalFlowDecoratorRatingsCalculator method lookupRating.
private AuthoritativenessRating lookupRating(Map<Long, DataType> typesById, Map<Long, LogicalFlow> flowsById, Map<Long, Application> targetAppsById, AuthoritativeSourceResolver resolver, LogicalFlowDecorator decorator) {
LogicalFlow flow = flowsById.get(decorator.dataFlowId());
EntityReference vantagePoint = lookupVantagePoint(targetAppsById, flow);
EntityReference source = flow.source();
String dataTypeCode = lookupDataTypeCode(typesById, decorator);
return resolver.resolve(vantagePoint, source, dataTypeCode);
}
use of com.khartec.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class LogicalFlowDecoratorRatingsCalculator method calculate.
public Collection<LogicalFlowDecorator> calculate(Collection<LogicalFlowDecorator> decorators) {
List<LogicalFlow> flows = loadFlows(decorators).stream().filter(f -> f.target().kind() == EntityKind.APPLICATION && f.source().kind() == EntityKind.APPLICATION).collect(toList());
if (isEmpty(flows))
return Collections.emptyList();
List<Application> targetApps = loadTargetApplications(flows);
List<DataType> dataTypes = dataTypeDao.getAll();
Map<Long, DataType> typesById = indexById(dataTypes);
Map<Long, LogicalFlow> flowsById = indexById(flows);
Map<Long, Application> targetAppsById = indexById(targetApps);
AuthoritativeSourceResolver resolver = createResolver(targetApps);
return decorators.stream().map(decorator -> {
try {
if (decorator.decoratorEntity().kind() != EntityKind.DATA_TYPE) {
return decorator;
} else {
AuthoritativenessRating rating = lookupRating(typesById, flowsById, targetAppsById, resolver, decorator);
return ImmutableLogicalFlowDecorator.copyOf(decorator).withRating(rating);
}
} catch (Exception e) {
LOG.warn("Failed to calculate rating for decorator: {}, reason: {}", decorator, e.getMessage());
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toSet());
}
use of com.khartec.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class DataFlowHarness method main.
public static void main(String[] args) throws ParseException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
LogicalFlowService service = ctx.getBean(LogicalFlowService.class);
LogicalFlowDao dao = ctx.getBean(LogicalFlowDao.class);
LogicalFlowIdSelectorFactory factory = ctx.getBean(LogicalFlowIdSelectorFactory.class);
IdSelectionOptions options = IdSelectionOptions.mkOpts(EntityReference.mkRef(EntityKind.ORG_UNIT, 5000), HierarchyQueryScope.CHILDREN);
Select<Record1<Long>> selector = factory.apply(options);
System.out.println(selector);
List<LogicalFlow> flows = dao.findBySelector(selector);
flows.forEach(System.out::println);
// by data type
EntityReference dataType = EntityReference.mkRef(EntityKind.DATA_TYPE, 6000);
IdSelectionOptions dataTypeOptions = IdSelectionOptions.mkOpts(dataType, HierarchyQueryScope.CHILDREN);
List<LogicalFlow> byDataTypeFlows = service.findBySelector(dataTypeOptions);
byDataTypeFlows.forEach(System.out::println);
System.out.println(byDataTypeFlows.size());
}
Aggregations