Search in sources :

Example 46 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class PhysicalSpecificationServiceTest method propagateDataTypesToLogicalFlows.

@Test
public void propagateDataTypesToLogicalFlows() {
    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");
    pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, username);
    assertThrows(IllegalArgumentException.class, () -> psSvc.propagateDataTypesToLogicalFlows(null, specId), "Should throw exception if username is null as cannot be logged");
    Long dt1Id = dtHelper.createDataType("dt1");
    Long dt2Id = dtHelper.createDataType("dt2");
    lfHelper.createLogicalFlowDecorators(flow.entityReference(), asSet(dt1Id));
    psSvc.propagateDataTypesToLogicalFlows(username, specId);
    List<DataTypeDecorator> lfDecorators = lfHelper.fetchDecoratorsForFlow(flow.entityReference().id());
    assertEquals(asSet(dt1Id), map(lfDecorators, DataTypeDecorator::dataTypeId), "Propagating does not remove data types from the logical");
    dtdSvc.updateDecorators(username, mkRef(EntityKind.PHYSICAL_SPECIFICATION, specId), asSet(dt1Id), emptySet());
    psSvc.propagateDataTypesToLogicalFlows(username, specId);
    assertEquals(asSet(dt1Id), map(lfDecorators, DataTypeDecorator::dataTypeId), "Can handle data types that already exist on the logical flow");
    dtdSvc.updateDecorators(username, mkRef(EntityKind.PHYSICAL_SPECIFICATION, specId), asSet(dt2Id), emptySet());
    psSvc.propagateDataTypesToLogicalFlows(username, specId);
    List<DataTypeDecorator> lfDecoratorsWithSpecDts = lfHelper.fetchDecoratorsForFlow(flow.entityReference().id());
    assertEquals(asSet(dt1Id, dt2Id), map(lfDecoratorsWithSpecDts, DataTypeDecorator::dataTypeId), "Adds data types that are not currently on the logical flow");
}
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 47 with EntityReference

use of org.finos.waltz.model.EntityReference 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 48 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class AssessmentsTest method createUpdateAndRemoveSingleRating.

