Search in sources :

Example 41 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.

the class PhysicalSpecificationServiceTest method isUsed.

@Test
public void isUsed() {
    assertThrows(IllegalArgumentException.class, () -> psSvc.isUsed(null), "Specification id must not be null");
    String username = mkName("propagateDataTypesToLogicalFlows");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
    Long specId = psHelper.createPhysicalSpec(a, "findByEntityReference");
    assertFalse(psSvc.isUsed(specId), "Should return false when so physical flows");
    PhysicalFlowCreateCommandResponse physicalFlow = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, username);
    assertTrue(psSvc.isUsed(specId), "Should return false when associated physical flows");
    pfHelper.deletePhysicalFlow(physicalFlow.entityReference().id());
    assertFalse(psSvc.isUsed(specId), "Should return false when all physical flows are removed");
}
Also used : PhysicalFlowCreateCommandResponse(org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 42 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.

the class ChangeUnitViewService method findPhysicalFlowChangeUnitsByChangeSetId.

public Set<PhysicalFlowChangeUnitViewItem> findPhysicalFlowChangeUnitsByChangeSetId(long changeSetId) {
    IdSelectionOptions idSelectionOptions = mkOptsForAllLifecycleStates(mkRef(EntityKind.CHANGE_SET, changeSetId), HierarchyQueryScope.EXACT);
    Collection<PhysicalFlow> physicalFlows = physicalFlowService.findBySelector(idSelectionOptions);
    Collection<PhysicalSpecification> physicalSpecs = physicalSpecificationService.findByIds(map(physicalFlows, PhysicalFlow::specificationId));
    // TODO: Move to a logical flow selector based upon change set #5626
    Collection<LogicalFlow> logicalFlows = logicalFlowService.findAllByFlowIds(map(physicalFlows, PhysicalFlow::logicalFlowId));
    List<AssessmentRating> assessmentRatings = assessmentRatingService.findByTargetKindForRelatedSelector(EntityKind.CHANGE_UNIT, idSelectionOptions);
    Map<Long, RatingSchemeItem> ratingSchemeItemsById = indexBy(ratingSchemeService.getAllRatingSchemeItems(), item -> item.id().get());
    Map<Long, PhysicalFlow> physicalFlowsById = indexBy(physicalFlows, flow -> flow.id().get());
    Map<Long, LogicalFlow> logicalFlowsById = indexBy(logicalFlows, flow -> flow.id().get());
    Map<Long, PhysicalSpecification> specsById = indexBy(physicalSpecs, spec -> spec.id().get());
    Map<Long, Collection<AssessmentRating>> assessmentRatingsByEntityId = groupBy(rating -> rating.entityReference().id(), assessmentRatings);
    List<ChangeUnit> changeUnits = changeUnitService.findByChangeSetId(changeSetId);
    return changeUnits.stream().filter(cu -> cu.subjectEntity().kind().equals(EntityKind.PHYSICAL_FLOW)).map(cu -> {
        PhysicalFlow physicalFlow = physicalFlowsById.get(cu.subjectEntity().id());
        PhysicalSpecification spec = specsById.get(physicalFlow.specificationId());
        LogicalFlow logicalFlow = logicalFlowsById.get(physicalFlow.logicalFlowId());
        Long changeUnitId = cu.id().get();
        Collection<AssessmentRating> assessmentRatingsForChangeUnit = assessmentRatingsByEntityId.getOrDefault(changeUnitId, emptySet());
        Set<AssessmentRatingDetail> assessmentRatingDetailForChangeUnit = map(assessmentRatingsForChangeUnit, rating -> mkAssessmentDefinitionDetail(rating, ratingSchemeItemsById.get(rating.ratingId())));
        return ImmutablePhysicalFlowChangeUnitViewItem.builder().changeUnit(cu).physicalSpecification(spec).logicalFlow(logicalFlow).assessments(assessmentRatingDetailForChangeUnit).build();
    }).collect(toSet());
}
Also used : ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) PhysicalSpecificationService(org.finos.waltz.service.physical_specification.PhysicalSpecificationService) EntityKind(org.finos.waltz.model.EntityKind) PhysicalFlowChangeUnitViewItem(org.finos.waltz.model.change_unit.PhysicalFlowChangeUnitViewItem) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) Autowired(org.springframework.beans.factory.annotation.Autowired) RatingSchemeService(org.finos.waltz.service.rating_scheme.RatingSchemeService) AssessmentRatingDetail(org.finos.waltz.model.assessment_rating.AssessmentRatingDetail) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) ImmutablePhysicalFlowChangeUnitViewItem(org.finos.waltz.model.change_unit.ImmutablePhysicalFlowChangeUnitViewItem) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) Service(org.springframework.stereotype.Service) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) Map(java.util.Map) LogicalFlowService(org.finos.waltz.service.logical_flow.LogicalFlowService) Collectors.toSet(java.util.stream.Collectors.toSet) IdSelectionOptions.mkOptsForAllLifecycleStates(org.finos.waltz.model.IdSelectionOptions.mkOptsForAllLifecycleStates) PhysicalFlowService(org.finos.waltz.service.physical_flow.PhysicalFlowService) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Collections.emptySet(java.util.Collections.emptySet) Collection(java.util.Collection) Set(java.util.Set) MapUtilities.indexBy(org.finos.waltz.common.MapUtilities.indexBy) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) AssessmentRatingService(org.finos.waltz.service.assessment_rating.AssessmentRatingService) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) ImmutableAssessmentRatingDetail(org.finos.waltz.model.assessment_rating.ImmutableAssessmentRatingDetail) HierarchyQueryScope(org.finos.waltz.model.HierarchyQueryScope) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) Collectors.toSet(java.util.stream.Collectors.toSet) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) Collection(java.util.Collection) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Example 43 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.

