use of org.finos.waltz.model.physical_specification.PhysicalSpecification 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.physical_specification.PhysicalSpecification in project waltz by khartec.
the class PhysicalFlowServiceTest method create_canCreateNewSpecIfRequired.
@Test
public void create_canCreateNewSpecIfRequired() {
String username = mkName("createWillCreateSpecIfRequired");
EntityReference a = appHelper.createNewApp(mkName("a"), ouIds.a);
EntityReference b = appHelper.createNewApp(mkName("b"), ouIds.a1);
LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
String specExtId = mkName("createWillCreateSpecIfRequired");
ImmutablePhysicalSpecification newSpec = ImmutablePhysicalSpecification.builder().externalId(specExtId).owningEntity(a).name(specExtId).description(specExtId).format(DataFormatKind.UNKNOWN).lastUpdatedBy(username).isRemoved(false).created(UserTimestamp.mkForUser(username, DateTimeUtilities.nowUtcTimestamp())).build();
ImmutableFlowAttributes flowAttrs = ImmutableFlowAttributes.builder().frequency(FrequencyKind.DAILY).criticality(Criticality.MEDIUM).transport(TransportKindValue.UNKNOWN).basisOffset(0).build();
ImmutablePhysicalFlowCreateCommand createCommand = ImmutablePhysicalFlowCreateCommand.builder().logicalFlowId(ab.entityReference().id()).specification(newSpec).flowAttributes(flowAttrs).build();
PhysicalFlowCreateCommandResponse firstCreateResp = pfSvc.create(createCommand, username);
assertEquals(CommandOutcome.SUCCESS, firstCreateResp.outcome(), "Successfully creates flow when new spec needs to be created");
PhysicalFlow newPhysFlow = pfSvc.getById(firstCreateResp.entityReference().id());
PhysicalSpecification createdSpec = psSvc.getById(newPhysFlow.specificationId());
assertEquals(specExtId, createdSpec.externalId().get(), "Specification associated to new flow has the correct external id");
assertEquals(username, createdSpec.created().get().by(), "Specification associated to flow has the correct user against it");
}
use of org.finos.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.
the class PhysicalFlowServiceTest method merge.
@Test
public void merge() {
EntityReference a = appHelper.createNewApp(mkName("a"), ouIds.a);
EntityReference b = appHelper.createNewApp(mkName("b"), ouIds.a1);
LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
Long specId = psHelper.createPhysicalSpec(a, mkName("merge"));
Long specId2 = psHelper.createPhysicalSpec(a, mkName("merge2"));
PhysicalFlowCreateCommandResponse firstFlowCreateResp = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId, mkName("merge"));
PhysicalFlowCreateCommandResponse secondFlowCreateResp = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId2, mkName("merge"));
pfHelper.updateExternalIdOnFlowDirectly(firstFlowCreateResp.entityReference().id(), "merge");
boolean merge = pfSvc.merge(firstFlowCreateResp.entityReference().id(), secondFlowCreateResp.entityReference().id(), mkName("merge"));
List<PhysicalFlow> flowsWithMergeExtId = pfSvc.findByExternalId("merge");
PhysicalFlow firstFlowAfterUpdate = pfSvc.getById(firstFlowCreateResp.entityReference().id());
assertTrue(firstFlowAfterUpdate.isRemoved(), "Once merged the original flow should no longer be active");
assertTrue(map(flowsWithMergeExtId, d -> d.entityReference().id()).contains(secondFlowCreateResp.entityReference().id()), "Once merged the second flow should have the external id of the original");
PhysicalSpecification specAfterUpdate = psSvc.getById(specId);
assertTrue(specAfterUpdate.isRemoved(), "If last remaining flow spec should be removed");
}
use of org.finos.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.
the class PhysicalFlowServiceTest method create_ifDuplicateFlowWillReturnFailureWithMessage.
@Test
public void create_ifDuplicateFlowWillReturnFailureWithMessage() {
String username = mkName("createIfDuplicateFlowWillReturnFailureWithMessage");
EntityReference a = appHelper.createNewApp(mkName("a"), ouIds.a);
EntityReference b = appHelper.createNewApp(mkName("b"), ouIds.a1);
LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
Long specId = psHelper.createPhysicalSpec(a, mkName("createIfDuplicateFlowWillReturnFailureWithMessage"));
PhysicalSpecification spec = psSvc.getById(specId);
ImmutableFlowAttributes flowAttrs = ImmutableFlowAttributes.builder().frequency(FrequencyKind.DAILY).criticality(Criticality.MEDIUM).transport(TransportKindValue.UNKNOWN).basisOffset(0).build();
ImmutablePhysicalFlowCreateCommand createCommand = ImmutablePhysicalFlowCreateCommand.builder().logicalFlowId(ab.entityReference().id()).specification(spec).flowAttributes(flowAttrs).build();
ImmutablePhysicalFlowCreateCommand createCommand2 = ImmutablePhysicalFlowCreateCommand.builder().logicalFlowId(ab.entityReference().id()).specification(spec).flowAttributes(flowAttrs).build();
PhysicalFlowCreateCommandResponse firstCreateResp = pfSvc.create(createCommand, username);
assertEquals(CommandOutcome.SUCCESS, firstCreateResp.outcome(), "Successfully creates flow when new");
PhysicalFlowCreateCommandResponse secondCreateResp = pfSvc.create(createCommand2, username);
assertEquals(CommandOutcome.FAILURE, secondCreateResp.outcome(), "Fails to create flow when a similar one is already active");
assertTrue(secondCreateResp.message().map(msg -> msg.equalsIgnoreCase("Duplicate with existing flow")).orElse(false), "Failure message advises user that there is an existing flow");
}
use of org.finos.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.
the class PhysicalFlowServiceTest method merge_ifSpecShareByMultipleFlowsShouldNotBeRemoved.
@Test
public void merge_ifSpecShareByMultipleFlowsShouldNotBeRemoved() {
EntityReference a = appHelper.createNewApp(mkName("a"), ouIds.a);
EntityReference b = appHelper.createNewApp(mkName("b"), ouIds.a1);
EntityReference c = appHelper.createNewApp(mkName("b"), ouIds.a1);
LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
LogicalFlow bc = lfHelper.createLogicalFlow(b, c);
Long specId = psHelper.createPhysicalSpec(a, mkName("merge"));
Long specId2 = psHelper.createPhysicalSpec(a, mkName("merge2"));
PhysicalFlowCreateCommandResponse firstFlowCreateResp = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId, mkName("merge"));
PhysicalFlowCreateCommandResponse secondFlowCreateResp = pfHelper.createPhysicalFlow(bc.entityReference().id(), specId, mkName("merge"));
PhysicalFlowCreateCommandResponse thirdFlowCreateResp = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId2, mkName("merge"));
boolean merge = pfSvc.merge(firstFlowCreateResp.entityReference().id(), thirdFlowCreateResp.entityReference().id(), mkName("merge"));
PhysicalSpecification specAfterUpdate = psSvc.getById(specId);
assertFalse(specAfterUpdate.isRemoved(), "If other flows share the spec it should not be removed after the merge");
}
Aggregations