@Test
public void createUpdateAndRemoveSingleRating() {
    String user = NameHelper.mkUserId("user");
    String name = NameHelper.mkName("testAssessment");
    String role = NameHelper.mkName("testRole");
    SchemeDetail schemeDetail = createScheme();
    AssessmentDefinition def = ImmutableAssessmentDefinition.builder().name(name).description("desc").isReadOnly(false).permittedRole(role).entityKind(EntityKind.APPLICATION).lastUpdatedBy(user).visibility(AssessmentVisibility.SECONDARY).ratingSchemeId(schemeDetail.id).build();
    long defId = definitionService.save(def);
    definitionService.save(ImmutableAssessmentDefinition.copyOf(def).withId(defId).withDescription("updated desc"));
    Collection<AssessmentDefinition> allDefs = definitionService.findAll();
    AssessmentDefinition found = find(d -> d.id().equals(Optional.of(defId)), allDefs).orElseThrow(AssertionError::new);
    assertEquals("updated desc", found.description());
    assertEquals(found, definitionService.getById(defId));
    EntityReference app1 = appHelper.createNewApp(NameHelper.mkName("app1"), ouIds.a);
    EntityReference app2 = appHelper.createNewApp(NameHelper.mkName("app2"), ouIds.b);
    SaveAssessmentRatingCommand cmd = ImmutableSaveAssessmentRatingCommand.builder().assessmentDefinitionId(defId).entityReference(app1).ratingId(schemeDetail.y).lastUpdatedBy(user).build();
    ratingService.store(cmd, user);
    changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(app1, Operation.ADD);
    assertNotNull(find(r -> r.assessmentDefinitionId() == defId && r.ratingId() == schemeDetail.y, ratingService.findForEntity(app1)));
    assertTrue(ratingService.findForEntity(app2).isEmpty());
    ratingService.store(ImmutableSaveAssessmentRatingCommand.copyOf(cmd).withRatingId(schemeDetail.n), user);
    changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(app1, Operation.UPDATE);
    assertNotNull(find(r -> r.assessmentDefinitionId() == defId && r.ratingId() == schemeDetail.n, ratingService.findForEntity(app1)));
    List<AssessmentRating> allRatingsAfterUpdate = ratingService.findByDefinitionId(defId);
    assertEquals(1, allRatingsAfterUpdate.size());
    assertTrue(find(r -> r.entityReference().equals(app1) && r.ratingId() == schemeDetail.n, allRatingsAfterUpdate).isPresent());
    ratingService.remove(ImmutableRemoveAssessmentRatingCommand.builder().assessmentDefinitionId(defId).entityReference(app1).lastUpdatedBy(user).build(), user);
    changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(app1, Operation.REMOVE);
    assertTrue(ratingService.findForEntity(app1).isEmpty());
    List<AssessmentRating> allRatingsAfterRemoval = ratingService.findByDefinitionId(defId);
    assertTrue(allRatingsAfterRemoval.isEmpty());
}
Also used : ImmutableSaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.ImmutableSaveAssessmentRatingCommand) SaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.SaveAssessmentRatingCommand) EntityKind(org.finos.waltz.model.EntityKind) AssessmentVisibility(org.finos.waltz.model.assessment_definition.AssessmentVisibility) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) Autowired(org.springframework.beans.factory.annotation.Autowired) ImmutableRemoveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.ImmutableRemoveAssessmentRatingCommand) RatingSchemeService(org.finos.waltz.service.rating_scheme.RatingSchemeService) ImmutableRatingSchemeItem(org.finos.waltz.model.rating.ImmutableRatingSchemeItem) AssessmentDefinition(org.finos.waltz.model.assessment_definition.AssessmentDefinition) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) ChangeLogHelper(org.finos.waltz.integration_test.inmem.helpers.ChangeLogHelper) Collection(java.util.Collection) AppHelper(org.finos.waltz.integration_test.inmem.helpers.AppHelper) NameHelper(org.finos.waltz.integration_test.inmem.helpers.NameHelper) RatingSchemeHelper(org.finos.waltz.integration_test.inmem.helpers.RatingSchemeHelper) AssessmentDefinitionService(org.finos.waltz.service.assessment_definition.AssessmentDefinitionService) Operation(org.finos.waltz.model.Operation) Test(org.junit.jupiter.api.Test) List(java.util.List) ImmutableAssessmentDefinition(org.finos.waltz.model.assessment_definition.ImmutableAssessmentDefinition) CollectionUtilities.find(org.finos.waltz.common.CollectionUtilities.find) Assertions(org.junit.jupiter.api.Assertions) EntityReference(org.finos.waltz.model.EntityReference) AssessmentRatingService(org.finos.waltz.service.assessment_rating.AssessmentRatingService) Optional(java.util.Optional) AssessmentDefinition(org.finos.waltz.model.assessment_definition.AssessmentDefinition) ImmutableAssessmentDefinition(org.finos.waltz.model.assessment_definition.ImmutableAssessmentDefinition) ImmutableSaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.ImmutableSaveAssessmentRatingCommand) SaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.SaveAssessmentRatingCommand) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 49 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class BookmarkGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    List<EntityReference> appRefs = dsl.select(APPLICATION.NAME, APPLICATION.ID).from(APPLICATION).fetch(r -> EntityReference.mkRef(EntityKind.APPLICATION, r.value2(), r.value1()));
    List<EntityReference> measurableRefs = dsl.select(MEASURABLE.NAME, MEASURABLE.ID).from(MEASURABLE).fetch(r -> EntityReference.mkRef(EntityKind.MEASURABLE, r.value2(), r.value1()));
    List<EntityReference> ouRefs = dsl.select(ORGANISATIONAL_UNIT.NAME, ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT).fetch(r -> EntityReference.mkRef(EntityKind.ORG_UNIT, r.value2(), r.value1()));
    List<EntityReference> appGroupRefs = dsl.select(APPLICATION_GROUP.NAME, APPLICATION_GROUP.ID).from(APPLICATION_GROUP).fetch(r -> EntityReference.mkRef(EntityKind.APP_GROUP, r.value2(), r.value1()));
    List<EntityReference> refs = ListUtilities.concat(appRefs, measurableRefs, ouRefs, appGroupRefs);
    List<BookmarkRecord> bookmarks = refs.stream().flatMap(r -> RandomUtilities.randomlySizedIntStream(2, 15).mapToObj(idx -> {
        BookmarkRecord record = dsl.newRecord(BOOKMARK);
        record.setParentKind(r.kind().name());
        record.setParentId(r.id());
        record.setTitle(mkText(r.name().get()));
        record.setDescription(mkText(r.name().get()));
        record.setKind(randomPick(bookmarkKinds));
        record.setUrl(mkUrl(r.name().get()));
        record.setProvenance(SAMPLE_DATA_PROVENANCE);
        record.setLastUpdatedBy("admin");
        record.setUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
        record.setCreatedAt(DateTimeUtilities.nowUtcTimestamp());
        return record;
    })).collect(Collectors.toList());
    dsl.batchStore(bookmarks).execute();
    return null;
}
Also used : APPLICATION(org.finos.waltz.schema.tables.Application.APPLICATION) EntityKind(org.finos.waltz.model.EntityKind) Random(java.util.Random) BookmarkRecord(org.finos.waltz.schema.tables.records.BookmarkRecord) BOOKMARK(org.finos.waltz.schema.tables.Bookmark.BOOKMARK) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) RandomUtilities(org.finos.waltz.common.RandomUtilities) List(java.util.List) ORGANISATIONAL_UNIT(org.finos.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) MEASURABLE(org.finos.waltz.schema.tables.Measurable.MEASURABLE) ListUtilities(org.finos.waltz.common.ListUtilities) Map(java.util.Map) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) APPLICATION_GROUP(org.finos.waltz.schema.tables.ApplicationGroup.APPLICATION_GROUP) EntityReference(org.finos.waltz.model.EntityReference) DSLContext(org.jooq.DSLContext) EntityReference(org.finos.waltz.model.EntityReference) DSLContext(org.jooq.DSLContext) BookmarkRecord(org.finos.waltz.schema.tables.records.BookmarkRecord)

