2323import org .finos .waltz .model .EntityReference ;
2424import org .finos .waltz .model .FlowDirection ;
2525import org .finos .waltz .model .ImmutableEntityReference ;
26- import org .finos .waltz .model .Severity ;
26+ import org .finos .waltz .model .MessageSeverity ;
2727import org .finos .waltz .model .flow_classification_rule .DiscouragedSource ;
2828import org .finos .waltz .model .flow_classification_rule .FlowClassificationRule ;
2929import org .finos .waltz .model .flow_classification_rule .FlowClassificationRuleCreateCommand ;
3434import org .finos .waltz .model .flow_classification_rule .ImmutableFlowClassificationRuleVantagePoint ;
3535import org .finos .waltz .model .rating .AuthoritativenessRatingValue ;
3636import org .finos .waltz .schema .tables .Application ;
37- import org .finos .waltz .schema .tables .DataType ;
3837import org .finos .waltz .schema .tables .EntityHierarchy ;
3938import org .finos .waltz .schema .tables .records .FlowClassificationRuleRecord ;
4039import org .finos .waltz .schema .tables .records .LogicalFlowDecoratorRecord ;
4140import org .jooq .AggregateFunction ;
4241import org .jooq .Condition ;
4342import org .jooq .DSLContext ;
4443import org .jooq .Field ;
44+ import org .jooq .InsertSetMoreStep ;
4545import org .jooq .Record ;
4646import org .jooq .Record1 ;
4747import org .jooq .Record11 ;
@@ -93,6 +93,8 @@ public class FlowClassificationRuleDao {
9393
9494 public final static Application CONSUMER_APP = APPLICATION .as ("consumer" );
9595 public final static Application SUPPLIER_APP = APPLICATION .as ("supplier" );
96+ public final static Application SUBJECT_APP = APPLICATION .as ("subject_app" );
97+ public final static Application SUBJECT_EUDA = APPLICATION .as ("subject_euda" );
9698 public static final org .finos .waltz .schema .tables .DataType parent_dt = org .finos .waltz .schema .tables .DataType .DATA_TYPE .as ("parent_dt" );
9799 public static final org .finos .waltz .schema .tables .DataType child_dt = org .finos .waltz .schema .tables .DataType .DATA_TYPE .as ("child_dt" );
98100 public static final EntityHierarchy eh = ENTITY_HIERARCHY .as ("eh" );
@@ -108,12 +110,12 @@ public class FlowClassificationRuleDao {
108110 private static final Field <String > PARENT_NAME_FIELD = InlineSelectFieldFactory .mkNameField (
109111 FLOW_CLASSIFICATION_RULE .PARENT_ID ,
110112 FLOW_CLASSIFICATION_RULE .PARENT_KIND ,
111- newArrayList (EntityKind .ORG_UNIT , EntityKind .APPLICATION , EntityKind .ACTOR ));
113+ newArrayList (EntityKind .ORG_UNIT , EntityKind .APPLICATION , EntityKind .ACTOR , EntityKind . END_USER_APPLICATION ));
112114
113115 private static final Field <String > SUBJECT_NAME_FIELD = InlineSelectFieldFactory .mkNameField (
114116 FLOW_CLASSIFICATION_RULE .SUBJECT_ENTITY_ID ,
115117 FLOW_CLASSIFICATION_RULE .SUBJECT_ENTITY_KIND ,
116- newArrayList (EntityKind .APPLICATION , EntityKind .ACTOR ));
118+ newArrayList (EntityKind .APPLICATION , EntityKind .ACTOR , EntityKind . END_USER_APPLICATION ));
117119
118120 private static final Condition flowNotRemoved = LOGICAL_FLOW .ENTITY_LIFECYCLE_STATUS .ne (REMOVED .name ())
119121 .and (LOGICAL_FLOW .IS_REMOVED .isFalse ());
@@ -160,7 +162,7 @@ public class FlowClassificationRuleDao {
160162 .externalId (Optional .ofNullable (record .getExternalId ()))
161163 .isReadonly (record .getIsReadonly ())
162164 .message (record .getMessage ())
163- .messageSeverity (Severity .valueOf (record .getMessageSeverity ()))
165+ .messageSeverity (MessageSeverity .valueOf (record .getMessageSeverity ()))
164166 .build ();
165167 };
166168
@@ -176,7 +178,7 @@ public class FlowClassificationRuleDao {
176178 .dataTypeRank (r .get (dataTypeLevel ))
177179 .ruleId (r .get (FLOW_CLASSIFICATION_RULE .ID ))
178180 .message (r .get (FLOW_CLASSIFICATION_RULE .MESSAGE ))
179- .messageSeverity (Severity .valueOf (r .get (FLOW_CLASSIFICATION_RULE .MESSAGE_SEVERITY )))
181+ .messageSeverity (MessageSeverity .valueOf (r .get (FLOW_CLASSIFICATION_RULE .MESSAGE_SEVERITY )))
180182 .build ();
181183 };
182184
@@ -240,6 +242,11 @@ public int update(FlowClassificationRuleUpdateCommand command) {
240242 .set (FLOW_CLASSIFICATION_RULE .FLOW_CLASSIFICATION_ID , command .classificationId ())
241243 .set (FLOW_CLASSIFICATION_RULE .DESCRIPTION , command .description ());
242244
245+ if (command .severity () != null ) {
246+ upd .set (FLOW_CLASSIFICATION_RULE .MESSAGE_SEVERITY , command .severity ().name ());
247+ upd .set (FLOW_CLASSIFICATION_RULE .MESSAGE , command .message ());
248+ }
249+
243250 return upd
244251 .where (FLOW_CLASSIFICATION_RULE .ID .eq (command .id ().get ()))
245252 .execute ();
@@ -249,7 +256,7 @@ public int update(FlowClassificationRuleUpdateCommand command) {
249256 public long insert (FlowClassificationRuleCreateCommand command , String username ) {
250257 checkNotNull (command , "command cannot be null" );
251258
252- return dsl
259+ InsertSetMoreStep < FlowClassificationRuleRecord > stmt = dsl
253260 .insertInto (FLOW_CLASSIFICATION_RULE )
254261 .set (FLOW_CLASSIFICATION_RULE .PARENT_KIND , command .parentReference ().kind ().name ())
255262 .set (FLOW_CLASSIFICATION_RULE .PARENT_ID , command .parentReference ().id ())
@@ -260,7 +267,14 @@ public long insert(FlowClassificationRuleCreateCommand command, String username)
260267 .set (FLOW_CLASSIFICATION_RULE .DESCRIPTION , command .description ())
261268 .set (FLOW_CLASSIFICATION_RULE .PROVENANCE , "waltz" )
262269 .set (FLOW_CLASSIFICATION_RULE .LAST_UPDATED_AT , nowUtcTimestamp ())
263- .set (FLOW_CLASSIFICATION_RULE .LAST_UPDATED_BY , username )
270+ .set (FLOW_CLASSIFICATION_RULE .LAST_UPDATED_BY , username );
271+
272+ if (command .severity () != null ) {
273+ stmt .set (FLOW_CLASSIFICATION_RULE .MESSAGE_SEVERITY , command .severity ().name ());
274+ stmt .set (FLOW_CLASSIFICATION_RULE .MESSAGE , command .message ());
275+ }
276+
277+ return stmt
264278 .returning (FLOW_CLASSIFICATION_RULE .ID )
265279 .fetchOne ()
266280 .getId ();
@@ -318,6 +332,8 @@ public Set<EntityReference> cleanupOrphans() {
318332 }
319333
320334
335+ /* deprecating as we need to work on improving the speed of on-demand recalcs */
336+ @ Deprecated
321337 public int clearRatingsForPointToPointFlows (FlowClassificationRule rule ) {
322338
323339 // this may wipe any lower level explicit datatype mappings but these will be restored by the nightly job
@@ -526,22 +542,10 @@ public List<DiscouragedSource> findDiscouragedSourcesBySelector(Condition custom
526542
527543 public Set <FlowClassificationRule > findClassificationRules (Condition customSelectionCriteria ) {
528544
529- SelectConditionStep <Record1 <Long >> ruleSelectorBasedOnCustomSelectionForTargetApps = DSL
530- .select (FLOW_CLASSIFICATION_RULE .ID )
531- .from (FLOW_CLASSIFICATION_RULE )
532- .innerJoin (LOGICAL_FLOW )
533- .on (LOGICAL_FLOW .SOURCE_ENTITY_ID .eq (FLOW_CLASSIFICATION_RULE .SUBJECT_ENTITY_ID )
534- .and (LOGICAL_FLOW .SOURCE_ENTITY_KIND .eq (FLOW_CLASSIFICATION_RULE .SUBJECT_ENTITY_KIND ))
535- .and (LOGICAL_FLOW .ENTITY_LIFECYCLE_STATUS .ne (REMOVED .name ())
536- .and (LOGICAL_FLOW .IS_REMOVED .isFalse ())))
537- .innerJoin (CONSUMER_APP ).on (LOGICAL_FLOW .TARGET_ENTITY_ID .eq (CONSUMER_APP .ID )
538- .and (LOGICAL_FLOW .TARGET_ENTITY_KIND .eq (EntityKind .APPLICATION .name ())))
545+ SelectConditionStep <Record > qry = baseSelect ()
539546 .where (customSelectionCriteria );
540547
541- Condition criteria = FLOW_CLASSIFICATION_RULE .ID .in (ruleSelectorBasedOnCustomSelectionForTargetApps );
542-
543- return baseSelect ()
544- .where (criteria )
548+ return qry
545549 .fetchSet (TO_DOMAIN_MAPPER );
546550 }
547551
@@ -554,13 +558,16 @@ private SelectOnConditionStep<Record> baseSelect() {
554558 .select (SUBJECT_NAME_FIELD )
555559 .select (ORGANISATIONAL_UNIT .ID , ORGANISATIONAL_UNIT .NAME )
556560 .select (FLOW_CLASSIFICATION_RULE .fields ())
557- .select (SUPPLIER_APP .NAME , SUPPLIER_APP .ID )
558561 .from (FLOW_CLASSIFICATION_RULE )
559- .leftJoin (SUPPLIER_APP )
560- .on (SUPPLIER_APP .ID .eq (FLOW_CLASSIFICATION_RULE .SUBJECT_ENTITY_ID )
562+ .leftJoin (SUBJECT_APP )
563+ .on (SUBJECT_APP .ID .eq (FLOW_CLASSIFICATION_RULE .SUBJECT_ENTITY_ID )
561564 .and (FLOW_CLASSIFICATION_RULE .SUBJECT_ENTITY_KIND .eq (EntityKind .APPLICATION .name ())))
565+ .leftJoin (SUBJECT_EUDA )
566+ .on (SUBJECT_EUDA .ID .eq (FLOW_CLASSIFICATION_RULE .SUBJECT_ENTITY_ID )
567+ .and (FLOW_CLASSIFICATION_RULE .SUBJECT_ENTITY_KIND .eq (EntityKind .END_USER_APPLICATION .name ())))
562568 .leftJoin (ORGANISATIONAL_UNIT )
563- .on (ORGANISATIONAL_UNIT .ID .eq (SUPPLIER_APP .ORGANISATIONAL_UNIT_ID ));
569+ .on (ORGANISATIONAL_UNIT .ID .eq (SUBJECT_APP .ORGANISATIONAL_UNIT_ID )
570+ .or (ORGANISATIONAL_UNIT .ID .eq (SUBJECT_EUDA .ORGANISATIONAL_UNIT_ID )));
564571 }
565572
566573
0 commit comments