use of org.finos.waltz.model.application.Application in project waltz by finos.
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 finos.
the class ApplicationService method findRelated.
public Map<AssetCodeRelationshipKind, List<Application>> findRelated(long appId) {
List<Application> related = applicationDao.findRelatedByApplicationId(appId);
Optional<Application> foundApp = related.stream().filter(app -> app.id().equals(Optional.of(appId))).findFirst();
if (foundApp.isPresent()) {
Application app = foundApp.get();
Function<Application, AssetCodeRelationshipKind> classifier = relatedApp -> {
boolean sameParent = relatedApp.parentAssetCode().equals(app.parentAssetCode());
boolean sameCode = relatedApp.assetCode().equals(app.assetCode());
boolean isParent = relatedApp.assetCode().equals(app.parentAssetCode());
boolean isChild = relatedApp.parentAssetCode().equals(app.assetCode());
if (sameCode) {
return AssetCodeRelationshipKind.SHARING;
} else if (isParent) {
return AssetCodeRelationshipKind.PARENT;
} else if (isChild) {
return AssetCodeRelationshipKind.CHILD;
} else if (sameParent && app.parentAssetCode().isPresent()) {
return AssetCodeRelationshipKind.SIBLING;
} else {
return AssetCodeRelationshipKind.NONE;
}
};
return related.stream().filter(// can do simple ref check here
relatedApp -> relatedApp != app).collect(Collectors.groupingBy(classifier));
} else {
return emptyMap();
}
}
use of org.finos.waltz.model.application.Application in project waltz by finos.
the class ScenarioRatingImporter method mkScenarioRatingRecords.
private List<ScenarioRatingItemRecord> mkScenarioRatingRecords(List<Measurable> measurables, Map<String, RatingSchemeItem> ratingsByName, List<ScenarioRatingRow> rows, Scenario scenario) {
Collection<ScenarioAxisItem> scenarioAxes = scenarioAxisItemDao.findForScenarioId(scenario.id().get());
Map<Long, Measurable> measurablesById = indexBy(m -> m.id().get(), measurables);
Map<String, ScenarioAxisItem> scenarioAxesByName = scenarioAxes.stream().map(sa -> Tuple.tuple(lower(measurablesById.get(sa.domainItem().id()).name()), sa)).collect(toMap(t -> t.v1(), t -> t.v2()));
return rows.stream().map(r -> {
ScenarioAxisItem columnAxis = scenarioAxesByName.get(lower(r.column()));
checkNotNull(columnAxis, "columnAxis cannot be null");
checkTrue(columnAxis.axisOrientation().equals(AxisOrientation.COLUMN), "column does not match a oolumn axis");
ScenarioAxisItem rowAxis = scenarioAxesByName.get(lower(r.row()));
checkNotNull(rowAxis, "rowAxis cannot be null");
checkTrue(rowAxis.axisOrientation().equals(AxisOrientation.ROW), "row does not match a row axis");
Application app = assetCodeToApplicationMap.get(r.assetCode());
checkNotNull(app, String.format("Application with asset code[%s] cannot be null", r.assetCode()));
RatingSchemeItem rating = ratingsByName.get(lower(r.rating()));
checkNotNull(rating, String.format("rating [%s] cannot be null", r.rating()));
ScenarioRatingItemRecord record = new ScenarioRatingItemRecord();
record.setScenarioId(scenario.id().get());
record.setRating(rating.rating().toString());
record.setDomainItemKind(EntityKind.APPLICATION.name());
record.setDomainItemId(app.id().get());
record.setRowKind(rowAxis.domainItem().kind().name());
record.setRowId(rowAxis.domainItem().id());
record.setColumnKind(columnAxis.domainItem().kind().name());
record.setColumnId(columnAxis.domainItem().id());
record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
record.setLastUpdatedBy(r.providedBy());
record.setDescription(r.description());
return record;
}).collect(toList());
}
use of org.finos.waltz.model.application.Application in project waltz by finos.
the class ScenarioRatingImporter method importScenarioRatings.
public void importScenarioRatings(String filename) throws IOException {
List<Application> allApps = dsl.select().from(APPLICATION).fetch(ApplicationDao.TO_DOMAIN_MAPPER);
assetCodeToApplicationMap = indexBy(a -> ExternalIdValue.orElse(a.assetCode(), null), allApps);
List<ScenarioRatingRow> ratingRows = parseData(filename);
Map<String, Map<String, List<ScenarioRatingRow>>> rowsGroupedByRoadmapByScenario = ratingRows.stream().collect(groupingBy(ScenarioRatingRow::roadmap, groupingBy(ScenarioRatingRow::scenario)));
// get roadmap id
Map<String, Roadmap> roadmapNameToIdMap = getNameToRoadmapMap(roadmapDao);
List<Measurable> measurables = measurableDao.findAll();
rowsGroupedByRoadmapByScenario.forEach((String roadmapName, Map<String, List<ScenarioRatingRow>> scenarioAndRows) -> {
// get roadmap
Roadmap roadmap = roadmapNameToIdMap.get(lower(roadmapName));
checkNotNull(roadmap, "roadmap [" + roadmapName + "] cannot be null");
// get rating scheme
RatingScheme ratingScheme = ratingSchemeDao.getById(roadmap.ratingSchemeId());
checkNotNull(ratingScheme, "ratingScheme cannot be null");
Map<String, RatingSchemeItem> ratingsByName = indexBy(r -> lower(r.name()), ratingScheme.ratings());
// index available scenarios
Map<String, Scenario> scenariosByName = indexBy(s -> lower(s.name()), scenarioDao.findForRoadmapId(roadmap.id().get()));
scenarioAndRows.forEach((scenarioName, rows) -> updateRatingsForScenario(measurables, roadmap, ratingsByName, rows, scenariosByName, scenarioName));
});
}
use of org.finos.waltz.model.application.Application in project waltz by khartec.
the class LogicalFlowDecoratorRatingsCalculator method calculate.
public Collection<DataTypeDecorator> calculate(Collection<DataTypeDecorator> decorators) {
List<LogicalFlow> appToAppFlows = filter(IS_APP_TO_APP_FLOW, loadFlows(decorators));
if (isEmpty(appToAppFlows))
return Collections.emptyList();
List<Application> targetApps = loadTargetApplications(appToAppFlows);
List<DataType> dataTypes = dataTypeDao.findAll();
Set<FlowClassification> flowClassifications = flowClassificationDao.findAll();
Map<Long, DataType> typesById = indexById(dataTypes);
Map<Long, LogicalFlow> flowsById = indexById(appToAppFlows);
Map<Long, Application> targetAppsById = indexById(targetApps);
FlowClassificationRuleResolver resolver = createResolver(targetApps);
return decorators.stream().filter(d -> flowsById.containsKey(d.dataFlowId())).map(decorator -> {
try {
if (decorator.decoratorEntity().kind() != EntityKind.DATA_TYPE) {
return decorator;
} else {
AuthoritativenessRatingValue rating = lookupRating(flowsById, targetAppsById, resolver, decorator);
Optional<Long> ruleId = lookupFlowClassificationRule(typesById, flowsById, targetAppsById, resolver, decorator);
return ImmutableDataTypeDecorator.copyOf(decorator).withRating(rating).withFlowClassificationRuleId(ruleId);
}
} catch (Exception e) {
LOG.warn("Failed to calculate rating for decorator: {}, reason: {}", decorator, e.getMessage());
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toSet());
}
Aggregations