use of org.finos.waltz.model.application.Application in project waltz by khartec.
the class FlowSummaryWithTypesAndPhysicalsExport method main.
public static void main(String[] args) throws IOException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
ApplicationIdSelectorFactory appIdSelectorFactory = new ApplicationIdSelectorFactory();
ApplicationDao applicationDao = ctx.getBean(ApplicationDao.class);
OrganisationalUnitDao organisationalUnitDao = ctx.getBean(OrganisationalUnitDao.class);
LogicalFlowDao logicalFlowDao = ctx.getBean(LogicalFlowDao.class);
LogicalFlowDecoratorDao decoratorDao = ctx.getBean(LogicalFlowDecoratorDao.class);
DataTypeDao dataTypeDao = ctx.getBean(DataTypeDao.class);
Select<Record1<Long>> appSelector = mkAppIdSelector(appIdSelectorFactory);
Select<Record1<Long>> logicalFlowSelector = mkLogicalFlowSelectorFromAppSelector(appSelector);
System.out.println("Loading apps");
Set<Application> allApps = fromCollection(applicationDao.findAll());
System.out.println("Loading in scope apps");
Set<Long> inScopeAppIds = toIds(applicationDao.findByAppIdSelector(appSelector));
System.out.println("Loading OUs");
List<OrganisationalUnit> allOUs = organisationalUnitDao.findAll();
System.out.println("Loading DTs");
List<DataType> allDataTypes = dataTypeDao.findAll();
System.out.println("Loading Logical Flows");
List<LogicalFlow> logicalFlows = logicalFlowDao.findBySelector(logicalFlowSelector);
System.out.println("Loading decorators");
List<DataTypeDecorator> decorators = decoratorDao.findByAppIdSelector(appSelector);
System.out.println("Loading phys flows");
Map<Long, Collection<Tuple7<Long, String, String, String, String, String, String>>> physicalsByLogical = loadPhysicalsByLogical(dsl, logicalFlowSelector);
System.out.println("Indexing");
Map<Optional<Long>, Application> appsById = indexByOptId(allApps);
Map<Optional<Long>, DataType> dataTypesById = indexByOptId(allDataTypes);
Map<Optional<Long>, OrganisationalUnit> ousById = indexByOptId(allOUs);
Map<Long, Collection<DataTypeDecorator>> decoratorsByLogicalFlowId = groupBy(DataTypeDecorator::dataFlowId, decorators);
System.out.println("Processing");
CsvListWriter csvWriter = setupCSVWriter();
logicalFlows.stream().filter(lf -> lf.source().kind() == EntityKind.APPLICATION && lf.target().kind() == EntityKind.APPLICATION).map(Tuple::tuple).map(t -> t.concat(appsById.get(Optional.of(t.v1.source().id())))).map(t -> t.concat(appsById.get(Optional.of(t.v1.target().id())))).filter(t -> t.v2 != null && t.v3 != null).map(t -> t.concat(ousById.get(Optional.of(t.v2.organisationalUnitId())))).map(t -> t.concat(ousById.get(Optional.of(t.v3.organisationalUnitId())))).map(t -> t.concat(decoratorsByLogicalFlowId.getOrDefault(t.v1.id().orElse(-1L), emptyList()).stream().filter(d -> d.decoratorEntity().kind() == EntityKind.DATA_TYPE).map(d -> dataTypesById.get(Optional.of(d.decoratorEntity().id()))).sorted(Comparator.comparing(NameProvider::name)).collect(Collectors.toList()))).map(t -> t.concat(inScopeAppIds.contains(t.v2.id().get()))).map(t -> t.concat(inScopeAppIds.contains(t.v3.id().get()))).flatMap(t -> physicalsByLogical.getOrDefault(t.v1.id().orElse(-1L), newArrayList(tuple(-1L, "-", "-", "-", "-", "-", "-"))).stream().map(p -> t.concat(p.skip1()))).map(t -> newArrayList(// src
t.v2.name(), t.v2.assetCode().map(ExternalIdValue::value).orElse(""), t.v2.applicationKind().name(), t.v2.entityLifecycleStatus().name(), // src OU
Optional.ofNullable(t.v4).map(NameProvider::name).orElse("?"), t.v7.toString(), // trg
t.v3.name(), t.v3.assetCode().map(ExternalIdValue::value).orElse(""), t.v3.applicationKind().name(), t.v3.entityLifecycleStatus().name(), // trg OU
Optional.ofNullable(t.v5).map(NameProvider::name).orElse("?"), t.v8.toString(), StringUtilities.joinUsing(t.v6, NameProvider::name, ","), t.v9, t.v10, t.v11, t.v12, t.v13, t.v14)).forEach(Unchecked.consumer(csvWriter::write));
}
use of org.finos.waltz.model.application.Application in project waltz by khartec.
the class ShortestPath method main.
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
LogicalFlowDao logicalFlowDao = ctx.getBean(LogicalFlowDao.class);
ApplicationDao applicationDao = ctx.getBean(ApplicationDao.class);
List<LogicalFlow> allActive = logicalFlowDao.findAllActive();
Graph<EntityReference, DefaultEdge> g = createGraph(allActive);
Application targetApp = findFirstMatchByCode(applicationDao, targetAssetCode);
Stream.of(sourceAssetCodes).map(assetCode -> findFirstMatchByCode(applicationDao, assetCode)).filter(Objects::nonNull).map(sourceApp -> {
System.out.printf("Route from: %s (%s)\n----------------------\n", sourceApp.name(), ExternalIdValue.orElse(sourceApp.assetCode(), ""));
return sourceApp.entityReference();
}).filter(sourceRef -> {
if (!g.containsVertex(sourceRef)) {
System.out.println("No flows defined for application\n\n");
return false;
}
return true;
}).map(sourceRef -> findShortestPath(g, sourceRef, targetApp.entityReference())).filter(route -> {
if (route == null) {
System.out.println("No route found\n\n");
return false;
}
return true;
}).forEach(route -> {
List<DefaultEdge> edgeList = route.getEdgeList();
Set<Long> appIds = edgeList.stream().flatMap(e -> Stream.of(g.getEdgeSource(e).id(), g.getEdgeTarget(e).id())).collect(toSet());
Map<Long, Application> appsById = MapUtilities.indexBy(a -> a.id().get(), applicationDao.findByIds(appIds));
edgeList.forEach(edge -> {
Application source = appsById.get(g.getEdgeSource(edge).id());
Application target = appsById.get(g.getEdgeTarget(edge).id());
System.out.printf("%s (%s) -> %s (%s) \n", source.name(), ExternalIdValue.orElse(source.assetCode(), ""), target.name(), ExternalIdValue.orElse(target.assetCode(), ""));
});
System.out.println();
System.out.println();
});
}
use of org.finos.waltz.model.application.Application in project waltz by khartec.
the class MsSqlSearchHarness method main.
public static void main(String[] args) {
ApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
SqlServerAppSearch appSearch = new SqlServerAppSearch();
EntitySearchOptions searchOptions = ImmutableEntitySearchOptions.builder().addEntityKinds(EntityKind.APPLICATION).userId("admin").limit(EntitySearchOptions.DEFAULT_SEARCH_RESULTS_LIMIT).searchQuery("sap").build();
List<Application> results = appSearch.searchFullText(dsl, searchOptions);
results.stream().filter(a -> a.entityLifecycleStatus() != EntityLifecycleStatus.REMOVED).forEach(a -> System.out.println(a.name() + " - " + a.lifecyclePhase()));
}
use of org.finos.waltz.model.application.Application in project waltz by khartec.
the class InvolvementImporter method main.
public static void main(String[] args) throws IOException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
ApplicationService applicationService = ctx.getBean(ApplicationService.class);
PersonService personService = ctx.getBean(PersonService.class);
Map<String, Application> appsByExtId = indexBy(a -> ExternalIdValue.orElse(a.assetCode(), null), applicationService.findAll());
Map<String, Person> peopleByName = indexBy(p -> toSurnameFirstname(p.displayName()).toLowerCase(), personService.all());
Siphon<String[]> incorrectSizeSiphon = mkSiphon(arr -> arr.length != 3);
Siphon<Tuple2<String, ?>> unknownAppSiphon = mkSiphon(t -> !appsByExtId.containsKey(t.v1));
Siphon<Tuple2<?, String>> unknownPersonSiphon = mkSiphon(t -> !peopleByName.containsKey(t.v2.toLowerCase()));
Siphon<Tuple2<Application, ?>> retiredAppSiphon = mkSiphon(t -> t.v1.lifecyclePhase() == LifecyclePhase.RETIRED);
List<Tuple2<Application, Person>> r = IOUtilities.streamLines(classLoader.getResourceAsStream(fileName)).map(line -> line.split("\t")).filter(d -> incorrectSizeSiphon.test(d)).map(arr -> Tuple.tuple(arr[1], arr[0])).filter(t -> unknownAppSiphon.test(t)).map(t -> t.map1(extId -> appsByExtId.get(extId))).filter(t -> retiredAppSiphon.test(t)).filter(t -> unknownPersonSiphon.test(t)).map(t -> t.map2(n -> peopleByName.get(n.toLowerCase()))).collect(Collectors.toList());
Set<Application> distinctApps = r.stream().map(t -> t.v1).distinct().collect(Collectors.toSet());
Set<Person> distinctPeople = r.stream().map(t -> t.v2).distinct().collect(Collectors.toSet());
System.out.println("----");
System.out.println("Wrong size count: " + incorrectSizeSiphon.getResults().size());
System.out.println("Apps not found count: " + unknownAppSiphon.getResults().size());
System.out.println("Retired app count: " + retiredAppSiphon.getResults().size());
System.out.println("Person not found count: " + unknownPersonSiphon.getResults().size());
System.out.println("----");
System.out.println("Good record count: " + r.size());
System.out.println("Distinct App count: " + distinctApps.size());
System.out.println("Distinct People count: " + distinctPeople.size());
Map<String, Long> unknownPersonCounts = countBy(Tuple2::v2, unknownPersonSiphon.getResults());
DebugUtilities.dump(unknownPersonCounts);
}
use of org.finos.waltz.model.application.Application in project waltz by khartec.
the class EntityStatisticGenerator method createIntStatsFor.
private void createIntStatsFor(EntityStatisticDefinition defn, Application[] applications, EntityStatisticValueDao valueDao, int bound, BiFunction<StatisticValueState, Integer, String> outcomeFn) {
Random rnd = RandomUtilities.getRandom();
List<EntityStatisticValue> values = streamAppRefs(applications).map(appRef -> {
StatisticValueState state = randomPick(StatisticValueState.values());
int v = state == StatisticValueState.PROVIDED ? rnd.nextInt(bound) : 0;
// naughty
v = rnd.nextInt(bound);
return ImmutableEntityStatisticValue.builder().entity(appRef).state(state).statisticId(defn.id().get()).current(true).createdAt(LocalDateTime.now()).value(Integer.toString(v)).outcome(outcomeFn.apply(state, v)).provenance(SAMPLE_DATA_PROVENANCE).build();
}).collect(toList());
valueDao.bulkSaveValues(values);
}
Aggregations