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