Skip to content

Commit

Permalink
Pull request #361: Fcr rule updates
Browse files Browse the repository at this point in the history
Merge in WALTZ/waltz from WALTZ/waltz-jws:fcr-rule-updates to db-feature/waltz-7036-flow-classification-rules-inbound

* commit '9d6e6a5c74ab11bf6b9b481e15e47224cf2d0ead':
  New EntityHierarchy immutable which can findAncestors and findChildren upon a list of EntityHierarchyItem
  Additional tests to cover the point-to-point flows and inbound rules
  Update rule calculator to do both inbound and outbound rules as well as point-to-point flows
  Update rule calculator to do both inbound and outbound rules as well as point-to-point flows
  Update rule calculator to do both inbound and outbound rules as well as point-to-point flows
  Update rule calculator to do both inbound and outbound rules as well as point-to-point flows
  Update rule calculator to do both inbound and outbound rules
  Update rule calcualtor to do both inbound and outbound rules
  • Loading branch information
jessica-woodland-scott-db authored and db-waltz committed Apr 9, 2024
2 parents ca36aa7 + 9d6e6a5 commit c1f5aae
Show file tree
Hide file tree
Showing 18 changed files with 1,116 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@
import org.finos.waltz.model.EntityReference;
import org.finos.waltz.model.datatype.DataTypeDecorator;
import org.finos.waltz.model.datatype.DataTypeUsageCharacteristics;
import org.finos.waltz.model.datatype.FlowDataType;
import org.finos.waltz.model.datatype.ImmutableDataTypeDecorator;
import org.finos.waltz.model.datatype.ImmutableDataTypeUsageCharacteristics;
import org.finos.waltz.model.datatype.ImmutableFlowDataType;
import org.finos.waltz.model.flow_classification_rule.FlowClassificationRuleVantagePoint;
import org.finos.waltz.model.rating.AuthoritativenessRatingValue;
import org.finos.waltz.schema.Tables;
import org.finos.waltz.schema.tables.Application;
import org.finos.waltz.schema.tables.EntityHierarchy;
import org.finos.waltz.schema.tables.LogicalFlow;
import org.finos.waltz.schema.tables.LogicalFlowDecorator;
import org.finos.waltz.schema.tables.records.LogicalFlowDecoratorRecord;
import org.jooq.Condition;
Expand Down Expand Up @@ -57,6 +63,7 @@
import static java.util.stream.Collectors.toList;
import static org.finos.waltz.common.Checks.checkNotNull;
import static org.finos.waltz.common.ListUtilities.newArrayList;
import static org.finos.waltz.data.JooqUtilities.readRef;
import static org.finos.waltz.data.logical_flow.LogicalFlowDao.LOGICAL_NOT_REMOVED;
import static org.finos.waltz.model.EntityKind.DATA_TYPE;
import static org.finos.waltz.model.EntityKind.LOGICAL_DATA_FLOW;
Expand All @@ -72,6 +79,12 @@
@Repository
public class LogicalFlowDecoratorDao extends DataTypeDecoratorDao {

private static final LogicalFlow lf = Tables.LOGICAL_FLOW;
private static final LogicalFlowDecorator lfd = Tables.LOGICAL_FLOW_DECORATOR;
private static final Application srcApp = Tables.APPLICATION.as("srcApp");
private static final Application targetApp = Tables.APPLICATION.as("targetApp");
private static final EntityHierarchy eh = Tables.ENTITY_HIERARCHY;

private static final Field<String> ENTITY_NAME_FIELD = InlineSelectFieldFactory.mkNameField(
LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_ID,
LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_KIND,
Expand Down Expand Up @@ -384,6 +397,59 @@ public int updateRatingsByCondition(AuthoritativenessRatingValue rating, Conditi
.execute();
}

public int resetRatingsAndFlowClassificationRulesCondition(Condition condition) {
return dsl
.update(LOGICAL_FLOW_DECORATOR)
.set(LOGICAL_FLOW_DECORATOR.RATING, AuthoritativenessRatingValue.NO_OPINION.value())
.setNull(LOGICAL_FLOW_DECORATOR.FLOW_CLASSIFICATION_RULE_ID)
.setNull(LOGICAL_FLOW_DECORATOR.INBOUND_FLOW_CLASSIFICATION_RULE_ID)
.where(condition)
.execute();
}

public Set<FlowDataType> fetchFlowDataTypePopulationForFlowSelector(Select<Record1<Long>> flowSelector) {
Condition lfSelectorCondition = lf.ID.in(flowSelector);
return fetchFlowDataTypePopulation(lfSelectorCondition);
}

public Set<FlowDataType> fetchFlowDataTypePopulation(Condition condition) {
return dsl
.select(lf.ID,
lfd.ID,
lfd.DECORATOR_ENTITY_ID,
lfd.INBOUND_FLOW_CLASSIFICATION_RULE_ID,
lfd.FLOW_CLASSIFICATION_RULE_ID,
lf.SOURCE_ENTITY_ID,
lf.SOURCE_ENTITY_KIND,
lf.TARGET_ENTITY_ID,
lf.TARGET_ENTITY_KIND,
srcApp.ORGANISATIONAL_UNIT_ID,
targetApp.ORGANISATIONAL_UNIT_ID,
lfd.RATING,
lfd.TARGET_INBOUND_RATING)
.from(lf)
.innerJoin(lfd).on(lfd.LOGICAL_FLOW_ID.eq(lf.ID).and(lfd.DECORATOR_ENTITY_KIND.eq(EntityKind.DATA_TYPE.name())))
.leftJoin(srcApp).on(srcApp.ID.eq(lf.SOURCE_ENTITY_ID).and(lf.SOURCE_ENTITY_KIND.eq(EntityKind.APPLICATION.name())))
.leftJoin(targetApp).on(targetApp.ID.eq(lf.TARGET_ENTITY_ID).and(lf.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name())))
.where(lf.IS_REMOVED.isFalse()
.and(lf.ENTITY_LIFECYCLE_STATUS.eq(EntityLifecycleStatus.ACTIVE.name())))
.and(condition)
.fetchSet(r -> ImmutableFlowDataType
.builder()
.lfdId(r.get(lfd.ID))
.dtId(r.get(lfd.DECORATOR_ENTITY_ID))
.lfId(r.get(lf.ID))
.source(readRef(r, lf.SOURCE_ENTITY_KIND, lf.SOURCE_ENTITY_ID))
.target(readRef(r, lf.TARGET_ENTITY_KIND, lf.TARGET_ENTITY_ID))
.inboundRuleId(r.get(lfd.INBOUND_FLOW_CLASSIFICATION_RULE_ID))
.outboundRuleId(r.get(lfd.FLOW_CLASSIFICATION_RULE_ID))
.sourceOuId(r.get(srcApp.ORGANISATIONAL_UNIT_ID))
.targetOuId(r.get(targetApp.ORGANISATIONAL_UNIT_ID))
.sourceOutboundRating(AuthoritativenessRatingValue.of(r.get(lfd.RATING)))
.targetInboundRating(AuthoritativenessRatingValue.of(r.get(lfd.TARGET_INBOUND_RATING)))
.build());
}


// --- HELPERS ---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jooq.Record;
import org.jooq.RecordMapper;
import org.jooq.impl.DSL;
import org.jooq.lambda.tuple.Tuple2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -42,6 +43,7 @@
import static org.finos.waltz.schema.tables.EntityHierarchy.ENTITY_HIERARCHY;
import static org.finos.waltz.common.Checks.checkNotNull;
import static org.finos.waltz.common.ListUtilities.map;
import static org.jooq.lambda.tuple.Tuple.tuple;

@Repository
public class EntityHierarchyDao {
Expand Down Expand Up @@ -145,4 +147,11 @@ public List<EntityHierarchyItem> findDesendents(EntityReference ref) {
.fetch(TO_DOMAIN_MAPPER);
}

public List<EntityHierarchyItem> fetchHierarchyForKind(EntityKind kind) {
return dsl
.select(eh.fields())
.from(eh)
.where(eh.KIND.eq(kind.name()))
.fetch(TO_DOMAIN_MAPPER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import org.finos.waltz.model.flow_classification_rule.ImmutableFlowClassificationRuleVantagePoint;
import org.finos.waltz.model.rating.AuthoritativenessRatingValue;
import org.finos.waltz.schema.tables.Application;
import org.finos.waltz.schema.tables.DataType;
import org.finos.waltz.schema.tables.EntityHierarchy;
import org.finos.waltz.schema.tables.records.FlowClassificationRuleRecord;
import org.finos.waltz.schema.tables.records.LogicalFlowDecoratorRecord;
import org.jooq.AggregateFunction;
import org.jooq.Condition;
import org.jooq.DSLContext;
Expand All @@ -44,15 +46,16 @@
import org.jooq.Record1;
import org.jooq.Record2;
import org.jooq.Record3;
import org.jooq.Record8;
import org.jooq.Record9;
import org.jooq.RecordMapper;
import org.jooq.Result;
import org.jooq.Select;
import org.jooq.SelectConditionStep;
import org.jooq.SelectOnConditionStep;
import org.jooq.SelectSeekStep2;
import org.jooq.SelectSeekStep3;
import org.jooq.SelectSeekStep4;
import org.jooq.SelectSeekStep5;
import org.jooq.SelectSeekStep6;
import org.jooq.UpdateConditionStep;
import org.jooq.UpdateSetMoreStep;
import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -103,8 +106,10 @@ public class FlowClassificationRuleDao {
private final static org.finos.waltz.schema.tables.DataType declaredDataType = org.finos.waltz.schema.tables.DataType.DATA_TYPE.as("declaredDataType");
private final static org.finos.waltz.schema.tables.DataType impliedDataType = org.finos.waltz.schema.tables.DataType.DATA_TYPE.as("impliedDataType");

private final static Field<Long> targetOrgUnitId = ehOrgUnit.ID.as("targetOrgUnitId");
private final static Field<Long> declaredOrgUnitId = ehOrgUnit.ID.as("declaredOrgUnitId");
public static final Field<Long> vantagePointId = DSL.coalesce(ehOrgUnit.ID, FLOW_CLASSIFICATION_RULE.PARENT_ID);
private final static Field<Integer> declaredOrgUnitLevel = ehOrgUnit.LEVEL.as("declaredOrgUnitLevel");
public static final Field<Integer> vantagePointLevel = DSL.coalesce(ehOrgUnit.LEVEL, 0).as("parentLevel");
private final static Field<Long> declaredDataTypeId = ehDataType.ID.as("declaredDataTypeId");
private final static Field<Integer> declaredDataTypeLevel = ehDataType.LEVEL.as("declaredDataTypeLevel");

Expand Down Expand Up @@ -170,11 +175,11 @@ public class FlowClassificationRuleDao {

private static final RecordMapper<Record, FlowClassificationRuleVantagePoint> TO_VANTAGE_MAPPER = r -> ImmutableFlowClassificationRuleVantagePoint
.builder()
.vantagePoint(mkRef(EntityKind.ORG_UNIT, r.get(targetOrgUnitId)))
.vantagePointRank(r.get(declaredOrgUnitLevel))
.vantagePoint(mkRef(EntityKind.valueOf(r.get(FLOW_CLASSIFICATION_RULE.PARENT_KIND)), r.get(vantagePointId))) // could be child org unit
.vantagePointRank(r.get(vantagePointLevel))
.subjectReference(mkRef(EntityKind.valueOf(r.get(FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_KIND)), r.get(FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_ID)))
.classificationCode(r.get(FLOW_CLASSIFICATION.CODE))
.dataType(mkRef(EntityKind.DATA_TYPE, r.get(declaredDataTypeId)))
.dataType(mkRef(EntityKind.DATA_TYPE, r.get(ehDataType.ID)))
.dataTypeRank(r.get(declaredDataTypeLevel))
.ruleId(r.get(FLOW_CLASSIFICATION_RULE.ID))
.build();
Expand Down Expand Up @@ -345,29 +350,54 @@ public int clearRatingsForPointToPointFlows(FlowClassificationRule rule) {
}


public List<FlowClassificationRuleVantagePoint> findExpandedFlowClassificationRuleVantagePoints(Set<Long> orgIds) {
SelectSeekStep3<Record8<Long, Integer, Long, Integer, Long, String, String, Long>, Integer, Integer, Long> select = dsl
.select(targetOrgUnitId,
declaredOrgUnitLevel,
declaredDataTypeId,
public List<FlowClassificationRuleVantagePoint> findExpandedFlowClassificationRuleVantagePoints(FlowDirection direction,
Set<Long> orgVantagePointIds,
Set<Long> appVantagePointIds,
Set<Long> actorVantagePointIds) {

Condition appVantagePointCondition = FLOW_CLASSIFICATION_RULE.PARENT_KIND.eq(EntityKind.APPLICATION.name())
.and(FLOW_CLASSIFICATION_RULE.PARENT_ID.in(appVantagePointIds));

Condition actorVantagePointCondition = FLOW_CLASSIFICATION_RULE.PARENT_KIND.eq(EntityKind.ACTOR.name())
.and(FLOW_CLASSIFICATION_RULE.PARENT_ID.in(actorVantagePointIds));

Condition orgUnitVantagePointCondition = FLOW_CLASSIFICATION_RULE.PARENT_KIND.eq(EntityKind.ORG_UNIT.name())
.and(ehOrgUnit.ID.in(orgVantagePointIds));

Condition vantagePointCondition = appVantagePointCondition
.or(actorVantagePointCondition)
.or(orgUnitVantagePointCondition);

SelectSeekStep5<Record9<Long, String, Integer, Long, Integer, Long, String, String, Long>, String, Integer, Integer, Long, Long> select = dsl
.select(vantagePointId,
FLOW_CLASSIFICATION_RULE.PARENT_KIND,
vantagePointLevel,
ehDataType.ID,
declaredDataTypeLevel,
FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_ID,
FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_KIND,
FLOW_CLASSIFICATION.CODE,
FLOW_CLASSIFICATION_RULE.ID)
.from(ehOrgUnit)
.innerJoin(FLOW_CLASSIFICATION_RULE)
.on(ehOrgUnit.ANCESTOR_ID.eq(FLOW_CLASSIFICATION_RULE.PARENT_ID).and(ehOrgUnit.KIND.eq(EntityKind.ORG_UNIT.name())))
.from(FLOW_CLASSIFICATION_RULE)
.leftJoin(ehOrgUnit)
.on(ehOrgUnit.ANCESTOR_ID.eq(FLOW_CLASSIFICATION_RULE.PARENT_ID)
.and(ehOrgUnit.KIND.eq(EntityKind.ORG_UNIT.name())
.and(FLOW_CLASSIFICATION_RULE.PARENT_KIND.eq(EntityKind.ORG_UNIT.name()))))
.innerJoin(declaredDataType)
.on(declaredDataType.ID.eq(FLOW_CLASSIFICATION_RULE.DATA_TYPE_ID))
.innerJoin(ehDataType)
.on(ehDataType.ANCESTOR_ID.eq(declaredDataType.ID).and(ehDataType.KIND.eq(EntityKind.DATA_TYPE.name())))
.innerJoin(impliedDataType)
.on(impliedDataType.ID.eq(ehDataType.ID).and(ehDataType.KIND.eq(EntityKind.DATA_TYPE.name())))
.innerJoin(FLOW_CLASSIFICATION).on(FLOW_CLASSIFICATION_RULE.FLOW_CLASSIFICATION_ID.eq(FLOW_CLASSIFICATION.ID))
.where(ehOrgUnit.ID.in(orgIds))
.orderBy(ehOrgUnit.LEVEL.desc(), ehDataType.LEVEL.desc(), ehOrgUnit.ID);
.where(FLOW_CLASSIFICATION.DIRECTION.eq(direction.name())
.and(vantagePointCondition))
.orderBy(
FLOW_CLASSIFICATION_RULE.PARENT_KIND,
ehOrgUnit.LEVEL.desc(),
ehDataType.LEVEL.desc(),
ehOrgUnit.ID,
ehDataType.ID);

System.out.println(select);
return select
.fetch(TO_VANTAGE_MAPPER);
}
Expand All @@ -379,34 +409,38 @@ public List<FlowClassificationRuleVantagePoint> findFlowClassificationRuleVantag


private List<FlowClassificationRuleVantagePoint> findFlowClassificationRuleVantagePoints(Condition condition) {
SelectSeekStep4<Record8<Long, Integer, Long, Integer, Long, String, String, Long>, Integer, Integer, Long, Long> select = dsl
.select(targetOrgUnitId,
declaredOrgUnitLevel,
declaredDataTypeId,
SelectSeekStep6<Record9<Long, String, Integer, Long, Integer, Long, String, String, Long>, String, Integer, Integer, Long, Long, Long> select = dsl
.select(vantagePointId,
FLOW_CLASSIFICATION_RULE.PARENT_KIND,
vantagePointLevel,
ehDataType.ID,
declaredDataTypeLevel,
FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_ID,
FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_KIND,
FLOW_CLASSIFICATION.CODE,
FLOW_CLASSIFICATION_RULE.ID)
.from(FLOW_CLASSIFICATION_RULE)
.innerJoin(ehOrgUnit)
.leftJoin(ehOrgUnit)
.on(ehOrgUnit.ANCESTOR_ID.eq(FLOW_CLASSIFICATION_RULE.PARENT_ID)
.and(ehOrgUnit.KIND.eq(EntityKind.ORG_UNIT.name()))
.and(ehOrgUnit.ID.eq(ehOrgUnit.ANCESTOR_ID)))
.innerJoin(org.finos.waltz.schema.tables.DataType.DATA_TYPE)
.on(org.finos.waltz.schema.tables.DataType.DATA_TYPE.ID.eq(FLOW_CLASSIFICATION_RULE.DATA_TYPE_ID))
.innerJoin(DataType.DATA_TYPE)
.on(DataType.DATA_TYPE.ID.eq(FLOW_CLASSIFICATION_RULE.DATA_TYPE_ID))
.innerJoin(ehDataType)
.on(ehDataType.ANCESTOR_ID.eq(org.finos.waltz.schema.tables.DataType.DATA_TYPE.ID)
.on(ehDataType.ANCESTOR_ID.eq(DataType.DATA_TYPE.ID)
.and(ehDataType.KIND.eq(EntityKind.DATA_TYPE.name()))
.and(ehDataType.ID.eq(ehDataType.ANCESTOR_ID)))
.innerJoin(FLOW_CLASSIFICATION).on(FLOW_CLASSIFICATION_RULE.FLOW_CLASSIFICATION_ID.eq(FLOW_CLASSIFICATION.ID))
.where(condition)
.orderBy(
ehOrgUnit.LEVEL.desc(),
FLOW_CLASSIFICATION_RULE.PARENT_KIND, //ACTOR, APPLICATION, ORG_UNIT
vantagePointLevel.desc(),
ehDataType.LEVEL.desc(),
ehOrgUnit.ID,
ehDataType.ID
vantagePointId,
ehDataType.ID,
FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_ID
);

return select.fetch(TO_VANTAGE_MAPPER);
}

Expand Down Expand Up @@ -619,4 +653,8 @@ public Set<FlowClassificationRule> findAppliedClassificationRulesForFlow(Long lo
.where(LOGICAL_FLOW_DECORATOR.LOGICAL_FLOW_ID.eq(logicalFlowId))
.fetchSet(TO_DOMAIN_MAPPER);
}

public int updateDecoratorsWithClassifications(Set<UpdateConditionStep<LogicalFlowDecoratorRecord>> updateStmts) {
return IntStream.of(dsl.batch(updateStmts).execute()).sum();
}
}
Loading

0 comments on commit c1f5aae

Please sign in to comment.