Search in sources :

Example 11 with PhysicalSpecification

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);
        }
    }
}
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 12 with PhysicalSpecification

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");
}
Also used : ImmutablePhysicalSpecification(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) ImmutablePhysicalSpecification(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 13 with PhysicalSpecification

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");
}
Also used : ImmutablePhysicalSpecification(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 14 with PhysicalSpecification

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");
}
Also used : ImmutablePhysicalSpecification(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 15 with PhysicalSpecification

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");
}
Also used : ImmutablePhysicalSpecification(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

PhysicalSpecification (org.finos.waltz.model.physical_specification.PhysicalSpecification)21 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)16 ImmutablePhysicalSpecification (org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification)13 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)9 Test (org.junit.jupiter.api.Test)9 PhysicalFlow (org.finos.waltz.model.physical_flow.PhysicalFlow)4 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)3 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 String.format (java.lang.String.format)2 LocalDateTime (java.time.LocalDateTime)2 Collection (java.util.Collection)2 List (java.util.List)2 Set (java.util.Set)2 DateTimeUtilities.nowUtc (org.finos.waltz.common.DateTimeUtilities.nowUtc)2 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)2 StringUtilities.isEmpty (org.finos.waltz.common.StringUtilities.isEmpty)2 PhysicalFlowDao (org.finos.waltz.data.physical_flow.PhysicalFlowDao)2 org.finos.waltz.model (org.finos.waltz.model)2