Example 50 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class LogicalFlowStatsDao method getFlowInfoByDirection.

public Map<FlowDirection, Set<FlowInfo>> getFlowInfoByDirection(EntityReference ref, Long datatypeId) {
    Condition sourceAppCondition = lf.SOURCE_ENTITY_ID.eq(counterpart_app.ID).and(lf.SOURCE_ENTITY_KIND.eq(EntityKind.APPLICATION.name()));
    Condition sourceActorCondition = lf.SOURCE_ENTITY_ID.eq(counterpart_actor.ID).and(lf.SOURCE_ENTITY_KIND.eq(EntityKind.ACTOR.name()));
    Condition targetAppCondition = lf.TARGET_ENTITY_ID.eq(counterpart_app.ID).and(lf.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name()));
    Condition targetActorCondition = lf.TARGET_ENTITY_ID.eq(counterpart_actor.ID).and(lf.TARGET_ENTITY_KIND.eq(EntityKind.ACTOR.name()));
    Condition dataTypeCondition = datatypeId == null ? rollup_dt.PARENT_ID.isNull() : rollup_dt.PARENT_ID.eq(datatypeId);
    Condition isUpstream = lf.SOURCE_ENTITY_ID.eq(ref.id()).and(lf.SOURCE_ENTITY_KIND.eq(ref.kind().name()));
    Condition isDownstream = lf.TARGET_ENTITY_ID.eq(ref.id()).and(lf.TARGET_ENTITY_KIND.eq(ref.kind().name()));
    SelectConditionStep<Record11<Long, Long, String, Long, Long, String, String, Long, String, String, String>> sourceQry = mkDirectionalQuery(sourceAppCondition, sourceActorCondition, dataTypeCondition, isDownstream, INBOUND);
    SelectConditionStep<Record11<Long, Long, String, Long, Long, String, String, Long, String, String, String>> targetQry = mkDirectionalQuery(targetAppCondition, targetActorCondition, dataTypeCondition, isUpstream, OUTBOUND);
    SelectOrderByStep<Record11<Long, Long, String, Long, Long, String, String, Long, String, String, String>> unionedData = sourceQry.union(targetQry);
    return unionedData.fetch().stream().collect(groupingBy(record -> {
        String directionStr = record.get("direction", String.class);
        return FlowDirection.valueOf(directionStr);
    }, mapping(r -> {
        EntityReference rollupDtRef = mkRef(DATA_TYPE, r.get(rollup_dt.ID), r.get(rollup_dt.NAME));
        EntityReference actualDtRef = mkRef(DATA_TYPE, r.get(actual_dt.ID), r.get(actual_dt.NAME));
        EntityReference counterpartRef = mkRef(EntityKind.valueOf(r.get("counterpart_kind", String.class)), r.get("counterpart_id", Long.class), r.get("counterpart_name", String.class));
        return (FlowInfo) ImmutableFlowInfo.builder().classificationId(r.get(FLOW_CLASSIFICATION.ID)).rollupDataType(rollupDtRef).actualDataType(actualDtRef).counterpart(counterpartRef).flowEntityLifecycleStatus(EntityLifecycleStatus.valueOf(r.get(lf.ENTITY_LIFECYCLE_STATUS))).flowId(r.get(lf.ID)).build();
    }, toSet())));
}
Also used : org.finos.waltz.schema.tables(org.finos.waltz.schema.tables) DSL(org.jooq.impl.DSL) APPLICATION(org.finos.waltz.schema.tables.Application.APPLICATION) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) Tally(org.finos.waltz.model.tally.Tally) Autowired(org.springframework.beans.factory.annotation.Autowired) Supplier(java.util.function.Supplier) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) BigDecimal(java.math.BigDecimal) LOGICAL_FLOW(org.finos.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW) Future(java.util.concurrent.Future) DataType(org.finos.waltz.schema.tables.DataType) org.jooq(org.jooq) Map(java.util.Map) TallyPack(org.finos.waltz.model.tally.TallyPack) FlowDirection(org.finos.waltz.model.FlowDirection) Repository(org.springframework.stereotype.Repository) EntityLifecycleStatus(org.finos.waltz.model.EntityLifecycleStatus) ImmutableTally(org.finos.waltz.model.tally.ImmutableTally) Unchecked(org.jooq.lambda.Unchecked) JooqUtilities(org.finos.waltz.data.JooqUtilities) Set(java.util.Set) org.finos.waltz.model.logical_flow(org.finos.waltz.model.logical_flow) Collectors(java.util.stream.Collectors) DBExecutorPoolInterface(org.finos.waltz.data.DBExecutorPoolInterface) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) INBOUND(org.finos.waltz.model.FlowDirection.INBOUND) LogicalFlow(org.finos.waltz.schema.tables.LogicalFlow) EntityReference(org.finos.waltz.model.EntityReference) ImmutableTallyPack(org.finos.waltz.model.tally.ImmutableTallyPack) OUTBOUND(org.finos.waltz.model.FlowDirection.OUTBOUND) DATA_TYPE(org.finos.waltz.model.EntityKind.DATA_TYPE) REMOVED(org.finos.waltz.model.EntityLifecycleStatus.REMOVED) EntityReference(org.finos.waltz.model.EntityReference)

Aggregations

EntityReference (org.finos.waltz.model.EntityReference)114 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)55 Test (org.junit.jupiter.api.Test)55 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)40 EntityKind (org.finos.waltz.model.EntityKind)23 List (java.util.List)21 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)19 Autowired (org.springframework.beans.factory.annotation.Autowired)17 DataTypeDecorator (org.finos.waltz.model.datatype.DataTypeDecorator)16 Set (java.util.Set)14 Collection (java.util.Collection)13 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)13 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)10 IdSelectionOptions.mkOpts (org.finos.waltz.model.IdSelectionOptions.mkOpts)9 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)8 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)8 Bookmark (org.finos.waltz.model.bookmark.Bookmark)8 Collections.emptyList (java.util.Collections.emptyList)7 Collectors (java.util.stream.Collectors)7 CollectionUtilities.first (org.finos.waltz.common.CollectionUtilities.first)7