Search in sources :

Example 1 with DataTypeDecorator

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

the class DataTypeDecoratorServiceTest method findByEntityIdSelector.

@Test
public void findByEntityIdSelector() {
    String username = mkName("findByEntityIdSelector");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    IdSelectionOptions appOpts = mkOpts(a);
    assertThrows(IllegalArgumentException.class, () -> dtdSvc.findByEntityIdSelector(EntityKind.APPLICATION, appOpts), "If not logical flow kind or physical spec kind should throw exception");
    List<DataTypeDecorator> selectorForLfWhereNoDecorators = dtdSvc.findByEntityIdSelector(EntityKind.LOGICAL_DATA_FLOW, appOpts);
    assertEquals(emptyList(), selectorForLfWhereNoDecorators, "If no flows and decorators for selector returns empty list");
    LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
    Long dtId = dataTypeHelper.createDataType("findByEntityIdSelector");
    Long dtId2 = dataTypeHelper.createDataType("findByEntityIdSelector2");
    dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId, dtId2), emptySet());
    List<DataTypeDecorator> selectorWithDecorators = dtdSvc.findByEntityIdSelector(EntityKind.LOGICAL_DATA_FLOW, appOpts);
    assertEquals(asSet(dtId, dtId2), map(selectorWithDecorators, DataTypeDecorator::dataTypeId), "Returns all data types for flow selector");
    IdSelectionOptions flowOpts = mkOpts(flow.entityReference());
    List<DataTypeDecorator> selectorForPsWhereNoDecorators = dtdSvc.findByEntityIdSelector(EntityKind.PHYSICAL_SPECIFICATION, flowOpts);
    assertEquals(emptyList(), selectorForPsWhereNoDecorators, "If no flows and decorators for selector returns empty list");
    Long psId = psHelper.createPhysicalSpec(a, "findByEntityIdSelector");
    EntityReference specRef = mkRef(EntityKind.PHYSICAL_SPECIFICATION, psId);
    pfHelper.createPhysicalFlow(flow.entityReference().id(), psId, "findByEntityIdSelector");
    dtdSvc.updateDecorators(username, specRef, asSet(dtId, dtId2), emptySet());
    List<DataTypeDecorator> selectorForPs = dtdSvc.findByEntityIdSelector(EntityKind.PHYSICAL_SPECIFICATION, flowOpts);
    assertEquals(asSet(dtId, dtId2), map(selectorForPs, DataTypeDecorator::dataTypeId), "Returns all data types for spec selector");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with DataTypeDecorator

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

the class DataTypeDecoratorServiceTest method updateDecorators.

