Search in sources :

Example 11 with DataType

use of org.finos.waltz.model.datatype.DataType in project waltz by khartec.

the class DataTypeServiceTest method findSuggestedBySourceEntityRef.

@Test
public void findSuggestedBySourceEntityRef() {
    dataTypeHelper.clearAllDataTypes();
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    EntityReference c = appHelper.createNewApp("b", ouIds.b);
    Collection<DataType> noDecoratorsOnFlow = dtSvc.findSuggestedBySourceEntityRef(a);
    assertEquals(emptyList(), noDecoratorsOnFlow, "if source app has no logical flows returns empty list");
    LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
    assertEquals(emptyList(), noDecoratorsOnFlow, "if source app has no flow decorators returns empty list");
    dataTypeHelper.createDataType(1L, "dt1", "DT1");
    lfHelper.createLogicalFlowDecorators(ab.entityReference(), asSet(1L));
    Set<Long> suggestedDtIds = map(dtSvc.findSuggestedBySourceEntityRef(a), dtd -> dtd.entityReference().id());
    assertEquals(asSet(1L), suggestedDtIds, "returns data type associated to the source application");
    LogicalFlow bc = lfHelper.createLogicalFlow(b, c);
    dataTypeHelper.createDataType(2L, "dt2", "DT2");
    lfHelper.createLogicalFlowDecorators(bc.entityReference(), asSet(2L));
    Set<Long> onlySourceDts = map(dtSvc.findSuggestedBySourceEntityRef(a), dtd -> dtd.entityReference().id());
    assertEquals(asSet(1L), onlySourceDts, "does not return dts associated to only the target app");
    lfHelper.createLogicalFlowDecorators(ab.entityReference(), asSet(2L));
    Set<Long> allSourceDts = map(dtSvc.findSuggestedBySourceEntityRef(a), dtd -> dtd.entityReference().id());
    assertEquals(asSet(1L, 2L), allSourceDts, "returns all dts associated to source app");
    LogicalFlow ac = lfHelper.createLogicalFlow(a, c);
    lfHelper.createLogicalFlowDecorators(ac.entityReference(), asSet(2L));
    Set<Long> setOfDts = map(dtSvc.findSuggestedBySourceEntityRef(a), dtd -> dtd.entityReference().id());
    assertEquals(asSet(1L, 2L), setOfDts, "returns all dts associated to source app");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) EntityReference(org.finos.waltz.model.EntityReference) DataType(org.finos.waltz.model.datatype.DataType) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 12 with DataType

use of org.finos.waltz.model.datatype.DataType 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)

Example 13 with DataType

use of org.finos.waltz.model.datatype.DataType in project waltz by khartec.

the class FlowClassificationRuleService method logUpdate.

private void logUpdate(FlowClassificationRuleUpdateCommand command, String username) {
    FlowClassificationRule rule = getById(command.id().get());
    if (rule == null) {
        return;
    }
    String parentName = getParentEntityName(rule.parentReference());
    DataType dataType = dataTypeDao.getById(rule.dataTypeId());
    Application app = applicationDao.getById(rule.applicationReference().id());
    FlowClassification classification = flowClassificationDao.getById(command.classificationId());
    if (app != null && dataType != null && parentName != null) {
        String msg = format("Updated flow classification rule: %s as the source application with rating: %s, for type: %s, for %s: %s", app.name(), classification.name(), dataType.name(), rule.parentReference().kind().prettyName(), parentName);
        multiLog(username, rule.id().get(), rule.parentReference(), dataType, app, msg, Operation.UPDATE);
    }
}
Also used : FlowClassification(org.finos.waltz.model.flow_classification.FlowClassification) DataType(org.finos.waltz.model.datatype.DataType) Application(org.finos.waltz.model.application.Application)

Example 14 with DataType

use of org.finos.waltz.model.datatype.DataType in project waltz by khartec.

the class LogicalFlowService method getFlowInfoByDirection.

/**
 * @param ref  app or actor ref
 * @param startingDataTypeId  optional id of the data type to use (i.e. restrict to flows below that data type)
 * @return
 */
public LogicalFlowGraphSummary getFlowInfoByDirection(EntityReference ref, Long startingDataTypeId) {
    ImmutableLogicalFlowGraphSummary.Builder result = ImmutableLogicalFlowGraphSummary.builder().flowInfoByDirection(logicalFlowStatsDao.getFlowInfoByDirection(ref, startingDataTypeId));
    if (startingDataTypeId != null) {
        DataType startingDataType = dataTypeService.getDataTypeById(startingDataTypeId);
        result.startingDataType(startingDataType);
        result.parentDataType(startingDataType.parentId().map(dataTypeService::getDataTypeById).orElse(null));
    }
    return result.build();
}
Also used : DataType(org.finos.waltz.model.datatype.DataType)

Example 15 with DataType

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

Aggregations

DataType (org.finos.waltz.model.datatype.DataType)16 DataTypeDao (org.finos.waltz.data.data_type.DataTypeDao)5 Application (org.finos.waltz.model.application.Application)5 DataTypeDecorator (org.finos.waltz.model.datatype.DataTypeDecorator)5 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)5 Collectors (java.util.stream.Collectors)4 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)4 EntityKind (org.finos.waltz.model.EntityKind)4 EntityReference (org.finos.waltz.model.EntityReference)4 Test (org.junit.jupiter.api.Test)4 java.util (java.util)3 Collections.emptyList (java.util.Collections.emptyList)3 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Collection (java.util.Collection)2 Collections.emptySet (java.util.Collections.emptySet)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 ListUtilities (org.finos.waltz.common.ListUtilities)2 ListUtilities.asList (org.finos.waltz.common.ListUtilities.asList)2