Skip to content

Commit

Permalink
Pull request #360: Wrel 159
Browse files Browse the repository at this point in the history
Merge in WALTZ/waltz from WALTZ/waltz-dw:wrel-159 to db-feature/waltz-7032-flow-classifications-add-directionality

* commit 'e32f88c785cb394241604b6a230a8ba6cd4a5caf':
  Flow Classifications becoming inbound rule aware
  Flow Classifications becoming inbound rule aware
  Licences - search for licences from navbar
  Licences - search for licences from navbar
  Licences - search for licences from navbar
  Report Grids: entity stats have view options
  Survey instance shows the contact email
  Delete .github/workflows/meetings.yml since deprecated
  • Loading branch information
db-waltz authored and jessica-woodland-scott-db committed Mar 27, 2024
2 parents 5635408 + e32f88c commit 76333de
Show file tree
Hide file tree
Showing 20 changed files with 506 additions and 124 deletions.
88 changes: 0 additions & 88 deletions .github/workflows/meetings.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@

package org.finos.waltz.common;

import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static org.finos.waltz.common.Checks.checkNotEmpty;


public class CollectionUtilities {

Expand Down Expand Up @@ -242,5 +245,4 @@ public static Long sumInts(Collection<Integer> values) {
return acc;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;
import static org.finos.waltz.common.Checks.checkNotNull;
Expand Down Expand Up @@ -195,11 +196,34 @@ public static <T> Optional<T> maybeGet(List<T> xs, int idx) {
}
}


/**
* Given a list, index and default value returns the element at that index or the default value if the index is out of bounds.
*/
public static <T> T getOrDefault(List<T> xs, int idx, T defaultValue) {
return maybeGet(xs, idx)
.orElse(defaultValue);
}


public static <X> List<X> take(Collection<X> xs,
int amount) {
return ListUtilities
.ensureNotNull(xs)
.stream()
.limit(amount)
.collect(Collectors.toList());
}



/**
* Returns a list of distinct values from a given list
* @param ts a list of T's with possible duplicates
* @return distinct values in <code>ts</code>
* @param <T>
*/
public static <T> List<T> distinct(List<T> ts) {
return ts.stream().distinct().collect(toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.finos.waltz.common;

import org.junit.jupiter.api.Test;

import java.util.List;

import static org.finos.waltz.common.ListUtilities.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class ListUtilities_distinct {

@Test
public void distinctDedupesListsButPreservesInitialOrder() {
List<String> xs = asList("a", "b", "c", "c", "b", "c", "d");
List<String> uniq = ListUtilities.distinct(xs);
assertEquals(asList("a", "b", "c", "d"), uniq);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.finos.waltz.data.InlineSelectFieldFactory;
import org.finos.waltz.model.EntityKind;
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.flow_classification_rule.DiscouragedSource;
Expand Down Expand Up @@ -372,7 +373,12 @@ public List<FlowClassificationRuleVantagePoint> findExpandedFlowClassificationRu
}


public List<FlowClassificationRuleVantagePoint> findFlowClassificationRuleVantagePoints() {
public List<FlowClassificationRuleVantagePoint> findFlowClassificationRuleVantagePoints(FlowDirection direction) {
return findFlowClassificationRuleVantagePoints(FLOW_CLASSIFICATION.DIRECTION.eq(direction.name()));
}


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,
Expand All @@ -394,6 +400,7 @@ public List<FlowClassificationRuleVantagePoint> findFlowClassificationRuleVantag
.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(),
ehDataType.LEVEL.desc(),
Expand Down Expand Up @@ -533,7 +540,7 @@ private SelectOnConditionStep<Record> baseSelect() {
}


public int updatePointToPointFlowClassificationRules() {
public int updatePointToPointFlowClassificationRules(FlowDirection direction) {

Condition logicalFlowTargetIsAuthSourceParent = FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_ID.eq(LOGICAL_FLOW.SOURCE_ENTITY_ID)
.and(LOGICAL_FLOW.SOURCE_ENTITY_KIND.eq(FLOW_CLASSIFICATION_RULE.SUBJECT_ENTITY_KIND)
Expand All @@ -558,7 +565,7 @@ public int updatePointToPointFlowClassificationRules() {
.and(level.ID.eq(level.ANCESTOR_ID)
.and(level.KIND.eq(EntityKind.DATA_TYPE.name()))))
.innerJoin(FLOW_CLASSIFICATION).on(FLOW_CLASSIFICATION_RULE.FLOW_CLASSIFICATION_ID.eq(FLOW_CLASSIFICATION.ID))
.where(FLOW_CLASSIFICATION.CODE.ne(LOGICAL_FLOW_DECORATOR.RATING))
.where(FLOW_CLASSIFICATION.CODE.ne(LOGICAL_FLOW_DECORATOR.RATING).and(FLOW_CLASSIFICATION.DIRECTION.eq(direction.name())))
.orderBy(level.LEVEL)
.fetch()
.stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.finos.waltz.data.licence.search;

import org.finos.waltz.common.ListUtilities;
import org.finos.waltz.data.SearchDao;
import org.finos.waltz.data.licence.LicenceDao;
import org.finos.waltz.model.entity_search.EntitySearchOptions;
import org.finos.waltz.model.licence.Licence;
import org.jooq.Condition;
import org.jooq.DSLContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

import static java.util.Collections.emptyList;
import static org.finos.waltz.common.ListUtilities.concat;
import static org.finos.waltz.data.JooqUtilities.mkBasicTermSearch;
import static org.finos.waltz.data.JooqUtilities.mkStartsWithTermSearch;
import static org.finos.waltz.data.SearchUtilities.mkTerms;
import static org.finos.waltz.schema.Tables.LICENCE;

@Repository
public class LicenceSearchDao implements SearchDao<Licence> {

private final DSLContext dsl;


@Autowired
public LicenceSearchDao(DSLContext dsl) {
this.dsl = dsl;
}


/**
* Searches by <code>name</code> and <code>external_id</code>
* @param options
* @return List of matching legal entities,
* matches on name are given precedence over external_id matches
*/
@Override
public List<Licence> search(EntitySearchOptions options) {
List<String> terms = mkTerms(options.searchQuery());
if (terms.isEmpty()) {
return emptyList();
}

Condition nameCondition = mkBasicTermSearch(LICENCE.NAME, terms);
Condition externalIdCondition = mkStartsWithTermSearch(LICENCE.EXTERNAL_ID, terms);

return ListUtilities.distinct(concat(
mkQuery(nameCondition, options),
mkQuery(externalIdCondition, options)));
}


private List<Licence> mkQuery(Condition nameCondition, EntitySearchOptions options) {
return dsl
.select(LICENCE.fields())
.from(LICENCE)
.where(nameCondition)
.orderBy(LICENCE.NAME)
.limit(options.limit())
.fetch(LicenceDao.TO_DOMAIN_MAPPER);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2284,50 +2284,62 @@ private Set<ReportGridCell> fetchEntityStatisticData(GenericSelector selector,
if (isEmpty(cols)) {
return emptySet();
} else {
Map<Long, Long> statisticDefinitionIdToColIdMap = indexBy(
Map<Long, ReportGridFixedColumnDefinition> statisticDefinitionIdToColMap = indexBy(
cols,
ReportGridFixedColumnDefinition::columnEntityId,
ReportGridFixedColumnDefinition::gridColumnId);
ReportGridFixedColumnDefinition::columnEntityId);

return dsl
.select(esv.ENTITY_ID,
esv.STATISTIC_ID,
esv.OUTCOME,
esv.VALUE,
esv.REASON)
.from(esv)
.where(esv.STATISTIC_ID.in(statisticDefinitionIdToColIdMap.keySet())
.where(esv.STATISTIC_ID.in(statisticDefinitionIdToColMap.keySet())
.and(esv.CURRENT.eq(true))
.and(esv.ENTITY_KIND.eq(selector.kind().name()))
.and(esv.ENTITY_ID.in(selector.selector())))
.orderBy(esv.OUTCOME)
.fetchGroups(
r -> tuple(
r.get(esv.ENTITY_ID),
statisticDefinitionIdToColIdMap.get(r.get(esv.STATISTIC_ID))),
statisticDefinitionIdToColMap.get(r.get(esv.STATISTIC_ID))),
r -> tuple(
r.get(esv.OUTCOME),
r.get(esv.VALUE),
r.get(esv.REASON)))
.entrySet()
.stream()
.map(kv -> {
Tuple2<Long, ReportGridFixedColumnDefinition> cellKey = kv.getKey();
List<Tuple3<String, String, String>> cellValues = kv.getValue();

String outcomeString = kv.getValue()
String outcomeString = cellValues
.stream()
.map(t -> t.v1)
.sorted(comparing(StringUtilities::lower))
.sorted(comparing(t -> StringUtilities.lower(t.v1)))
.map(t -> {
AdditionalColumnOptions opts = cellKey.v2.additionalColumnOptions();
if (opts == AdditionalColumnOptions.VALUES_ONLY) {
return t.v2;
} else if (opts == AdditionalColumnOptions.VALUES_AND_OUTCOMES) {
return String.format("%s = %s", t.v1, t.v2);
} else {
return t.v1;
}
})
.collect(joining("; "));

List<Tuple2<String, String>> rowsInComment = CollectionUtilities.sort(
kv.getValue(),
List<Tuple3<String, String, String>> rowsInComment = CollectionUtilities.sort(
cellValues,
comparing(t -> lower(safeTrim(t.v1))));

return ImmutableReportGridCell
.builder()
.subjectId(kv.getKey().v1)
.columnDefinitionId(kv.getKey().v2)
.subjectId(cellKey.v1)
.columnDefinitionId(cellKey.v2.gridColumnId())
.textValue(outcomeString)
.comment(toHtmlTable(
asList("Outcome", "Reason"),
asList("Outcome", "Value", "Reason"),
rowsInComment))
.build();
})
Expand Down
Loading

0 comments on commit 76333de

Please sign in to comment.