use of com.khartec.waltz.model.data_flow_decorator.LogicalFlowDecorator in project waltz by khartec.
the class LogicalFlowDecoratorService method addDecorators.
public int[] addDecorators(long flowId, Set<EntityReference> decoratorReferences, String username) {
checkNotNull(decoratorReferences, "decoratorReferences cannot be null");
if (decoratorReferences.isEmpty())
return new int[0];
LogicalFlow flow = logicalFlowDao.findByFlowId(flowId);
boolean requiresRating = flow.source().kind() == APPLICATION && flow.target().kind() == APPLICATION;
Collection<LogicalFlowDecorator> unrated = map(decoratorReferences, ref -> ImmutableLogicalFlowDecorator.builder().rating(AuthoritativenessRating.NO_OPINION).provenance("waltz").dataFlowId(flowId).decoratorEntity(ref).lastUpdatedBy(username).lastUpdatedAt(nowUtc()).build());
Collection decorators = requiresRating ? ratingsCalculator.calculate(unrated) : unrated;
int[] added = logicalFlowDecoratorDao.addDecorators(decorators);
dataTypeUsageService.recalculateForApplications(newArrayList(flow.source(), flow.target()));
audit("Added", decoratorReferences, flow, username);
return added;
}
use of com.khartec.waltz.model.data_flow_decorator.LogicalFlowDecorator in project waltz by khartec.
the class AuthSourceRatingCalculator method update.
private int[] update(DataType dataType, EntityReference vantageRef) {
LOG.info("Updating ratings for auth source - dataType: {}, vantage point: {}", dataType, vantageRef);
IdSelectionOptions selectorOptions = mkOpts(vantageRef, HierarchyQueryScope.CHILDREN);
Select<Record1<Long>> selector = appIdSelectorFactory.apply(selectorOptions);
Collection<LogicalFlowDecorator> impactedDecorators = logicalFlowDecoratorDao.findByEntityIdSelectorAndKind(EntityKind.APPLICATION, selector, EntityKind.DATA_TYPE).stream().filter(decorator -> decorator.decoratorEntity().id() == dataType.id().get()).collect(toList());
Collection<LogicalFlowDecorator> reRatedDecorators = ratingsCalculator.calculate(impactedDecorators);
Set<LogicalFlowDecorator> modifiedDecorators = SetUtilities.minus(fromCollection(reRatedDecorators), fromCollection(impactedDecorators));
LOG.info("Need to update {} ratings due to auth source change - dataType: {}, parent: {}", modifiedDecorators.size(), dataType, vantageRef);
return updateDecorators(modifiedDecorators);
}
use of com.khartec.waltz.model.data_flow_decorator.LogicalFlowDecorator 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());
}
Aggregations