Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow Classification Rules admin #7065

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Select<Record1<Long>> apply(IdSelectionOptions options) {
case ALL:
return mkForAll(options);
case ACTOR:
return mkForActor(options);
return mkViaFlows(options);
case APP_GROUP:
return mkForAppGroup(options);
case APPLICATION:
Expand All @@ -88,6 +88,8 @@ public Select<Record1<Long>> apply(IdSelectionOptions options) {
return mkForEntityRelationship(options);
case DATA_TYPE:
return mkForDataType(options);
case END_USER_APPLICATION:
return mkViaFlows(options);
case FLOW_DIAGRAM:
return mkForFlowDiagram(options);
case LICENCE:
Expand Down Expand Up @@ -327,27 +329,28 @@ private Select<Record1<Long>> mkForServer(IdSelectionOptions options) {
}


public static Select<Record1<Long>> mkForActor(IdSelectionOptions options) {
private static Select<Record1<Long>> mkViaFlows(IdSelectionOptions options) {
SelectorUtilities.ensureScopeIsExact(options);
long actorId = options.entityReference().id();
long entityId = options.entityReference().id();
EntityKind entityKind = options.entityReference().kind();

Condition applicationConditions = SelectorUtilities.mkApplicationConditions(options);

Select<Record1<Long>> sourceAppIds = DSL
.select(logicalFlow.SOURCE_ENTITY_ID)
.from(logicalFlow)
.innerJoin(APPLICATION).on(APPLICATION.ID.eq(logicalFlow.SOURCE_ENTITY_ID))
.where(logicalFlow.TARGET_ENTITY_ID.eq(actorId)
.and(logicalFlow.TARGET_ENTITY_KIND.eq(EntityKind.ACTOR.name()))
.where(logicalFlow.TARGET_ENTITY_ID.eq(entityId)
.and(logicalFlow.SOURCE_ENTITY_KIND.eq(EntityKind.APPLICATION.name()))
.and(logicalFlow.TARGET_ENTITY_KIND.eq(entityKind.name()))
.and(logicalFlow.ENTITY_LIFECYCLE_STATUS.ne(REMOVED.name())))
.and(applicationConditions);

Select<Record1<Long>> targetAppIds = DSL.select(logicalFlow.TARGET_ENTITY_ID)
.from(logicalFlow)
.innerJoin(APPLICATION).on(APPLICATION.ID.eq(logicalFlow.TARGET_ENTITY_ID))
.where(logicalFlow.SOURCE_ENTITY_ID.eq(actorId)
.and(logicalFlow.SOURCE_ENTITY_KIND.eq(EntityKind.ACTOR.name()))
.where(logicalFlow.SOURCE_ENTITY_ID.eq(entityId)
.and(logicalFlow.SOURCE_ENTITY_KIND.eq(entityKind.name()))
.and(logicalFlow.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name()))
.and(logicalFlow.ENTITY_LIFECYCLE_STATUS.ne(REMOVED.name())))
.and(applicationConditions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
package org.finos.waltz.data.flow_classification_rule;

import org.finos.waltz.model.FlowDirection;
import org.finos.waltz.model.Severity;
import org.finos.waltz.schema.tables.records.FlowClassificationRecord;
import org.finos.waltz.model.MessageSeverity;
import org.finos.waltz.model.flow_classification.FlowClassification;
import org.finos.waltz.model.flow_classification.ImmutableFlowClassification;
import org.finos.waltz.schema.tables.records.FlowClassificationRecord;
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.RecordMapper;
Expand All @@ -31,8 +31,8 @@

import java.util.Set;

import static org.finos.waltz.schema.Tables.FLOW_CLASSIFICATION;
import static org.finos.waltz.common.Checks.checkNotNull;
import static org.finos.waltz.schema.Tables.FLOW_CLASSIFICATION;


@Repository
Expand All @@ -53,7 +53,7 @@ public class FlowClassificationDao {
.userSelectable(record.getUserSelectable())
.direction(FlowDirection.valueOf(record.getDirection()))
.defaultMessage(record.getDefaultMessage())
.messageSeverity(Severity.valueOf(record.getMessageSeverity()))
.messageSeverity(MessageSeverity.valueOf(record.getMessageSeverity()))
.build();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.finos.waltz.model.EntityReference;
import org.finos.waltz.model.FlowDirection;
import org.finos.waltz.model.ImmutableEntityReference;
import org.finos.waltz.model.Severity;
import org.finos.waltz.model.MessageSeverity;
import org.finos.waltz.model.flow_classification_rule.DiscouragedSource;
import org.finos.waltz.model.flow_classification_rule.FlowClassificationRule;
import org.finos.waltz.model.flow_classification_rule.FlowClassificationRuleCreateCommand;
Expand All @@ -34,14 +34,14 @@
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;
import org.jooq.Field;
import org.jooq.InsertSetMoreStep;
import org.jooq.Record;
import org.jooq.Record1;
import org.jooq.Record11;
Expand Down Expand Up @@ -93,6 +93,8 @@ public class FlowClassificationRuleDao {

public final static Application CONSUMER_APP = APPLICATION.as("consumer");
public final static Application SUPPLIER_APP = APPLICATION.as("supplier");
public final static Application SUBJECT_APP = APPLICATION.as("subject_app");
public final static Application SUBJECT_EUDA = APPLICATION.as("subject_euda");
public static final org.finos.waltz.schema.tables.DataType parent_dt = org.finos.waltz.schema.tables.DataType.DATA_TYPE.as("parent_dt");
public static final org.finos.waltz.schema.tables.DataType child_dt = org.finos.waltz.schema.tables.DataType.DATA_TYPE.as("child_dt");
public static final EntityHierarchy eh = ENTITY_HIERARCHY.as("eh");
Expand All @@ -108,12 +110,12 @@ public class FlowClassificationRuleDao {
private static final Field<String> PARENT_NAME_FIELD = InlineSelectFieldFactory.mkNameField(
FLOW_CLASSIFICATION_RULE.PARENT_ID,
FLOW_CLASSIFICATION_RULE.PARENT_KIND,
newArrayList(EntityKind.ORG_UNIT, EntityKind.APPLICATION, EntityKind.ACTOR));
newArrayList(EntityKind.ORG_UNIT, EntityKind.APPLICATION, EntityKind.ACTOR, EntityKind.END_USER_APPLICATION));

private static final Field<String> SUBJECT_NAME_FIELD = InlineSelectFieldFactory.mkNameField(
FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_ID,
FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_KIND,
newArrayList(EntityKind.APPLICATION, EntityKind.ACTOR));
newArrayList(EntityKind.APPLICATION, EntityKind.ACTOR, EntityKind.END_USER_APPLICATION));

private static final Condition flowNotRemoved = LOGICAL_FLOW.ENTITY_LIFECYCLE_STATUS.ne(REMOVED.name())
.and(LOGICAL_FLOW.IS_REMOVED.isFalse());
Expand Down Expand Up @@ -160,7 +162,7 @@ public class FlowClassificationRuleDao {
.externalId(Optional.ofNullable(record.getExternalId()))
.isReadonly(record.getIsReadonly())
.message(record.getMessage())
.messageSeverity(Severity.valueOf(record.getMessageSeverity()))
.messageSeverity(MessageSeverity.valueOf(record.getMessageSeverity()))
.build();
};

Expand All @@ -176,7 +178,7 @@ public class FlowClassificationRuleDao {
.dataTypeRank(r.get(dataTypeLevel))
.ruleId(r.get(FLOW_CLASSIFICATION_RULE.ID))
.message(r.get(FLOW_CLASSIFICATION_RULE.MESSAGE))
.messageSeverity(Severity.valueOf(r.get(FLOW_CLASSIFICATION_RULE.MESSAGE_SEVERITY)))
.messageSeverity(MessageSeverity.valueOf(r.get(FLOW_CLASSIFICATION_RULE.MESSAGE_SEVERITY)))
.build();
};

Expand Down Expand Up @@ -240,6 +242,11 @@ public int update(FlowClassificationRuleUpdateCommand command) {
.set(FLOW_CLASSIFICATION_RULE.FLOW_CLASSIFICATION_ID, command.classificationId())
.set(FLOW_CLASSIFICATION_RULE.DESCRIPTION, command.description());

if (command.severity() != null) {
upd.set(FLOW_CLASSIFICATION_RULE.MESSAGE_SEVERITY, command.severity().name());
upd.set(FLOW_CLASSIFICATION_RULE.MESSAGE, command.message());
}

return upd
.where(FLOW_CLASSIFICATION_RULE.ID.eq(command.id().get()))
.execute();
Expand All @@ -249,7 +256,7 @@ public int update(FlowClassificationRuleUpdateCommand command) {
public long insert(FlowClassificationRuleCreateCommand command, String username) {
checkNotNull(command, "command cannot be null");

return dsl
InsertSetMoreStep<FlowClassificationRuleRecord> stmt = dsl
.insertInto(FLOW_CLASSIFICATION_RULE)
.set(FLOW_CLASSIFICATION_RULE.PARENT_KIND, command.parentReference().kind().name())
.set(FLOW_CLASSIFICATION_RULE.PARENT_ID, command.parentReference().id())
Expand All @@ -260,7 +267,14 @@ public long insert(FlowClassificationRuleCreateCommand command, String username)
.set(FLOW_CLASSIFICATION_RULE.DESCRIPTION, command.description())
.set(FLOW_CLASSIFICATION_RULE.PROVENANCE, "waltz")
.set(FLOW_CLASSIFICATION_RULE.LAST_UPDATED_AT, nowUtcTimestamp())
.set(FLOW_CLASSIFICATION_RULE.LAST_UPDATED_BY, username)
.set(FLOW_CLASSIFICATION_RULE.LAST_UPDATED_BY, username);

if (command.severity() != null) {
stmt.set(FLOW_CLASSIFICATION_RULE.MESSAGE_SEVERITY, command.severity().name());
stmt.set(FLOW_CLASSIFICATION_RULE.MESSAGE, command.message());
}

return stmt
.returning(FLOW_CLASSIFICATION_RULE.ID)
.fetchOne()
.getId();
Expand Down Expand Up @@ -318,6 +332,8 @@ public Set<EntityReference> cleanupOrphans() {
}


/* deprecating as we need to work on improving the speed of on-demand recalcs */
@Deprecated
public int clearRatingsForPointToPointFlows(FlowClassificationRule rule) {

// this may wipe any lower level explicit datatype mappings but these will be restored by the nightly job
Expand Down Expand Up @@ -526,22 +542,10 @@ public List<DiscouragedSource> findDiscouragedSourcesBySelector(Condition custom

public Set<FlowClassificationRule> findClassificationRules(Condition customSelectionCriteria) {

SelectConditionStep<Record1<Long>> ruleSelectorBasedOnCustomSelectionForTargetApps = DSL
.select(FLOW_CLASSIFICATION_RULE.ID)
.from(FLOW_CLASSIFICATION_RULE)
.innerJoin(LOGICAL_FLOW)
.on(LOGICAL_FLOW.SOURCE_ENTITY_ID.eq(FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_ID)
.and(LOGICAL_FLOW.SOURCE_ENTITY_KIND.eq(FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_KIND))
.and(LOGICAL_FLOW.ENTITY_LIFECYCLE_STATUS.ne(REMOVED.name())
.and(LOGICAL_FLOW.IS_REMOVED.isFalse())))
.innerJoin(CONSUMER_APP).on(LOGICAL_FLOW.TARGET_ENTITY_ID.eq(CONSUMER_APP.ID)
.and(LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name())))
SelectConditionStep<Record> qry = baseSelect()
.where(customSelectionCriteria);

Condition criteria = FLOW_CLASSIFICATION_RULE.ID.in(ruleSelectorBasedOnCustomSelectionForTargetApps);

return baseSelect()
.where(criteria)
return qry
.fetchSet(TO_DOMAIN_MAPPER);
}

Expand All @@ -554,13 +558,16 @@ private SelectOnConditionStep<Record> baseSelect() {
.select(SUBJECT_NAME_FIELD)
.select(ORGANISATIONAL_UNIT.ID, ORGANISATIONAL_UNIT.NAME)
.select(FLOW_CLASSIFICATION_RULE.fields())
.select(SUPPLIER_APP.NAME, SUPPLIER_APP.ID)
.from(FLOW_CLASSIFICATION_RULE)
.leftJoin(SUPPLIER_APP)
.on(SUPPLIER_APP.ID.eq(FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_ID)
.leftJoin(SUBJECT_APP)
.on(SUBJECT_APP.ID.eq(FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_ID)
.and(FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_KIND.eq(EntityKind.APPLICATION.name())))
.leftJoin(SUBJECT_EUDA)
.on(SUBJECT_EUDA.ID.eq(FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_ID)
.and(FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_KIND.eq(EntityKind.END_USER_APPLICATION.name())))
.leftJoin(ORGANISATIONAL_UNIT)
.on(ORGANISATIONAL_UNIT.ID.eq(SUPPLIER_APP.ORGANISATIONAL_UNIT_ID));
.on(ORGANISATIONAL_UNIT.ID.eq(SUBJECT_APP.ORGANISATIONAL_UNIT_ID)
.or(ORGANISATIONAL_UNIT.ID.eq(SUBJECT_EUDA.ORGANISATIONAL_UNIT_ID)));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@
package org.finos.waltz.jobs.harness;

import org.finos.waltz.model.EntityKind;
import org.finos.waltz.model.EntityReference;
import org.finos.waltz.model.datatype.DataTypeDecoratorRatingCharacteristics;
import org.finos.waltz.model.flow_classification_rule.FlowClassificationRule;
import org.finos.waltz.service.DIConfiguration;
import org.finos.waltz.service.data_flow_decorator.LogicalFlowDecoratorRatingsCalculator;
import org.finos.waltz.service.flow_classification_rule.FlowClassificationRuleService;
import org.jooq.DSLContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Optional;
import java.util.Set;

import static org.finos.waltz.common.SetUtilities.asSet;
import static org.finos.waltz.model.EntityReference.mkRef;
import static org.finos.waltz.model.IdSelectionOptions.mkOpts;


public class FlowClassificationRuleHarness {
Expand All @@ -39,18 +37,10 @@ public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);

LogicalFlowDecoratorRatingsCalculator calc = ctx.getBean(LogicalFlowDecoratorRatingsCalculator.class);
// AuthSourceRatingCalculator authSourceRatingCalculatorCalculator = ctx.getBean(AuthSourceRatingCalculator.class);
// LogicalFlowDecoratorRatingsCalculator flowCalculator = ctx.getBean(LogicalFlowDecoratorRatingsCalculator.class);
// LogicalFlowDecoratorSummaryDao decoratorDao = ctx.getBean(LogicalFlowDecoratorSummaryDao.class);
// AuthoritativeSourceDao dao = ctx.getBean(AuthoritativeSourceDao.class);

EntityReference waltz = EntityReference.mkRef(EntityKind.APPLICATION, 20506);
EntityReference apptio = EntityReference.mkRef(EntityKind.APPLICATION, 20023);

// Set<DataTypeDecoratorRatingCharacteristics> calculated = calc.calculate(waltz, apptio, Optional.of(asSet(58584L, 66684L)));
Set<DataTypeDecoratorRatingCharacteristics> calculated = calc.calculate(waltz, apptio, Optional.empty());
System.out.printf("Calculated %d\n", calculated.size());
FlowClassificationRuleService svc = ctx.getBean(FlowClassificationRuleService.class);
Set<FlowClassificationRule> r = svc.findClassificationRules(mkOpts(mkRef(EntityKind.ORG_UNIT, 14902L)));
System.out.println(r);

// System.exit(-1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ protected static HierarchyQueryScope determineDefaultScope(EntityKind kind) {
case APPLICATION:
case APP_GROUP:
case CHANGE_INITIATIVE:
case END_USER_APPLICATION:
case FLOW_DIAGRAM:
case LOGICAL_DATA_ELEMENT:
case LOGICAL_DATA_FLOW:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Waltz - Enterprise Architecture
* Copyright (C) 2016, 2017, 2018, 2019 Waltz open source project
* See README.md for more information
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific
*
*/

package org.finos.waltz.model;

public enum MessageSeverity {

NONE,
INFORMATION,
WARNING,
ERROR

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.finos.waltz.model.EntityReference;
import org.finos.waltz.model.MessageSeverity;
import org.finos.waltz.model.Nullable;
import org.finos.waltz.model.Severity;
import org.finos.waltz.model.rating.AuthoritativenessRatingValue;
import org.immutables.value.Value;

Expand Down Expand Up @@ -53,16 +53,16 @@ public AuthoritativenessRatingValue targetInboundRating(){
public abstract String outboundMessage();

@Value.Default
public Severity outboundMessageSeverity() {
return Severity.INFORMATION;
public MessageSeverity outboundMessageSeverity() {
return MessageSeverity.INFORMATION;
}

@Nullable
public abstract String inboundMessage();

@Value.Default
public Severity inboundMessageSeverity() {
return Severity.INFORMATION;
public MessageSeverity inboundMessageSeverity() {
return MessageSeverity.INFORMATION;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public FlowDirection direction() {
public abstract String defaultMessage();

@Value.Default
public Severity messageSeverity() {
return Severity.INFORMATION;
public MessageSeverity messageSeverity() {
return MessageSeverity.INFORMATION;
}
@Value.Default
public EntityKind kind() {
return EntityKind.FLOW_CLASSIFICATION_RULE;
return EntityKind.FLOW_CLASSIFICATION;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public boolean isReadonly() {
public abstract String message();

@Value.Default
public Severity messageSeverity() {
return Severity.INFORMATION;
public MessageSeverity messageSeverity() {
return MessageSeverity.INFORMATION;
}


Expand Down
Loading
Loading