the class PhysicalFlowUploadService method getOrCreateLogicalFlow.

private LogicalFlow getOrCreateLogicalFlow(EntityReference source, EntityReference target, EntityReference dataType, String username) {
    LogicalFlow flow = logicalFlowDao.getBySourceAndTarget(source, target);
    if (flow == null) {
        LocalDateTime now = nowUtc();
        LogicalFlow flowToAdd = ImmutableLogicalFlow.builder().source(source).target(target).lastUpdatedBy(username).lastUpdatedAt(now).provenance("waltz").created(UserTimestamp.mkForUser(username, now)).build();
        flow = logicalFlowDao.addFlow(flowToAdd);
    }
    EntityReference logicalFlowEntityRef = EntityReference.mkRef(EntityKind.LOGICAL_DATA_FLOW, flow.id().get());
    DataTypeDecorator existingDecorator = dataTypeDecoratorService.getByEntityRefAndDataTypeId(logicalFlowEntityRef, dataType.id());
    if (existingDecorator == null) {
        dataTypeDecoratorService.addDecorators(username, logicalFlowEntityRef, fromArray(dataType.id()));
    }
    return flow;
}
Also used : LocalDateTime(java.time.LocalDateTime) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) ImmutableLogicalFlow(org.finos.waltz.model.logical_flow.ImmutableLogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference)

Example 44 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.

the class PhysicalFlowParticipantService method writeToAuditLog.

// --- helpers ---
private void writeToAuditLog(String verb, long physicalFlowId, EntityReference participant, String username) {
    nameResolver.resolve(participant).ifPresent(p -> {
        String msg = format("%s participant: [%s] to physical flow", verb, p.name().orElse("?"));
        auditChange(msg, EntityReference.mkRef(PHYSICAL_FLOW, physicalFlowId), username, Operation.ADD);
    });
    PhysicalFlow physicalFlow = physicalFlowService.getById(physicalFlowId);
    if (physicalFlow != null) {
        LogicalFlow logicalFlow = logicalFlowService.getById(physicalFlow.logicalFlowId());
        PhysicalSpecification specification = physicalSpecificationService.getById(physicalFlow.specificationId());
        if (logicalFlow != null && specification != null) {
            auditChange(format("%s as a participant to flow: (%s) -[%s]-> (%s)", verb, logicalFlow.source().name().orElse("?"), specification.name(), logicalFlow.target().name().orElse("?")), participant, username, Operation.ADD);
        }
    }
}
Also used : PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow)

Example 45 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.

the class LogicalFlowServiceTest method cleanupOrphans.

@Test
public void cleanupOrphans() {
    helper.clearAllFlows();
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    EntityReference c = appHelper.createNewApp("c", ouIds.b);
    LogicalFlow ab = helper.createLogicalFlow(a, b);
    LogicalFlow ac = helper.createLogicalFlow(a, c);
    LogicalFlow ca = helper.createLogicalFlow(c, a);
    int flowsRemoved = lfSvc.cleanupOrphans();
    assertEquals(0, flowsRemoved, "No flows removed if all apps are active");
    appHelper.removeApp(c.id());
    int flowsRemovedAfterAppRemoved = lfSvc.cleanupOrphans();
    assertEquals(2, flowsRemovedAfterAppRemoved, "Flows removed where either source or target is retired");
    LogicalFlow flowWhereTargetRemoved = lfSvc.getById(ac.id().get());
    assertEquals(EntityLifecycleStatus.REMOVED, flowWhereTargetRemoved.entityLifecycleStatus(), "If target removed, flow still exists but has entity lifecycle status of 'REMOVED'");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)72 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)52 Test (org.junit.jupiter.api.Test)52 EntityReference (org.finos.waltz.model.EntityReference)40 PhysicalSpecification (org.finos.waltz.model.physical_specification.PhysicalSpecification)21 ImmutablePhysicalSpecification (org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification)15 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)13 DataTypeDecorator (org.finos.waltz.model.datatype.DataTypeDecorator)13 LogicalFlowService (org.finos.waltz.service.logical_flow.LogicalFlowService)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13 Collections.emptyList (java.util.Collections.emptyList)12 List (java.util.List)12 SetUtilities.map (org.finos.waltz.common.SetUtilities.map)12 Collection (java.util.Collection)11 IdSelectionOptions.mkOpts (org.finos.waltz.model.IdSelectionOptions.mkOpts)11 Collections.emptySet (java.util.Collections.emptySet)10 SetUtilities.asSet (org.finos.waltz.common.SetUtilities.asSet)10 Assertions (org.junit.jupiter.api.Assertions)10 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)9 org.finos.waltz.integration_test.inmem.helpers (org.finos.waltz.integration_test.inmem.helpers)9