@Test
public void updateDecorators() {
    String username = mkName("updateDecorators");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
    assertThrows(IllegalArgumentException.class, () -> dtdSvc.updateDecorators(null, flow.entityReference(), emptySet(), emptySet()), "Throws exception if no username provided");
    assertThrows(IllegalArgumentException.class, () -> dtdSvc.updateDecorators(username, null, emptySet(), emptySet()), "Throws exception if no ref provided");
    assertThrows(UnsupportedOperationException.class, () -> dtdSvc.updateDecorators(username, mkRef(EntityKind.APPLICATION, -1L), emptySet(), emptySet()), "Throws exception if no unsupported ref provided");
    Long dtId = dataTypeHelper.createDataType("updateDecorators");
    Long dtId2 = dataTypeHelper.createDataType("updateDecorators2");
    Long dtId3 = dataTypeHelper.createDataType("updateDecorators3");
    dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId, dtId2), emptySet());
    Collection<DataTypeDecorator> flowDecorators = dtdSvc.findByFlowIds(asSet(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
    assertEquals(asSet(dtId, dtId2), map(flowDecorators, DataTypeDecorator::dataTypeId), "Adds data types that do not exist on flow");
    dtdSvc.updateDecorators(username, flow.entityReference(), emptySet(), asSet(dtId3));
    Collection<DataTypeDecorator> removeDtNotAssociated = dtdSvc.findByFlowIds(asSet(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
    assertEquals(asSet(dtId, dtId2), map(removeDtNotAssociated, DataTypeDecorator::dataTypeId), "Removing dt not associated does not change set of decorators");
    dtdSvc.updateDecorators(username, flow.entityReference(), emptySet(), asSet(dtId2));
    Collection<DataTypeDecorator> removedDatatype = dtdSvc.findByFlowIds(asSet(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
    assertEquals(asSet(dtId), map(removedDatatype, DataTypeDecorator::dataTypeId), "Removed associated datatype");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with DataTypeDecorator

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

the class DataTypeDecoratorServiceTest method findByEntityId.

@Test
public void findByEntityId() {
    String username = mkName("getByEntityRefAndDataTypeId");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    assertThrows(IllegalArgumentException.class, () -> dtdSvc.findByEntityId(a), "If unsupported kind id throws exception");
    LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
    List<DataTypeDecorator> flowWithNoDts = dtdSvc.findByEntityId(flow.entityReference());
    assertEquals(emptyList(), flowWithNoDts, "If flow has no data types returns empty list");
    Long psId = psHelper.createPhysicalSpec(a, "getByEntityRefAndDataTypeId");
    EntityReference specRef = mkRef(EntityKind.PHYSICAL_SPECIFICATION, psId);
    List<DataTypeDecorator> specWithNoDts = dtdSvc.findByEntityId(specRef);
    assertEquals(emptyList(), specWithNoDts, "If spec has no data types returns empty list");
    Long dtId = dataTypeHelper.createDataType("getByEntityRefAndDataTypeId");
    Long dtId2 = dataTypeHelper.createDataType("getByEntityRefAndDataTypeId2");
    Long dtId3 = dataTypeHelper.createDataType("getByEntityRefAndDataTypeId3");
    dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId, dtId2, dtId3), emptySet());
    List<DataTypeDecorator> flowDecorators = dtdSvc.findByEntityId(flow.entityReference());
    assertEquals(asSet(dtId, dtId2, dtId3), map(flowDecorators, DataTypeDecorator::dataTypeId), "Returns all data types on flow");
    dtdSvc.updateDecorators(username, specRef, asSet(dtId, dtId2, dtId3), emptySet());
    List<DataTypeDecorator> specDecorators = dtdSvc.findByEntityId(specRef);
    assertEquals(asSet(dtId, dtId2, dtId3), map(specDecorators, DataTypeDecorator::dataTypeId), "Returns all data types on spec");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with DataTypeDecorator

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

the class DataTypeDecoratorServiceTest method getByEntityRefAndDataTypeId.

@Test
public void getByEntityRefAndDataTypeId() {
    String username = mkName("getByEntityRefAndDataTypeId");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    assertThrows(IllegalArgumentException.class, () -> dtdSvc.getByEntityRefAndDataTypeId(a, 1L), "If unsupported kind id throws exception");
    LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
    DataTypeDecorator noDt = dtdSvc.getByEntityRefAndDataTypeId(flow.entityReference(), -1L);
    assertNull(noDt, "Returns null no match for dt on flow");
    Long dtId = dataTypeHelper.createDataType("getByEntityRefAndDataTypeId");
    dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId), emptySet());
    DataTypeDecorator dataTypeDecorator = dtdSvc.getByEntityRefAndDataTypeId(flow.entityReference(), dtId);
    assertEquals(dtId, Long.valueOf(dataTypeDecorator.dataTypeId()), "Returns datatype if exists on flow");
    Long psId = psHelper.createPhysicalSpec(a, "getByEntityRefAndDataTypeId");
    EntityReference specRef = mkRef(EntityKind.PHYSICAL_SPECIFICATION, psId);
    dtdSvc.updateDecorators(username, specRef, asSet(dtId), emptySet());
    DataTypeDecorator specDtd = dtdSvc.getByEntityRefAndDataTypeId(specRef, dtId);
    assertEquals(dtId, Long.valueOf(specDtd.dataTypeId()), "Returns datatype if exists on spec");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with DataTypeDecorator

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

the class DataTypeDecoratorService method mkDecorators.

private Collection<DataTypeDecorator> mkDecorators(String userName, EntityReference entityReference, Set<Long> dataTypeIds) {
    if (LOGICAL_DATA_FLOW.equals(entityReference.kind())) {
        Collection<DataTypeDecorator> decorators = map(dataTypeIds, dtId -> mkDecorator(userName, entityReference, dtId, Optional.of(AuthoritativenessRatingValue.NO_OPINION)));
        LogicalFlow flow = logicalFlowDao.getByFlowId(entityReference.id());
        boolean requiresRating = flow.source().kind() == APPLICATION && flow.target().kind() == APPLICATION;
        return requiresRating ? ratingsCalculator.calculate(decorators) : decorators;
    }
    return map(dataTypeIds, dtId -> mkDecorator(userName, entityReference, dtId, Optional.empty()));
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) ImmutableDataTypeDecorator(org.finos.waltz.model.datatype.ImmutableDataTypeDecorator)

Aggregations

DataTypeDecorator (org.finos.waltz.model.datatype.DataTypeDecorator)12 EntityReference (org.finos.waltz.model.EntityReference)11 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)10 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)6 Test (org.junit.jupiter.api.Test)5 Collectors (java.util.stream.Collectors)3 DataTypeDao (org.finos.waltz.data.data_type.DataTypeDao)3 EntityKind (org.finos.waltz.model.EntityKind)3 DataType (org.finos.waltz.model.datatype.DataType)3 LocalDateTime (java.time.LocalDateTime)2 java.util (java.util)2 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)2 SetUtilities.fromCollection (org.finos.waltz.common.SetUtilities.fromCollection)2 ApplicationIdSelectorFactory (org.finos.waltz.data.application.ApplicationIdSelectorFactory)2 LogicalFlowDecoratorDao (org.finos.waltz.data.datatype_decorator.LogicalFlowDecoratorDao)2 LogicalFlowDao (org.finos.waltz.data.logical_flow.LogicalFlowDao)2 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)2 Application (org.finos.waltz.model.application.Application)2 ImmutableDataTypeDecorator (org.finos.waltz.model.datatype.ImmutableDataTypeDecorator)2 Logger (org.slf4j.Logger)2