Skip to content

Commit f7da6e4

Browse files
authored
Merge pull request #4835 from gchq/gh-4831-data-retention-impact-summary
PR for #4831 - Data Retention Impact Summary is not showing any results
2 parents 445ed88 + 1f9eb91 commit f7da6e4

File tree

4 files changed

+148
-83
lines changed

4 files changed

+148
-83
lines changed

Diff for: stroom-core-client/src/main/java/stroom/receive/rules/client/presenter/DataRetentionImpactPresenter.java

+29-12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import stroom.svg.client.Preset;
3737
import stroom.svg.client.SvgPresets;
3838
import stroom.util.client.DataGridUtil;
39+
import stroom.util.shared.GwtNullSafe;
3940
import stroom.widget.button.client.ButtonView;
4041
import stroom.widget.button.client.ToggleButtonView;
4142
import stroom.widget.popup.client.event.ShowPopupEvent;
@@ -221,11 +222,11 @@ private void updateButtonStates() {
221222
flatNestedToggleButton.setState(isTableNested);
222223

223224
expandAllButton.setEnabled(!isQueryRunning
224-
&& isTableNested
225-
&& treeAction.hasCollapsedRows());
225+
&& isTableNested
226+
&& treeAction.hasCollapsedRows());
226227
collapseAllButton.setEnabled(!isQueryRunning
227-
&& isTableNested
228-
&& treeAction.hasExpandedRows());
228+
&& isTableNested
229+
&& treeAction.hasExpandedRows());
229230
}
230231

