use of org.finos.waltz.model.datatype.DataTypeDecorator 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());
}
use of org.finos.waltz.model.datatype.DataTypeDecorator in project waltz by khartec.
the class FlowClassificationCalculator method update.
private int[] update(DataType dataType, EntityReference vantageRef) {
LOG.debug("Updating ratings for flow classification rule - dataType name: {}, id: {}, vantage point: {}", dataType.name(), dataType.id().get(), vantageRef);
IdSelectionOptions selectorOptions = mkOpts(vantageRef);
Select<Record1<Long>> selector = appIdSelectorFactory.apply(selectorOptions);
Set<Long> dataTypeDescendents = entityHierarchyDao.findDesendents(dataType.entityReference()).stream().map(d -> d.id().get()).collect(Collectors.toSet());
Collection<DataTypeDecorator> impactedDecorators = logicalFlowDecoratorDao.findByEntityIdSelector(selector, Optional.of(EntityKind.APPLICATION)).stream().filter(decorator -> dataTypeDescendents.contains(decorator.decoratorEntity().id())).collect(toList());
Collection<DataTypeDecorator> reRatedDecorators = ratingsCalculator.calculate(impactedDecorators);
Set<DataTypeDecorator> modifiedDecorators = SetUtilities.minus(fromCollection(reRatedDecorators), fromCollection(impactedDecorators));
LOG.debug("Need to update {} ratings due to auth source change - dataType name: {}, id: {}, parent: {}", modifiedDecorators.size(), dataType.name(), dataType.id().get(), vantageRef);
return updateDecorators(modifiedDecorators);
}
Aggregations