use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class LogicalFlowHarness method main.
public static void main(String[] args) throws ParseException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
LogicalFlowDao dao = ctx.getBean(LogicalFlowDao.class);
LogicalFlowService service = ctx.getBean(LogicalFlowService.class);
ApplicationIdSelectorFactory factory = new ApplicationIdSelectorFactory();
IdSelectionOptions options = IdSelectionOptions.mkOpts(mkRef(EntityKind.PERSON, 262508), HierarchyQueryScope.CHILDREN);
for (int i = 0; i < 5; i++) {
List<LogicalFlow> flows = FunctionUtilities.time("Get flows", () -> service.findBySelector(options));
}
}
use of org.finos.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 = new LogicalFlowIdSelectorFactory();
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());
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class LogicalFlowGenerator method create.
@Override
public Map<String, Integer> create(ApplicationContext ctx) {
FlowClassificationRuleDao flowClassificationRuleDao = ctx.getBean(FlowClassificationRuleDao.class);
ApplicationService applicationDao = ctx.getBean(ApplicationService.class);
OrganisationalUnitService orgUnitDao = ctx.getBean(OrganisationalUnitService.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
List<FlowClassificationRule> flowClassificationRules = flowClassificationRuleDao.findByEntityKind(EntityKind.ORG_UNIT);
List<Application> apps = applicationDao.findAll();
List<OrganisationalUnit> orgUnits = orgUnitDao.findAll();
LocalDateTime now = LocalDateTime.now();
Set<LogicalFlow> expectedFlows = flowClassificationRules.stream().flatMap(a -> {
long orgUnitId = a.parentReference().id();
return randomlySizedIntStream(0, 40).mapToObj(i -> randomAppPick(apps, orgUnitId).map(target -> ImmutableLogicalFlow.builder().source(a.applicationReference()).target(target).lastUpdatedBy("admin").provenance(SAMPLE_DATA_PROVENANCE).lastUpdatedAt(now).build()).orElse(null));
}).filter(Objects::nonNull).collect(toSet());
Set<LogicalFlow> probableFlows = flowClassificationRules.stream().flatMap(a -> randomlySizedIntStream(0, 30).mapToObj(i -> randomAppPick(apps, randomPick(orgUnits).id().get()).map(target -> ImmutableLogicalFlow.builder().source(a.applicationReference()).target(target).lastUpdatedBy("admin").provenance(SAMPLE_DATA_PROVENANCE).lastUpdatedAt(now).build()).orElse(null))).filter(Objects::nonNull).collect(toSet());
Set<LogicalFlow> randomFlows = apps.stream().flatMap(a -> randomlySizedIntStream(0, 5).mapToObj(i -> randomAppPick(apps, randomPick(orgUnits).id().get()).map(target -> ImmutableLogicalFlow.builder().source(a.entityReference()).target(target).lastUpdatedBy("admin").provenance(SAMPLE_DATA_PROVENANCE).lastUpdatedAt(now).build()).orElse(null))).filter(Objects::nonNull).collect(toSet());
Set<LogicalFlow> all = new HashSet<>();
all.addAll(randomFlows);
all.addAll(expectedFlows);
all.addAll(probableFlows);
Set<LogicalFlow> deduped = uniqBy(all, x -> Tuple.tuple(x.source(), x.target()));
log("--- saving: " + deduped.size());
Set<LogicalFlowRecord> records = SetUtilities.map(deduped, df -> LogicalFlowDao.TO_RECORD_MAPPER.apply(df, dsl));
dsl.batchStore(records).execute();
log("--- done");
return null;
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalSpecificationServiceTest method findBySelector.
@Test
public void findBySelector() {
assertThrows(IllegalArgumentException.class, () -> psSvc.findBySelector(null), "Options cannot be null");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
Long specId = psHelper.createPhysicalSpec(a, "findByEntityReference");
IdSelectionOptions specOpts = mkOpts(mkRef(EntityKind.PHYSICAL_SPECIFICATION, specId));
Collection<PhysicalSpecification> specs = psSvc.findBySelector(specOpts);
assertEquals(1, specs.size(), "When selector is a spec only returns one result");
assertEquals(specId, first(specs).id().get(), "Returns spec when using spec selector");
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
Long specId2 = psHelper.createPhysicalSpec(b, "findByEntityReference");
PhysicalFlowCreateCommandResponse physFlow = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, mkName("findBySelector"));
PhysicalFlowCreateCommandResponse physFlow2 = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId2, mkName("findBySelector"));
IdSelectionOptions appOpts = mkOpts(mkRef(EntityKind.APPLICATION, b.id()));
assertThrows(UnsupportedOperationException.class, () -> psSvc.findBySelector(appOpts), "Throws exception for unsupported entity kinds");
IdSelectionOptions flowOpts = mkOpts(mkRef(EntityKind.LOGICAL_DATA_FLOW, flow.entityReference().id()));
Collection<PhysicalSpecification> specsForFlow = psSvc.findBySelector(flowOpts);
assertEquals(2, specsForFlow.size(), "Returns all specs linked to a flow");
assertEquals(asSet(specId, specId2), map(specsForFlow, d -> d.entityReference().id()), "Returns all specs linked to a flow");
pfHelper.deletePhysicalFlow(physFlow2.entityReference().id());
psHelper.removeSpec(specId2);
Collection<PhysicalSpecification> activeSpecsForFlow = psSvc.findBySelector(flowOpts);
assertEquals(1, activeSpecsForFlow.size(), "Returns all specs linked to a flow");
assertEquals(asSet(specId), map(activeSpecsForFlow, d -> d.entityReference().id()), "Returns only active specs linked to a flow");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalSpecificationServiceTest method propagateDataTypesToLogicalFlows.
@Test
public void propagateDataTypesToLogicalFlows() {
String username = mkName("propagateDataTypesToLogicalFlows");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
Long specId = psHelper.createPhysicalSpec(a, "findByEntityReference");
pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, username);
assertThrows(IllegalArgumentException.class, () -> psSvc.propagateDataTypesToLogicalFlows(null, specId), "Should throw exception if username is null as cannot be logged");
Long dt1Id = dtHelper.createDataType("dt1");
Long dt2Id = dtHelper.createDataType("dt2");
lfHelper.createLogicalFlowDecorators(flow.entityReference(), asSet(dt1Id));
psSvc.propagateDataTypesToLogicalFlows(username, specId);
List<DataTypeDecorator> lfDecorators = lfHelper.fetchDecoratorsForFlow(flow.entityReference().id());
assertEquals(asSet(dt1Id), map(lfDecorators, DataTypeDecorator::dataTypeId), "Propagating does not remove data types from the logical");
dtdSvc.updateDecorators(username, mkRef(EntityKind.PHYSICAL_SPECIFICATION, specId), asSet(dt1Id), emptySet());
psSvc.propagateDataTypesToLogicalFlows(username, specId);
assertEquals(asSet(dt1Id), map(lfDecorators, DataTypeDecorator::dataTypeId), "Can handle data types that already exist on the logical flow");
dtdSvc.updateDecorators(username, mkRef(EntityKind.PHYSICAL_SPECIFICATION, specId), asSet(dt2Id), emptySet());
psSvc.propagateDataTypesToLogicalFlows(username, specId);
List<DataTypeDecorator> lfDecoratorsWithSpecDts = lfHelper.fetchDecoratorsForFlow(flow.entityReference().id());
assertEquals(asSet(dt1Id, dt2Id), map(lfDecoratorsWithSpecDts, DataTypeDecorator::dataTypeId), "Adds data types that are not currently on the logical flow");
}
Aggregations