Skip to content

Commit

Permalink
fix: Fix the usage of pivot type with all pivot options (#68)
Browse files Browse the repository at this point in the history
Co-authored-by: Romuald Rousseau <[email protected]>
  • Loading branch information
RomualdRousseau and Romuald Rousseau authored Dec 11, 2024
1 parent 9c4e671 commit 38aadfb
Showing 1 changed file with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ private void addTmpHeader(final BaseHeader header, final Set<String> pivotEntryT

if (header instanceof PivotKeyHeader) {
final var pivotHeader = (PivotKeyHeader) header.clone();

if (!pivotEntryTypes.isEmpty()) {
pivotHeader.setEntryTypeValues(pivotEntryTypes);
}

if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE_AND_VALUE) {
if (!pivotEntryTypes.isEmpty()) {
pivotHeader.setEntryTypeValues(pivotEntryTypes);
}
this.addHeaderIntoTmpHeaders(pivotHeader, false);
pivotHeader.getEntryTypeValues().forEach(
x -> this.addHeaderIntoTmpHeaders(pivotHeader.getPivotTypeHeader().clone().setName(x), false));
Expand Down Expand Up @@ -191,20 +193,23 @@ private List<Row> emitAllRowsForOneRow(final BaseTableGraph graph, final DataTab
}
if (pivotKeyHeader == null) {
this.emitOneRowWithoutPivot(graph, orgTable, orgRow, rowGroup).ifPresent(newRows::add);
} else if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE_AND_VALUE) {
pivotKeyHeader.getEntryPivotValues()
.forEach(x -> this
.emitOneRowWithPivotTypeAndValue(graph, orgTable, orgRow, rowGroup, pivotKeyHeader, x,
this.findTypeValue(orgTable, orgRow, pivotTypeHeader))
.ifPresent(newRows::add));
} else if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE) {
pivotKeyHeader.getEntries()
.forEach(x -> this.emitOneRowWithPivotAndType(graph, orgTable, orgRow, rowGroup, x)
.ifPresent(newRows::add));
} else {
pivotKeyHeader.getEntries()
.forEach(x -> this.emitOneRowWithPivot(graph, orgTable, orgRow, rowGroup, x)
.ifPresent(newRows::add));
final var typeValue = this.findTypeValue(orgTable, orgRow, pivotTypeHeader);
if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE_AND_VALUE) {
pivotKeyHeader.getEntryPivotValues()
.forEach(x -> this
.emitOneRowWithPivotTypeAndValue(graph, orgTable, orgRow, rowGroup, pivotKeyHeader, x,
typeValue)
.ifPresent(newRows::add));
} else if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE) {
pivotKeyHeader.getEntries()
.forEach(x -> this.emitOneRowWithPivotAndType(graph, orgTable, orgRow, rowGroup, x, typeValue)
.ifPresent(newRows::add));
} else {
pivotKeyHeader.getEntries()
.forEach(x -> this.emitOneRowWithPivot(graph, orgTable, orgRow, rowGroup, x, typeValue)
.ifPresent(newRows::add));
}
}
return newRows;
}
Expand Down Expand Up @@ -257,10 +262,13 @@ private Optional<Row> emitOneRowWithPivotTypeAndValue(final BaseTableGraph graph
}

private Optional<Row> emitOneRowWithPivotAndType(final BaseTableGraph graph, final DataTable orgTable,
final BaseRow orgRow, final RowGroup rowGroup, final PivotEntry pivotEntry) {
final BaseRow orgRow, final RowGroup rowGroup, final PivotEntry pivotEntry, final String typeValue) {
if (!orgRow.getCellAt(pivotEntry.getCell().getColumnIndex()).hasValue()) {
return Optional.empty();
}
if (typeValue != null && !typeValue.equals(pivotEntry.getTypeValue())) {
return Optional.empty();
}

final var newRow = new Row(this.tmpHeaders.size());
for (final var tmpHeader : this.tmpHeaders) {
Expand All @@ -283,10 +291,13 @@ private Optional<Row> emitOneRowWithPivotAndType(final BaseTableGraph graph, fin
}

private Optional<Row> emitOneRowWithPivot(final BaseTableGraph graph, final DataTable orgTable,
final BaseRow orgRow, final RowGroup rowGroup, final PivotEntry pivotEntry) {
final BaseRow orgRow, final RowGroup rowGroup, final PivotEntry pivotEntry, final String typeValue) {
if (!orgRow.getCellAt(pivotEntry.getCell().getColumnIndex()).hasValue()) {
return Optional.empty();
}
if (typeValue != null && !typeValue.equals(pivotEntry.getTypeValue())) {
return Optional.empty();
}

final var newRow = new Row(this.tmpHeaders.size());
for (final var tmpHeader : this.tmpHeaders) {
Expand Down

0 comments on commit 38aadfb

Please sign in to comment.