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");
}
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());
}
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;
}
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);
}
}
}
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'");
}
Aggregations