Search in sources :

Example 1 with LogicalFlowDecorator

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;
}
Also used : ImmutableLogicalFlowDecorator(com.khartec.waltz.model.data_flow_decorator.ImmutableLogicalFlowDecorator) LogicalFlowDecorator(com.khartec.waltz.model.data_flow_decorator.LogicalFlowDecorator) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow)

Example 2 with LogicalFlowDecorator

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);
}
Also used : Logger(org.slf4j.Logger) SetUtilities.fromCollection(com.khartec.waltz.common.SetUtilities.fromCollection) SetUtilities(com.khartec.waltz.common.SetUtilities) ApplicationIdSelectorFactory(com.khartec.waltz.data.application.ApplicationIdSelectorFactory) LogicalFlowDecoratorDao(com.khartec.waltz.data.data_flow_decorator.LogicalFlowDecoratorDao) Checks.checkNotNull(com.khartec.waltz.common.Checks.checkNotNull) LogicalFlowDecoratorRatingsCalculator(com.khartec.waltz.service.data_flow_decorator.LogicalFlowDecoratorRatingsCalculator) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) HierarchyQueryScope(com.khartec.waltz.model.HierarchyQueryScope) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) EntityReference(com.khartec.waltz.model.EntityReference) EntityKind(com.khartec.waltz.model.EntityKind) DataTypeDao(com.khartec.waltz.data.data_type.DataTypeDao) LogicalFlowDecorator(com.khartec.waltz.model.data_flow_decorator.LogicalFlowDecorator) Collectors.toList(java.util.stream.Collectors.toList) IdSelectionOptions(com.khartec.waltz.model.IdSelectionOptions) Record1(org.jooq.Record1) Service(org.springframework.stereotype.Service) DataType(com.khartec.waltz.model.datatype.DataType) IdSelectionOptions.mkOpts(com.khartec.waltz.model.IdSelectionOptions.mkOpts) Select(org.jooq.Select) LogicalFlowDecorator(com.khartec.waltz.model.data_flow_decorator.LogicalFlowDecorator) IdSelectionOptions(com.khartec.waltz.model.IdSelectionOptions) Record1(org.jooq.Record1)

Example 3 with LogicalFlowDecorator

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());
}
Also used : java.util(java.util) AuthoritativeSourceResolver(com.khartec.waltz.service.authoritative_source.AuthoritativeSourceResolver) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EntityReference(com.khartec.waltz.model.EntityReference) AuthoritativeRatingVantagePoint(com.khartec.waltz.model.authoritativesource.AuthoritativeRatingVantagePoint) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) EntityKind(com.khartec.waltz.model.EntityKind) ImmutableLogicalFlowDecorator(com.khartec.waltz.model.data_flow_decorator.ImmutableLogicalFlowDecorator) Service(org.springframework.stereotype.Service) LogicalFlowDao(com.khartec.waltz.data.logical_flow.LogicalFlowDao) ApplicationService(com.khartec.waltz.service.application.ApplicationService) Application(com.khartec.waltz.model.application.Application) Logger(org.slf4j.Logger) Checks.checkNotNull(com.khartec.waltz.common.Checks.checkNotNull) AuthoritativenessRating(com.khartec.waltz.model.rating.AuthoritativenessRating) AuthoritativeSourceDao(com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao) Collectors(java.util.stream.Collectors) DataTypeDao(com.khartec.waltz.data.data_type.DataTypeDao) LogicalFlowDecorator(com.khartec.waltz.model.data_flow_decorator.LogicalFlowDecorator) Collectors.toList(java.util.stream.Collectors.toList) SetUtilities.map(com.khartec.waltz.common.SetUtilities.map) DataType(com.khartec.waltz.model.datatype.DataType) ListUtilities.isEmpty(com.khartec.waltz.common.ListUtilities.isEmpty) IdUtilities.indexById(com.khartec.waltz.model.utils.IdUtilities.indexById) AuthoritativeSourceResolver(com.khartec.waltz.service.authoritative_source.AuthoritativeSourceResolver) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) DataType(com.khartec.waltz.model.datatype.DataType) AuthoritativenessRating(com.khartec.waltz.model.rating.AuthoritativenessRating) Application(com.khartec.waltz.model.application.Application)

Aggregations

LogicalFlowDecorator (com.khartec.waltz.model.data_flow_decorator.LogicalFlowDecorator)3 Checks.checkNotNull (com.khartec.waltz.common.Checks.checkNotNull)2 DataTypeDao (com.khartec.waltz.data.data_type.DataTypeDao)2 EntityKind (com.khartec.waltz.model.EntityKind)2 EntityReference (com.khartec.waltz.model.EntityReference)2 ImmutableLogicalFlowDecorator (com.khartec.waltz.model.data_flow_decorator.ImmutableLogicalFlowDecorator)2 DataType (com.khartec.waltz.model.datatype.DataType)2 LogicalFlow (com.khartec.waltz.model.logical_flow.LogicalFlow)2 Collectors.toList (java.util.stream.Collectors.toList)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2 ListUtilities.isEmpty (com.khartec.waltz.common.ListUtilities.isEmpty)1 SetUtilities (com.khartec.waltz.common.SetUtilities)1 SetUtilities.fromCollection (com.khartec.waltz.common.SetUtilities.fromCollection)1 SetUtilities.map (com.khartec.waltz.common.SetUtilities.map)1 ApplicationIdSelectorFactory (com.khartec.waltz.data.application.ApplicationIdSelectorFactory)1 AuthoritativeSourceDao (com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao)1 LogicalFlowDecoratorDao (com.khartec.waltz.data.data_flow_decorator.LogicalFlowDecoratorDao)1