TSK-1344: added key for all rows
This commit is contained in:
parent
d8b9c6fed9
commit
278d17ecfe
|
@ -71,8 +71,8 @@ public class ClassificationReport extends Report<MonitorQueryItem, TimeIntervalC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DetailedClassificationRow createRow(int columnSize) {
|
protected DetailedClassificationRow createRow(String key, int columnSize) {
|
||||||
return new DetailedClassificationRow(columnSize);
|
return new DetailedClassificationRow(key, columnSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public abstract class Report<I extends QueryItem, H extends ColumnHeader<? super
|
||||||
|
|
||||||
protected Report(List<H> columnHeaders, String[] rowDesc) {
|
protected Report(List<H> columnHeaders, String[] rowDesc) {
|
||||||
this.rowDesc = rowDesc;
|
this.rowDesc = rowDesc;
|
||||||
sumRow = createRow(columnHeaders.size());
|
sumRow = createRow("Total", columnHeaders.size());
|
||||||
this.columnHeaders = new ArrayList<>(columnHeaders);
|
this.columnHeaders = new ArrayList<>(columnHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,14 +69,16 @@ public abstract class Report<I extends QueryItem, H extends ColumnHeader<? super
|
||||||
public final void addItem(I item) {
|
public final void addItem(I item) {
|
||||||
Row<I> row = null;
|
Row<I> row = null;
|
||||||
if (columnHeaders.isEmpty()) {
|
if (columnHeaders.isEmpty()) {
|
||||||
row = reportRows.computeIfAbsent(item.getKey(), (s) -> createRow(columnHeaders.size()));
|
row = reportRows.computeIfAbsent(item.getKey(), key -> createRow(key, columnHeaders.size()));
|
||||||
row.updateTotalValue(item);
|
row.updateTotalValue(item);
|
||||||
sumRow.updateTotalValue(item);
|
sumRow.updateTotalValue(item);
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < columnHeaders.size(); i++) {
|
for (int i = 0; i < columnHeaders.size(); i++) {
|
||||||
if (columnHeaders.get(i).fits(item)) {
|
if (columnHeaders.get(i).fits(item)) {
|
||||||
if (row == null) {
|
if (row == null) {
|
||||||
row = reportRows.computeIfAbsent(item.getKey(), (s) -> createRow(columnHeaders.size()));
|
row =
|
||||||
|
reportRows.computeIfAbsent(
|
||||||
|
item.getKey(), key -> createRow(key, columnHeaders.size()));
|
||||||
}
|
}
|
||||||
row.addItem(item, i);
|
row.addItem(item, i);
|
||||||
sumRow.addItem(item, i);
|
sumRow.addItem(item, i);
|
||||||
|
@ -97,8 +99,8 @@ public abstract class Report<I extends QueryItem, H extends ColumnHeader<? super
|
||||||
items.forEach(this::addItem);
|
items.forEach(this::addItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Row<I> createRow(int columnSize) {
|
protected Row<I> createRow(String key, int columnSize) {
|
||||||
return new SingleRow<>(columnSize);
|
return new SingleRow<>(key, columnSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,8 +23,8 @@ public class TimestampReport extends Report<TimestampQueryItem, TimeIntervalColu
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TimestampRow createRow(int columnSize) {
|
protected TimestampRow createRow(String key, int columnSize) {
|
||||||
return new TimestampRow(columnSize);
|
return new TimestampRow(key, columnSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Builder for {@link TimestampReport}. */
|
/** Builder for {@link TimestampReport}. */
|
||||||
|
|
|
@ -9,8 +9,11 @@ import pro.taskana.monitor.api.reports.item.DetailedMonitorQueryItem;
|
||||||
*/
|
*/
|
||||||
public class DetailedClassificationRow extends FoldableRow<DetailedMonitorQueryItem> {
|
public class DetailedClassificationRow extends FoldableRow<DetailedMonitorQueryItem> {
|
||||||
|
|
||||||
public DetailedClassificationRow(int columnSize) {
|
public DetailedClassificationRow(String key, int columnSize) {
|
||||||
super(columnSize, (item) -> item.getAttachmentKey() != null ? item.getAttachmentKey() : "N/A");
|
super(
|
||||||
|
key,
|
||||||
|
columnSize,
|
||||||
|
(item) -> item.getAttachmentKey() != null ? item.getAttachmentKey() : "N/A");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,7 +22,7 @@ public class DetailedClassificationRow extends FoldableRow<DetailedMonitorQueryI
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Row<DetailedMonitorQueryItem> buildRow(int columnSize) {
|
protected Row<DetailedMonitorQueryItem> buildRow(String key, int columnSize) {
|
||||||
return new SingleRow<>(columnSize);
|
return new SingleRow<>(key, columnSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,12 +17,13 @@ import pro.taskana.monitor.api.reports.item.QueryItem;
|
||||||
*/
|
*/
|
||||||
public abstract class FoldableRow<I extends QueryItem> extends SingleRow<I> {
|
public abstract class FoldableRow<I extends QueryItem> extends SingleRow<I> {
|
||||||
|
|
||||||
private Map<String, Row<I>> foldableRows = new LinkedHashMap<>();
|
private final Map<String, Row<I>> foldableRows = new LinkedHashMap<>();
|
||||||
private Function<? super I, String> calcFoldableRowKey;
|
private final Function<? super I, String> calcFoldableRowKey;
|
||||||
private int columnSize;
|
private final int columnSize;
|
||||||
|
|
||||||
protected FoldableRow(int columnSize, Function<? super I, String> calcFoldableRowKey) {
|
protected FoldableRow(
|
||||||
super(columnSize);
|
String key, int columnSize, Function<? super I, String> calcFoldableRowKey) {
|
||||||
|
super(key, columnSize);
|
||||||
this.columnSize = columnSize;
|
this.columnSize = columnSize;
|
||||||
this.calcFoldableRowKey = calcFoldableRowKey;
|
this.calcFoldableRowKey = calcFoldableRowKey;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +40,7 @@ public abstract class FoldableRow<I extends QueryItem> extends SingleRow<I> {
|
||||||
public void addItem(I item, int index) throws IndexOutOfBoundsException {
|
public void addItem(I item, int index) throws IndexOutOfBoundsException {
|
||||||
super.addItem(item, index);
|
super.addItem(item, index);
|
||||||
foldableRows
|
foldableRows
|
||||||
.computeIfAbsent(calcFoldableRowKey.apply(item), (s) -> buildRow(columnSize))
|
.computeIfAbsent(calcFoldableRowKey.apply(item), key -> buildRow(key, columnSize))
|
||||||
.addItem(item, index);
|
.addItem(item, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ public abstract class FoldableRow<I extends QueryItem> extends SingleRow<I> {
|
||||||
public void updateTotalValue(I item) {
|
public void updateTotalValue(I item) {
|
||||||
super.updateTotalValue(item);
|
super.updateTotalValue(item);
|
||||||
foldableRows
|
foldableRows
|
||||||
.computeIfAbsent(calcFoldableRowKey.apply(item), (s) -> buildRow(columnSize))
|
.computeIfAbsent(calcFoldableRowKey.apply(item), key -> buildRow(key, columnSize))
|
||||||
.updateTotalValue(item);
|
.updateTotalValue(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ public abstract class FoldableRow<I extends QueryItem> extends SingleRow<I> {
|
||||||
return foldableRows.get(key);
|
return foldableRows.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract Row<I> buildRow(int columnSize);
|
protected abstract Row<I> buildRow(String key, int columnSize);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -28,6 +28,8 @@ public interface Row<I extends QueryItem> {
|
||||||
*/
|
*/
|
||||||
void updateTotalValue(I item);
|
void updateTotalValue(I item);
|
||||||
|
|
||||||
|
String getKey();
|
||||||
|
|
||||||
int getTotalValue();
|
int getTotalValue();
|
||||||
|
|
||||||
int[] getCells();
|
int[] getCells();
|
||||||
|
|
|
@ -14,8 +14,10 @@ public class SingleRow<I extends QueryItem> implements Row<I> {
|
||||||
|
|
||||||
private final int[] cells;
|
private final int[] cells;
|
||||||
private int total = 0;
|
private int total = 0;
|
||||||
|
private final String key;
|
||||||
|
|
||||||
public SingleRow(int columnCount) {
|
public SingleRow(String key, int columnCount) {
|
||||||
|
this.key = key;
|
||||||
cells = new int[columnCount];
|
cells = new int[columnCount];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +32,11 @@ public class SingleRow<I extends QueryItem> implements Row<I> {
|
||||||
total += item.getValue();
|
total += item.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int getTotalValue() {
|
public final int getTotalValue() {
|
||||||
return total;
|
return total;
|
||||||
|
|
|
@ -9,8 +9,8 @@ import pro.taskana.monitor.api.reports.item.TimestampQueryItem;
|
||||||
*/
|
*/
|
||||||
public class TimestampRow extends FoldableRow<TimestampQueryItem> {
|
public class TimestampRow extends FoldableRow<TimestampQueryItem> {
|
||||||
|
|
||||||
public TimestampRow(int columnSize) {
|
public TimestampRow(String key, int columnSize) {
|
||||||
super(columnSize, TimestampQueryItem::getOrgLevel1);
|
super(key, columnSize, TimestampQueryItem::getOrgLevel1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,8 +19,8 @@ public class TimestampRow extends FoldableRow<TimestampQueryItem> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
OrgLevel1Row buildRow(int columnSize) {
|
protected OrgLevel1Row buildRow(String key, int columnSize) {
|
||||||
return new OrgLevel1Row(columnSize);
|
return new OrgLevel1Row(key, columnSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,8 +29,8 @@ public class TimestampRow extends FoldableRow<TimestampQueryItem> {
|
||||||
*/
|
*/
|
||||||
public static final class OrgLevel1Row extends FoldableRow<TimestampQueryItem> {
|
public static final class OrgLevel1Row extends FoldableRow<TimestampQueryItem> {
|
||||||
|
|
||||||
private OrgLevel1Row(int columnSize) {
|
private OrgLevel1Row(String key, int columnSize) {
|
||||||
super(columnSize, TimestampQueryItem::getOrgLevel2);
|
super(key, columnSize, TimestampQueryItem::getOrgLevel2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -39,8 +39,8 @@ public class TimestampRow extends FoldableRow<TimestampQueryItem> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
OrgLevel2Row buildRow(int columnSize) {
|
protected OrgLevel2Row buildRow(String key, int columnSize) {
|
||||||
return new OrgLevel2Row(columnSize);
|
return new OrgLevel2Row(key, columnSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +50,8 @@ public class TimestampRow extends FoldableRow<TimestampQueryItem> {
|
||||||
*/
|
*/
|
||||||
public static final class OrgLevel2Row extends FoldableRow<TimestampQueryItem> {
|
public static final class OrgLevel2Row extends FoldableRow<TimestampQueryItem> {
|
||||||
|
|
||||||
private OrgLevel2Row(int columnSize) {
|
private OrgLevel2Row(String key, int columnSize) {
|
||||||
super(columnSize, TimestampQueryItem::getOrgLevel3);
|
super(key, columnSize, TimestampQueryItem::getOrgLevel3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,8 +60,8 @@ public class TimestampRow extends FoldableRow<TimestampQueryItem> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
OrgLevel3Row buildRow(int columnSize) {
|
protected OrgLevel3Row buildRow(String key, int columnSize) {
|
||||||
return new OrgLevel3Row(columnSize);
|
return new OrgLevel3Row(key, columnSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,8 +71,8 @@ public class TimestampRow extends FoldableRow<TimestampQueryItem> {
|
||||||
*/
|
*/
|
||||||
public static final class OrgLevel3Row extends FoldableRow<TimestampQueryItem> {
|
public static final class OrgLevel3Row extends FoldableRow<TimestampQueryItem> {
|
||||||
|
|
||||||
private OrgLevel3Row(int columnSize) {
|
private OrgLevel3Row(String key, int columnSize) {
|
||||||
super(columnSize, TimestampQueryItem::getOrgLevel4);
|
super(key, columnSize, TimestampQueryItem::getOrgLevel4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -81,8 +81,8 @@ public class TimestampRow extends FoldableRow<TimestampQueryItem> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Row<TimestampQueryItem> buildRow(int columnSize) {
|
protected Row<TimestampQueryItem> buildRow(String key, int columnSize) {
|
||||||
return new SingleRow<>(columnSize);
|
return new SingleRow<>(key, columnSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,9 @@ import pro.taskana.monitor.api.reports.Report;
|
||||||
import pro.taskana.monitor.api.reports.header.TimeIntervalColumnHeader;
|
import pro.taskana.monitor.api.reports.header.TimeIntervalColumnHeader;
|
||||||
import pro.taskana.monitor.api.reports.item.MonitorQueryItem;
|
import pro.taskana.monitor.api.reports.item.MonitorQueryItem;
|
||||||
import pro.taskana.monitor.api.reports.item.QueryItemPreprocessor;
|
import pro.taskana.monitor.api.reports.item.QueryItemPreprocessor;
|
||||||
|
import pro.taskana.monitor.api.reports.row.FoldableRow;
|
||||||
import pro.taskana.monitor.api.reports.row.Row;
|
import pro.taskana.monitor.api.reports.row.Row;
|
||||||
|
import pro.taskana.monitor.api.reports.row.SingleRow;
|
||||||
|
|
||||||
/** Tests for {@link Report}. */
|
/** Tests for {@link Report}. */
|
||||||
class ReportTest {
|
class ReportTest {
|
||||||
|
@ -37,7 +39,12 @@ class ReportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testEmptyReport() {
|
void should_HaveSumRowTotalKey_When_ReportExists() {
|
||||||
|
assertThat(report.getSumRow().getKey()).isEqualTo("Total");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void should_HaveEmptySumRow_When_ReportIsEmpty() {
|
||||||
// then
|
// then
|
||||||
assertThat(report.getRows()).isEmpty();
|
assertThat(report.getRows()).isEmpty();
|
||||||
Row<MonitorQueryItem> sumRow = report.getSumRow();
|
Row<MonitorQueryItem> sumRow = report.getSumRow();
|
||||||
|
@ -46,7 +53,54 @@ class ReportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInsertSingleItem() {
|
void should_CreateRowAndSetKey_When_InsertingItemWithUnknownKey() {
|
||||||
|
// when
|
||||||
|
report.addItem(item);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(report.getRows()).hasSize(1);
|
||||||
|
Row<MonitorQueryItem> row = report.getRow("key");
|
||||||
|
assertThat(row.getKey()).isEqualTo("key");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void should_CreateFoldableRowAndSetKey_When_InsertingItemWithUnknownKey() {
|
||||||
|
// when
|
||||||
|
ReportWithFoldableRow report =
|
||||||
|
new ReportWithFoldableRow(HEADERS, new String[] {"rowDesc", "foldableRowDesc"});
|
||||||
|
report.addItem(item);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(report.getRows()).hasSize(1);
|
||||||
|
FoldableTestRow row = report.getRow("key");
|
||||||
|
assertThat(row.getKey()).isEqualTo("key");
|
||||||
|
|
||||||
|
assertThat(row.getFoldableRowCount()).isOne();
|
||||||
|
Row<MonitorQueryItem> foldableRow = row.getFoldableRow("KEY");
|
||||||
|
assertThat(foldableRow.getKey()).isEqualTo("KEY");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void should_AppendItemValueInFoldableRow_When_ItemIsInserted() {
|
||||||
|
// when
|
||||||
|
ReportWithFoldableRow report =
|
||||||
|
new ReportWithFoldableRow(HEADERS, new String[] {"rowDesc", "foldableRowDesc"});
|
||||||
|
report.addItem(item);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(report.getRows()).hasSize(1);
|
||||||
|
FoldableTestRow row = report.getRow("key");
|
||||||
|
assertThat(row.getCells()).isEqualTo(new int[] {item.getValue(), 0, 0, 0});
|
||||||
|
assertThat(row.getTotalValue()).isEqualTo(item.getValue());
|
||||||
|
|
||||||
|
assertThat(row.getFoldableRowCount()).isOne();
|
||||||
|
Row<MonitorQueryItem> foldableRow = row.getFoldableRow("KEY");
|
||||||
|
assertThat(foldableRow.getCells()).isEqualTo(new int[] {item.getValue(), 0, 0, 0});
|
||||||
|
assertThat(foldableRow.getTotalValue()).isEqualTo(item.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void should_AppendItemValue_When_ItemIsInserted() {
|
||||||
// when
|
// when
|
||||||
report.addItem(item);
|
report.addItem(item);
|
||||||
|
|
||||||
|
@ -58,7 +112,7 @@ class ReportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInsertSameItemMultipleTimes() {
|
void should_AppendItemValue_When_CellAlreadyContainsValue() {
|
||||||
// when
|
// when
|
||||||
report.addItem(item);
|
report.addItem(item);
|
||||||
report.addItem(item);
|
report.addItem(item);
|
||||||
|
@ -71,13 +125,7 @@ class ReportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInsertSameItemMultipleTimes2() {
|
void should_AppendItemValue_When_UsingBulkOperationToInsertItems() {
|
||||||
// given
|
|
||||||
MonitorQueryItem item = new MonitorQueryItem();
|
|
||||||
item.setKey("key");
|
|
||||||
item.setAgeInDays(0);
|
|
||||||
item.setNumberOfTasks(3);
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
report.addItems(Arrays.asList(item, item));
|
report.addItems(Arrays.asList(item, item));
|
||||||
|
|
||||||
|
@ -89,80 +137,7 @@ class ReportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInsertSameItemMultipleTimesWithPreProcessor() {
|
void should_PreProcessItem_When_PreprocessorIsDefined() {
|
||||||
// given
|
|
||||||
int overrideValue = 5;
|
|
||||||
QueryItemPreprocessor<MonitorQueryItem> preprocessor =
|
|
||||||
(item) -> {
|
|
||||||
item.setNumberOfTasks(overrideValue);
|
|
||||||
return item;
|
|
||||||
};
|
|
||||||
// when
|
|
||||||
report.addItems(Arrays.asList(item, item), preprocessor);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(report.getRows()).hasSize(1);
|
|
||||||
Row<MonitorQueryItem> row = report.getRow("key");
|
|
||||||
assertThat(row.getCells()).isEqualTo(new int[] {2 * overrideValue, 0, 0, 0});
|
|
||||||
assertThat(row.getTotalValue()).isEqualTo(2 * overrideValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testInsertItemWithNoColumnHeaders() {
|
|
||||||
// given
|
|
||||||
List<TimeIntervalColumnHeader> headerList = Collections.emptyList();
|
|
||||||
report =
|
|
||||||
new MonitorQueryItemTimeIntervalColumnHeaderReport(headerList, new String[] {"rowDesc"});
|
|
||||||
|
|
||||||
// when
|
|
||||||
report.addItem(item);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(report.getRows()).hasSize(1);
|
|
||||||
assertThat(report.getRow("key").getCells()).isEqualTo(new int[0]);
|
|
||||||
assertThat(report.getRow("key").getTotalValue()).isEqualTo(item.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testInsertItemWhichIsNotInHeaderScopes() {
|
|
||||||
// given
|
|
||||||
item.setAgeInDays(-2);
|
|
||||||
// when
|
|
||||||
report.addItem(item);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(report.getRows()).isEmpty();
|
|
||||||
Row<MonitorQueryItem> sumRow = report.getSumRow();
|
|
||||||
assertThat(sumRow.getCells()).isEqualTo(new int[] {0, 0, 0, 0});
|
|
||||||
assertThat(sumRow.getTotalValue()).isEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testInsertItemWhichIsInMultipleHeaderScopes() {
|
|
||||||
// given
|
|
||||||
List<TimeIntervalColumnHeader> headers = new ArrayList<>(HEADERS);
|
|
||||||
headers.add(new TimeIntervalColumnHeader(0, 3));
|
|
||||||
report = new MonitorQueryItemTimeIntervalColumnHeaderReport(headers, new String[] {"rowDesc"});
|
|
||||||
|
|
||||||
item.setAgeInDays(2);
|
|
||||||
|
|
||||||
// when
|
|
||||||
report.addItem(item);
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(report.getRows()).hasSize(1);
|
|
||||||
|
|
||||||
Row<MonitorQueryItem> row = report.getRow("key");
|
|
||||||
assertThat(row.getCells()).isEqualTo(new int[] {0, 0, item.getValue(), 0, item.getValue()});
|
|
||||||
assertThat(row.getTotalValue()).isEqualTo(2 * item.getValue());
|
|
||||||
|
|
||||||
Row<MonitorQueryItem> sumRow = report.getSumRow();
|
|
||||||
assertThat(sumRow.getCells()).isEqualTo(new int[] {0, 0, item.getValue(), 0, item.getValue()});
|
|
||||||
assertThat(sumRow.getTotalValue()).isEqualTo(2 * item.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testInsertItemWithPreProcessor() {
|
|
||||||
// given
|
// given
|
||||||
int overrideValue = 5;
|
int overrideValue = 5;
|
||||||
QueryItemPreprocessor<MonitorQueryItem> preprocessor =
|
QueryItemPreprocessor<MonitorQueryItem> preprocessor =
|
||||||
|
@ -187,6 +162,79 @@ class ReportTest {
|
||||||
assertThat(sumRow.getTotalValue()).isEqualTo(overrideValue);
|
assertThat(sumRow.getTotalValue()).isEqualTo(overrideValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void should_PreProcessItem_When_PreprocessorIsDefinedForBulkInsert() {
|
||||||
|
// given
|
||||||
|
int overrideValue = 5;
|
||||||
|
QueryItemPreprocessor<MonitorQueryItem> preprocessor =
|
||||||
|
(item) -> {
|
||||||
|
item.setNumberOfTasks(overrideValue);
|
||||||
|
return item;
|
||||||
|
};
|
||||||
|
// when
|
||||||
|
report.addItems(Arrays.asList(item, item), preprocessor);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(report.getRows()).hasSize(1);
|
||||||
|
Row<MonitorQueryItem> row = report.getRow("key");
|
||||||
|
assertThat(row.getCells()).isEqualTo(new int[] {2 * overrideValue, 0, 0, 0});
|
||||||
|
assertThat(row.getTotalValue()).isEqualTo(2 * overrideValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void should_OnlyContainTotalRows_When_ReportContainsNoHeaders() {
|
||||||
|
// given
|
||||||
|
List<TimeIntervalColumnHeader> headerList = Collections.emptyList();
|
||||||
|
report =
|
||||||
|
new MonitorQueryItemTimeIntervalColumnHeaderReport(headerList, new String[] {"rowDesc"});
|
||||||
|
|
||||||
|
// when
|
||||||
|
report.addItem(item);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(report.getRows()).hasSize(1);
|
||||||
|
assertThat(report.getRow("key").getCells()).isEqualTo(new int[0]);
|
||||||
|
assertThat(report.getRow("key").getTotalValue()).isEqualTo(item.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void should_NotInsertItem_When_ItemIsOutOfHeaderScope() {
|
||||||
|
// given
|
||||||
|
item.setAgeInDays(-2);
|
||||||
|
// when
|
||||||
|
report.addItem(item);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(report.getRows()).isEmpty();
|
||||||
|
Row<MonitorQueryItem> sumRow = report.getSumRow();
|
||||||
|
assertThat(sumRow.getCells()).isEqualTo(new int[] {0, 0, 0, 0});
|
||||||
|
assertThat(sumRow.getTotalValue()).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void should_InsertItemMultipleTimes_When_HeaderFitsMultipleTimes() {
|
||||||
|
// given
|
||||||
|
List<TimeIntervalColumnHeader> headers = new ArrayList<>(HEADERS);
|
||||||
|
headers.add(new TimeIntervalColumnHeader(0, 3));
|
||||||
|
report = new MonitorQueryItemTimeIntervalColumnHeaderReport(headers, new String[] {"rowDesc"});
|
||||||
|
|
||||||
|
item.setAgeInDays(2);
|
||||||
|
|
||||||
|
// when
|
||||||
|
report.addItem(item);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(report.getRows()).hasSize(1);
|
||||||
|
|
||||||
|
Row<MonitorQueryItem> row = report.getRow("key");
|
||||||
|
assertThat(row.getCells()).isEqualTo(new int[] {0, 0, item.getValue(), 0, item.getValue()});
|
||||||
|
assertThat(row.getTotalValue()).isEqualTo(2 * item.getValue());
|
||||||
|
|
||||||
|
Row<MonitorQueryItem> sumRow = report.getSumRow();
|
||||||
|
assertThat(sumRow.getCells()).isEqualTo(new int[] {0, 0, item.getValue(), 0, item.getValue()});
|
||||||
|
assertThat(sumRow.getTotalValue()).isEqualTo(2 * item.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
private static class MonitorQueryItemTimeIntervalColumnHeaderReport
|
private static class MonitorQueryItemTimeIntervalColumnHeaderReport
|
||||||
extends Report<MonitorQueryItem, TimeIntervalColumnHeader> {
|
extends Report<MonitorQueryItem, TimeIntervalColumnHeader> {
|
||||||
|
|
||||||
|
@ -195,4 +243,35 @@ class ReportTest {
|
||||||
super(headerList, rowDesc);
|
super(headerList, rowDesc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class ReportWithFoldableRow
|
||||||
|
extends Report<MonitorQueryItem, TimeIntervalColumnHeader> {
|
||||||
|
|
||||||
|
protected ReportWithFoldableRow(
|
||||||
|
List<TimeIntervalColumnHeader> columnHeaders, String[] rowDesc) {
|
||||||
|
super(columnHeaders, rowDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FoldableTestRow getRow(String key) {
|
||||||
|
return (FoldableTestRow) super.getRow(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Row<MonitorQueryItem> createRow(String key, int columnSize) {
|
||||||
|
return new FoldableTestRow(key, columnSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FoldableTestRow extends FoldableRow<MonitorQueryItem> {
|
||||||
|
|
||||||
|
protected FoldableTestRow(String key, int columnSize) {
|
||||||
|
super(key, columnSize, (item) -> item.getKey().toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Row<MonitorQueryItem> buildRow(String key, int columnSize) {
|
||||||
|
return new SingleRow<>(key, columnSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,11 @@ public class ReportRepresentationModelAssembler {
|
||||||
report.getColumnHeaders().stream().map(H::getDisplayName).toArray(String[]::new);
|
report.getColumnHeaders().stream().map(H::getDisplayName).toArray(String[]::new);
|
||||||
ReportRepresentationModel.MetaInformation meta =
|
ReportRepresentationModel.MetaInformation meta =
|
||||||
new ReportRepresentationModel.MetaInformation(
|
new ReportRepresentationModel.MetaInformation(
|
||||||
report.getClass().getSimpleName(), time.toString(), header, report.getRowDesc());
|
report.getClass().getSimpleName(),
|
||||||
|
time.toString(),
|
||||||
|
header,
|
||||||
|
report.getRowDesc(),
|
||||||
|
report.getSumRow().getKey());
|
||||||
|
|
||||||
// iterate over each Row and transform it to a RowResource while keeping the domain key.
|
// iterate over each Row and transform it to a RowResource while keeping the domain key.
|
||||||
List<ReportRepresentationModel.RowResource> rows =
|
List<ReportRepresentationModel.RowResource> rows =
|
||||||
|
|
|
@ -88,22 +88,22 @@ public class ReportRepresentationModel extends RepresentationModel<ReportReprese
|
||||||
/** Meta Information about this ReportResource. */
|
/** Meta Information about this ReportResource. */
|
||||||
public static class MetaInformation {
|
public static class MetaInformation {
|
||||||
|
|
||||||
private static final String TOTAL_DESC = "Total";
|
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String date;
|
private final String date;
|
||||||
private final String[] header;
|
private final String[] header;
|
||||||
private final String[] rowDesc;
|
private final String[] rowDesc;
|
||||||
|
private final String totalDesc;
|
||||||
|
|
||||||
public MetaInformation(String name, String date, String[] header, String[] rowDesc) {
|
public MetaInformation(String name, String date, String[] header, String[] rowDesc, String totalDesc) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
this.header = header;
|
this.header = header;
|
||||||
this.rowDesc = rowDesc;
|
this.rowDesc = rowDesc;
|
||||||
|
this.totalDesc = totalDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTotalDesc() {
|
public String getTotalDesc() {
|
||||||
return TOTAL_DESC;
|
return totalDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
Loading…
Reference in New Issue