Search in sources :

Example 6 with AuthoritativenessRatingValue

use of org.finos.waltz.model.rating.AuthoritativenessRatingValue in project waltz by khartec.

the class FlowClassificationRuleResolverTest method existingEntriesThenReturnsMostSpecificRating.

@Test
public void existingEntriesThenReturnsMostSpecificRating() {
    List<FlowClassificationRuleVantagePoint> vantagePoints = new ArrayList<>();
    vantagePoints.add(ImmutableFlowClassificationRuleVantagePoint.builder().vantagePoint(vantagePoint).vantagePointRank(1).dataType(EntityReference.mkRef(EntityKind.DATA_TYPE, 20)).dataTypeRank(2).applicationId(205L).classificationCode(AuthoritativenessRatingValue.of("PRIMARY").value()).ruleId(1L).build());
    vantagePoints.add(ImmutableFlowClassificationRuleVantagePoint.builder().vantagePoint(vantagePoint).vantagePointRank(2).dataType(EntityReference.mkRef(EntityKind.DATA_TYPE, 20)).dataTypeRank(3).applicationId(200L).classificationCode(AuthoritativenessRatingValue.of("SECONDARY").value()).ruleId(1L).build());
    FlowClassificationRuleResolver flowClassificationRuleResolver = new FlowClassificationRuleResolver(vantagePoints);
    AuthoritativenessRatingValue rating = flowClassificationRuleResolver.resolve(vantagePoint, sourceApp, 20L);
    assertEquals(AuthoritativenessRatingValue.of("SECONDARY"), rating);
}
Also used : ImmutableFlowClassificationRuleVantagePoint(org.finos.waltz.model.flow_classification_rule.ImmutableFlowClassificationRuleVantagePoint) FlowClassificationRuleVantagePoint(org.finos.waltz.model.flow_classification_rule.FlowClassificationRuleVantagePoint) AuthoritativenessRatingValue(org.finos.waltz.model.rating.AuthoritativenessRatingValue) ListUtilities.newArrayList(org.finos.waltz.common.ListUtilities.newArrayList) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 7 with AuthoritativenessRatingValue

use of org.finos.waltz.model.rating.AuthoritativenessRatingValue 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());
}
Also used : AuthoritativenessRatingValue(org.finos.waltz.model.rating.AuthoritativenessRatingValue) java.util(java.util) LogicalFlowDao(org.finos.waltz.data.logical_flow.LogicalFlowDao) FlowClassification(org.finos.waltz.model.flow_classification.FlowClassification) ApplicationService(org.finos.waltz.service.application.ApplicationService) EntityKind(org.finos.waltz.model.EntityKind) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FlowClassificationDao(org.finos.waltz.data.flow_classification_rule.FlowClassificationDao) DataType(org.finos.waltz.model.datatype.DataType) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) FlowClassificationRuleVantagePoint(org.finos.waltz.model.flow_classification_rule.FlowClassificationRuleVantagePoint) FlowClassificationRuleDao(org.finos.waltz.data.flow_classification_rule.FlowClassificationRuleDao) Service(org.springframework.stereotype.Service) IdUtilities.indexById(org.finos.waltz.model.utils.IdUtilities.indexById) Logger(org.slf4j.Logger) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Application(org.finos.waltz.model.application.Application) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) Predicate(java.util.function.Predicate) ListUtilities.isEmpty(org.finos.waltz.common.ListUtilities.isEmpty) ImmutableDataTypeDecorator(org.finos.waltz.model.datatype.ImmutableDataTypeDecorator) Collectors(java.util.stream.Collectors) FlowClassificationRuleResolver(org.finos.waltz.service.flow_classification_rule.FlowClassificationRuleResolver) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) ListUtilities.filter(org.finos.waltz.common.ListUtilities.filter) EntityReference(org.finos.waltz.model.EntityReference) DataTypeDao(org.finos.waltz.data.data_type.DataTypeDao) FlowClassification(org.finos.waltz.model.flow_classification.FlowClassification) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) AuthoritativenessRatingValue(org.finos.waltz.model.rating.AuthoritativenessRatingValue) DataType(org.finos.waltz.model.datatype.DataType) Application(org.finos.waltz.model.application.Application) FlowClassificationRuleResolver(org.finos.waltz.service.flow_classification_rule.FlowClassificationRuleResolver)

Aggregations

AuthoritativenessRatingValue (org.finos.waltz.model.rating.AuthoritativenessRatingValue)7 FlowClassificationRuleVantagePoint (org.finos.waltz.model.flow_classification_rule.FlowClassificationRuleVantagePoint)5 ArrayList (java.util.ArrayList)4 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)4 ImmutableFlowClassificationRuleVantagePoint (org.finos.waltz.model.flow_classification_rule.ImmutableFlowClassificationRuleVantagePoint)4 Test (org.junit.jupiter.api.Test)4 EntityKind (org.finos.waltz.model.EntityKind)3 Collectors (java.util.stream.Collectors)2 EntityReference (org.finos.waltz.model.EntityReference)2 java.util (java.util)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 IntStream (java.util.stream.IntStream)1 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)1 HexStrings (org.finos.waltz.common.ColorUtilities.HexStrings)1 DateTimeUtilities.nowUtcTimestamp (org.finos.waltz.common.DateTimeUtilities.nowUtcTimestamp)1