231232
private void refreshVisibleData() {
@@ -347,48 +348,64 @@ private void initColumns() {
347348
ExpanderCell.getColumnWidth(3)); // Need space for three expander levels
348349

349350
dataGrid.addResizableColumn(
350-
DataGridUtil.textColumnBuilder((DataRetentionImpactRow dataRetentionImpactRow) ->
351-
dataRetentionImpactRow.getRuleNumber().toString())
351+
DataGridUtil.textColumnBuilder((DataRetentionImpactRow row) ->
352+
GwtNullSafe.toString(row.getRuleNumber()))
352353
.rightAligned()
353354
.withSorting(DataRetentionImpactRow.FIELD_NAME_RULE_NO)
354355
.build(),
355-
DataGridUtil.createRightAlignedHeader(DataRetentionImpactRow.FIELD_NAME_RULE_NO),
356+
DataGridUtil.headingBuilder(DataRetentionImpactRow.FIELD_NAME_RULE_NO)
357+
.rightAligned()
358+
.withToolTip("The lower the rule number, the higher priority when matching streams. " +
359+
"A stream's retention will be governed by the matching rule with the " +
360+
"highest priority.")
361+
.build(),
356362
ColumnSizeConstants.SMALL_COL);
357363

358364
dataGrid.addResizableColumn(
359365
DataGridUtil.textColumnBuilder(DataRetentionImpactRow::getRuleName)
360366
.withSorting(DataRetentionImpactRow.FIELD_NAME_RULE_NAME)
361367
.build(),
362-
DataRetentionImpactRow.FIELD_NAME_RULE_NAME,
368+
DataGridUtil.headingBuilder(DataRetentionImpactRow.FIELD_NAME_RULE_NAME)
369+
.withToolTip("The name of the rule.")
370+
.build(),
363371
200);
364372

365373
dataGrid.addResizableColumn(
366374
DataGridUtil.textColumnBuilder(DataRetentionImpactRow::getRuleAgeStr)
367375
.withSorting(DataRetentionImpactRow.FIELD_NAME_RULE_AGE)
368376
.build(),
369-
DataRetentionImpactRow.FIELD_NAME_RULE_AGE,
377+
DataGridUtil.headingBuilder(DataRetentionImpactRow.FIELD_NAME_RULE_AGE)
378+
.withToolTip("The retention age of this rule.")
379+
.build(),
370380
ColumnSizeConstants.MEDIUM_COL);
371381

372382
dataGrid.addResizableColumn(
373383
DataGridUtil.textColumnBuilder(DataRetentionImpactRow::getType)
374384
.withSorting(DataRetentionImpactRow.FIELD_NAME_TYPE)
375385
.build(),
376-
DataRetentionImpactRow.FIELD_NAME_TYPE,
386+
DataGridUtil.headingBuilder(DataRetentionImpactRow.FIELD_NAME_TYPE)
387+
.withToolTip("The stream type.")
388+
.build(),
377389
ColumnSizeConstants.MEDIUM_COL);
378390

379391
dataGrid.addResizableColumn(
380392
DataGridUtil.textColumnBuilder(DataRetentionImpactRow::getFeed)
381393
.withSorting(DataRetentionImpactRow.FIELD_NAME_FEED)
382394
.build(),
383-
DataRetentionImpactRow.FIELD_NAME_FEED,
395+
DataGridUtil.headingBuilder(DataRetentionImpactRow.FIELD_NAME_FEED)
396+
.withToolTip("The feed name.")
397+
.build(),
384398
ColumnSizeConstants.BIG_COL);
385399

386400
dataGrid.addResizableColumn(
387401
DataGridUtil.htmlColumnBuilder(this::getIndentedCountCellText)
388402
.rightAligned()
389403
.withSorting(DataRetentionImpactRow.FIELD_NAME_DELETE_COUNT)
390404
.build(),
391-
DataGridUtil.createRightAlignedHeader(DataRetentionImpactRow.FIELD_NAME_DELETE_COUNT),
405+
DataGridUtil.headingBuilder(DataRetentionImpactRow.FIELD_NAME_DELETE_COUNT)
406+
.rightAligned()
407+
.withToolTip("The number of streams that would be deleted by this rule.")
408+
.build(),
392409
150);
393410

394411
DataGridUtil.addEndColumn(dataGrid);

Diff for: stroom-core-client/src/main/java/stroom/receive/rules/client/presenter/DataRetentionImpactRow.java

+40-58
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import stroom.data.retention.shared.DataRetentionDeleteSummary;
44
import stroom.data.retention.shared.DataRetentionRule;
55
import stroom.data.retention.shared.FindDataRetentionImpactCriteria;
6+
import stroom.util.shared.CompareUtil;
7+
import stroom.util.shared.CriteriaFieldSort;
68
import stroom.util.shared.Expander;
9+
import stroom.util.shared.GwtNullSafe;
710
import stroom.util.shared.time.TimeUnit;
811

912
import java.util.ArrayList;
@@ -15,7 +18,6 @@
1518
import java.util.Objects;
1619
import java.util.Optional;
1720
import java.util.Set;
18-
import java.util.concurrent.atomic.AtomicLong;
1921
import java.util.function.Function;
2022
import java.util.stream.Collectors;
2123

@@ -28,15 +30,15 @@ public class DataRetentionImpactRow {
2830
public static final String FIELD_NAME_TYPE = "Type";
2931
public static final String FIELD_NAME_DELETE_COUNT = "Stream Delete Count";
3032

31-
public static final Comparator<DataRetentionImpactRow> FEED_COMPARATOR = Comparator.comparing(
33+
public static final Comparator<DataRetentionImpactRow> FEED_COMPARATOR = CompareUtil.getNullSafeComparator(
3234
DataRetentionImpactRow::getFeed);
33-
public static final Comparator<DataRetentionImpactRow> TYPE_COMPARATOR = Comparator.comparing(
35+
public static final Comparator<DataRetentionImpactRow> TYPE_COMPARATOR = CompareUtil.getNullSafeComparator(
3436
DataRetentionImpactRow::getType);
3537
public static final Comparator<DataRetentionImpactRow> COUNT_COMPARATOR = Comparator.comparingInt(
3638
DataRetentionImpactRow::getCount);
37-
public static final Comparator<DataRetentionImpactRow> RULE_NO_COMPARATOR = Comparator.comparingInt(
39+
public static final Comparator<DataRetentionImpactRow> RULE_NO_COMPARATOR = CompareUtil.getNullSafeComparator(
3840
DataRetentionImpactRow::getRuleNumber);
39-
public static final Comparator<DataRetentionImpactRow> RULE_NAME_COMPARATOR = Comparator.comparing(
41+
public static final Comparator<DataRetentionImpactRow> RULE_NAME_COMPARATOR = CompareUtil.getNullSafeComparator(
4042
DataRetentionImpactRow::getRuleName);
4143
public static final Comparator<DataRetentionImpactRow> RULE_AGE_COMPARATOR =
4244
Comparator.comparingLong(row ->
@@ -136,21 +138,12 @@ public void setExpander(final Expander expander) {
136138
this.expander = expander;
137139
}
138140

139-
private Comparator<DataRetentionImpactRow> chainComparators(
140-
final Comparator<DataRetentionImpactRow> first,
141-
final Comparator<DataRetentionImpactRow> second) {
142-
143-
if (first == null) {
144-
return second;
145-
} else {
146-
return first.thenComparing(second);
147-
}
148-
}
149-
150141
private static Comparator<DataRetentionImpactRow> buildComparator(final FindDataRetentionImpactCriteria criteria) {
151142

152-
if (criteria != null && criteria.getSortList() != null) {
153-
List<Comparator<DataRetentionImpactRow>> comparators = criteria.getSortList().stream()
143+
final List<CriteriaFieldSort> sortList = criteria.getSortList();
144+
if (GwtNullSafe.hasItems(sortList)) {
145+
//noinspection SimplifyStreamApiCallChains // Cos GWT
146+
List<Comparator<DataRetentionImpactRow>> comparators = sortList.stream()
154147
.filter(Objects::nonNull)
155148
.map(sort ->
156149
Optional.ofNullable(FIELD_TO_COMPARATOR_MAP.get(sort.getId()))
@@ -186,10 +179,9 @@ public static List<DataRetentionImpactRow> buildFlatTable(final List<DataRetenti
186179

187180
Map<Integer, DataRetentionRule> ruleNoToRuleMap = rules.stream()
188181
.collect(Collectors.toMap(
189-
rule -> Integer.valueOf(rule.getRuleNumber()), // Manual boxing to keep GWT happy
182+
DataRetentionRule::getRuleNumber, // Manual boxing to keep GWT happy
190183
Function.identity()));
191184

192-
final AtomicLong rowNumber = new AtomicLong(1);
193185
return summaries.stream()
194186
.map(summary -> {
195187
final DataRetentionRule rule = ruleNoToRuleMap.get(summary.getRuleNumber());
@@ -224,8 +216,6 @@ public static List<DataRetentionImpactRow> buildNestedTable(final List<DataReten
224216
DataRetentionDeleteSummary::getRuleNumber,
225217
Collectors.toSet()));
226218

227-
final AtomicLong rowNumber = new AtomicLong(1);
228-
229219
rules.stream()
230220
.map(rule ->
231221
buildRuleRow(
@@ -274,14 +264,15 @@ public static List<DataRetentionImpactRow> buildNestedTable(final List<DataReten
274264
summariesByRuleAndType.get(metaTypeRow.getType());
275265

276266
if (isExpanded(treeAction, metaTypeRow, 1)
277-
&& summariesForRuleAndType != null) {
267+
&& summariesForRuleAndType != null) {
278268

279269
Comparator<DataRetentionImpactRow> feedRowComparator = getComparator(
280270
criteria,
281271
FEED_COMPARATOR,
282272
FIELD_NAME_FEED,
283273
FIELD_NAME_DELETE_COUNT);
284274

275+
//noinspection SimplifyStreamApiCallChains // Cos GWT
285276
rows.addAll(summariesForRuleAndType.stream()
286277
.map(summaryForRuleTypeAndFeed ->
287278
buildFeedRow(
@@ -305,8 +296,9 @@ private static Comparator<DataRetentionImpactRow> getComparator(
305296
// If the sort list contains any of the sortableFieldNames then create a
306297
// comparator for it. Assumes only one sort in the sort list
307298

308-
if (criteria.getSortList() != null && !criteria.getSortList().isEmpty()) {
309-
return criteria.getSortList().stream()
299+
final List<CriteriaFieldSort> sortList = criteria.getSortList();
300+
if (GwtNullSafe.hasItems(sortList)) {
301+
return sortList.stream()
310302
.filter(sort ->
311303
Arrays.stream(sortableFieldNames)
312304
.anyMatch(fieldName ->
@@ -327,14 +319,9 @@ private static Comparator<DataRetentionImpactRow> getComparator(
327319
private static DataRetentionImpactRow buildRuleRow(final DataRetentionRule rule,
328320
final DataRetentionImpactTreeAction treeAction,
329321
final Set<DataRetentionDeleteSummary> summaries) {
330-
final int totalCount;
331-
if (summaries != null) {
332-
totalCount = summaries.stream()
333-
.mapToInt(DataRetentionDeleteSummary::getCount)
334-
.sum();
335-
} else {
336-
totalCount = 0;
337-
}
322+
final int totalCount = GwtNullSafe.stream(summaries)
323+
.mapToInt(DataRetentionDeleteSummary::getCount)
324+
.sum();
338325

339326
// TODO once we have built all the rows we will still have all the source data in memory.
340327
// We could change this class so it holds a ref to the source summary object and then
@@ -359,7 +346,7 @@ private static DataRetentionImpactRow buildRuleRow(final DataRetentionRule rule,
359346
totalCount);
360347

361348
final int depth = 0;
362-
final boolean isLeaf = summaries == null || summaries.isEmpty();
349+
final boolean isLeaf = GwtNullSafe.isEmptyCollection(summaries);
363350

364351
setExpander(treeAction, row, depth, isLeaf);
365352

@@ -372,14 +359,9 @@ private static DataRetentionImpactRow buildMetaTypeRow(final int ruleNumber,
372359
final Set<DataRetentionDeleteSummary> summaries,
373360
final DataRetentionImpactTreeAction treeAction) {
374361

375-
final int countByRuleAndFeed;
376-
if (summaries != null) {
377-
countByRuleAndFeed = summaries.stream()
378-
.mapToInt(DataRetentionDeleteSummary::getCount)
379-
.sum();
380-
} else {
381-
countByRuleAndFeed = 0;
382-
}
362+
final int countByRuleAndFeed = GwtNullSafe.stream(summaries)
363+
.mapToInt(DataRetentionDeleteSummary::getCount)
364+
.sum();
383365

384366
final DataRetentionImpactRow row = new DataRetentionImpactRow(
385367
buildRowKey(ruleNumber, metaType, null),
@@ -393,7 +375,7 @@ private static DataRetentionImpactRow buildMetaTypeRow(final int ruleNumber,
393375
countByRuleAndFeed);
394376

395377
final int depth = 1;
396-
final boolean isLeaf = summaries == null || summaries.isEmpty();
378+
final boolean isLeaf = GwtNullSafe.isEmptyCollection(summaries);
397379

398380
setExpander(treeAction, row, depth, isLeaf);
399381

@@ -464,12 +446,12 @@ public boolean equals(final Object o) {
464446
}
465447
final DataRetentionImpactRow that = (DataRetentionImpactRow) o;
466448
return count == that.count &&
467-
Objects.equals(rowKey, that.rowKey) &&
468-
Objects.equals(ruleNumber, that.ruleNumber) &&
469-
Objects.equals(ruleName, that.ruleName) &&
470-
Objects.equals(ruleAgeStr, that.ruleAgeStr) &&
471-
Objects.equals(feed, that.feed) &&
472-
Objects.equals(type, that.type);
449+
Objects.equals(rowKey, that.rowKey) &&
450+
Objects.equals(ruleNumber, that.ruleNumber) &&
451+
Objects.equals(ruleName, that.ruleName) &&
452+
Objects.equals(ruleAgeStr, that.ruleAgeStr) &&
453+
Objects.equals(feed, that.feed) &&
454+
Objects.equals(type, that.type);
473455
}
474456

475457
@Override
@@ -480,15 +462,15 @@ public int hashCode() {
480462
@Override
481463
public String toString() {
482464
return "DataRetentionImpactRow{" +
483-
"rowKey=" + rowKey +
484-
", ruleNumber=" + ruleNumber +
485-
", ruleName='" + ruleName + '\'' +
486-
", ruleAge='" + ruleAgeStr + '\'' +
487-
", feedName='" + feed + '\'' +
488-
", metaType='" + type + '\'' +
489-
", count=" + count +
490-
", expander=" + expander +
491-
'}';
465+
"rowKey=" + rowKey +
466+
", ruleNumber=" + ruleNumber +
467+
", ruleName='" + ruleName + '\'' +
468+
", ruleAge='" + ruleAgeStr + '\'' +
469+
", feedName='" + feed + '\'' +
470+
", metaType='" + type + '\'' +
471+
", count=" + count +
472+
", expander=" + expander +
473+
'}';
492474
}
493475

494476
/**

0 commit comments

Comments
 (0)