Skip to content

Commit

Permalink
Add support to export to XLSX
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed Jul 3, 2024
1 parent 34a86c3 commit 8bce67b
Show file tree
Hide file tree
Showing 14 changed files with 924 additions and 19 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ dependencies {
// ADempiere Core
implementation "${baseGroupId}:base:${baseVersion}"
implementation "${baseGroupId}:adempiere-grpc-utils:1.3.9"
implementation "org.apache.poi:poi-ooxml:5.2.5"

// Others
compileOnly 'org.apache.tomcat:annotations-api:6.0.53'
Expand Down
1 change: 1 addition & 0 deletions docker-compose/.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ DEFAULT_NETWORK="${STACK_NAME}.network"
POSTGRES_IMAGE="postgres:13"
POSTGRES_HOST="${STACK_NAME}.adempiere.database"
POSTGRES_PORT=5432
POSTGRES_EXTERNAL_PORT=5959
POSTGRES_PASSWORD="adempiere"
POSTGRES_VOLUME="${STACK_NAME}.volume_postgres"

Expand Down
43 changes: 42 additions & 1 deletion docker-compose/docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
version: "3.9"

name: template-service
name: adempiere-report-engine-dev-service

# Example API for images
services:
adempiere.database:
container_name: ${POSTGRES_HOST}
image: ${POSTGRES_IMAGE}
restart: ${GENERIC_RESTART}
volumes:
- volume_postgres:/var/lib/postgresql/data
- ./postgresql/initdb.sh:/docker-entrypoint-initdb.d/initdb.sh
- ./postgresql/seed.backup:/tmp/seed.backup
- ./postgresql/after_run:/tmp/after_run
healthcheck:
test: "bash -c 'printf \"GET / HTTP/1.1\n\n\" > /dev/tcp/127.0.0.1/5432; exit $?;'"
interval: 10s
retries: 60
start_period: 20s
timeout: 10s
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
TZ: 'America/Caracas'
PGTZ: 'America/Caracas'
ports:
- ${POSTGRES_EXTERNAL_PORT}:${POSTGRES_PORT}
networks:
- shared_network

adempiere.zk:
image: ${ADEMPIERE_ZK_IMAGE}
container_name: ${ADEMPIERE_ZK_HOST}
restart: ${GENERIC_RESTART}
environment:
ADEMPIERE_DB_SERVER: ${ADEMPIERE_ZK_DB_HOST}
ADEMPIERE_DB_PORT: ${ADEMPIERE_ZK_DB_PORT}
ADEMPIERE_DB_NAME: ${ADEMPIERE_ZK_DB_NAME}
ADEMPIERE_DB_PASSWORD: ${ADEMPIERE_ZK_DB_PASSWORD}
depends_on:
adempiere.database:
condition: service_healthy
ports:
- ${ADEMPIERE_ZK_EXTERNAL_PORT}:${ADEMPIERE_ZK_INTERNAL_PORT}
networks:
- shared_network

grpc.proxy:
image: ${ENVOY_GRPC_PROXY_IMAGE}
container_name: ${ENVOY_GRPC_PROXY_HOSTNAME}
Expand Down
Binary file not shown.
382 changes: 380 additions & 2 deletions docs/adempiere_report_engine.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/main/java/org/spin/report_engine/controller/ReportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.spin.report_engine.service.Service;
import org.spin.backend.grpc.report_engine.GetReportRequest;
import org.spin.backend.grpc.report_engine.Report;
import org.spin.backend.grpc.report_engine.RunExportRequest;
import org.spin.backend.grpc.report_engine.RunExportResponse;

import io.grpc.Status;
import io.grpc.stub.StreamObserver;
Expand Down Expand Up @@ -57,4 +59,19 @@ public void getView(GetReportRequest request, StreamObserver<Report> responseObs
.asRuntimeException());
}
}

@Override
public void runExport(RunExportRequest request, StreamObserver<RunExportResponse> responseObserver) {
try {
RunExportResponse.Builder reportBuilder = Service.getExportReport(request);
responseObserver.onNext(reportBuilder.build());
responseObserver.onCompleted();
} catch (Exception e) {
log.severe(e.getLocalizedMessage());
responseObserver.onError(Status.INTERNAL
.withDescription(e.getLocalizedMessage())
.withCause(e)
.asRuntimeException());
}
}
}
24 changes: 19 additions & 5 deletions src/main/java/org/spin/report_engine/data/ReportInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public ReportInfo addRow(Row row) {
public ReportInfo addRow() {
if(temporaryRow != null) {
addRow(Row.newInstance().withLevel(getLevel()).withCells(temporaryRow.getData()));
summaryHandler.addRow(Row.newInstance().withLevel(getLevel()).withCells(temporaryRow.getData()));
summaryHandler.addRow(Row.newInstance().withLevel(getLevel()).withSummaryRow(true).withCells(temporaryRow.getData()));
}
temporaryRow = Row.newInstance().withLevel(getLevel());
return this;
Expand All @@ -161,6 +161,12 @@ public List<Row> getRows() {
return rows;
}

public List<Row> getCompleteRows() {
return rows.stream()
.sorted(getSortingValue(true))
.collect(Collectors.toList());
}

public List<Row> getSummaryRows() {
return summaryRows;
}
Expand All @@ -169,7 +175,7 @@ public List<Row> getGroupedRows() {
return groupedRows;
}

private Comparator<Row> getSortingValue() {
private Comparator<Row> getSortingValue(boolean summaryAtEnd) {
AtomicReference<Comparator<Row>> comparator = new AtomicReference<>();
sortingItems.forEach(printFormatItem -> {
Comparator<Row> groupComparator = (p, o) -> p.getCompareValue(printFormatItem.getPrintFormatItemId()).compareToIgnoreCase(o.getCompareValue(printFormatItem.getPrintFormatItemId()));
Expand All @@ -180,9 +186,17 @@ private Comparator<Row> getSortingValue() {
}
});
if(comparator.get() != null) {
comparator.getAndUpdate(value -> value.thenComparing(Comparator.comparing(Row::getLevel)));
if(!summaryAtEnd) {
comparator.getAndUpdate(value -> value.thenComparing(Comparator.comparing(Row::getLevel)));
} else {
comparator.getAndUpdate(value -> value.thenComparing(Comparator.comparing(Row::getLevel).reversed()));
}
} else {
comparator.set(Comparator.comparing(Row::getLevel));
if(!summaryAtEnd) {
comparator.set(Comparator.comparing(Row::getLevel).reversed());
} else {
comparator.set(Comparator.comparing(Row::getLevel));
}
}
return comparator.get();
}
Expand All @@ -191,7 +205,7 @@ public ReportInfo completeInfo() {
recordCount = rows.size();
groupedRows = summaryHandler.getAsRows();
List<Row> completeRows = Stream.concat(getRows().stream(), groupedRows.stream())
.sorted(getSortingValue())
.sorted(getSortingValue(false))
.collect(Collectors.toList());
rows = completeRows;
return this;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/spin/report_engine/data/Row.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Row {
private Map<Integer, Cell> data;
private int level;
private List<Row> children;
private boolean isSummaryRow;

public Row() {
data = new HashMap<>();
Expand All @@ -48,6 +49,15 @@ public static Row newInstance() {
return new Row();
}

public boolean isSummaryRow() {
return isSummaryRow;
}

public Row withSummaryRow(boolean isSummaryRow) {
this.isSummaryRow = isSummaryRow;
return this;
}

public Row withCell(int printFormatItemId, Cell cell) {
data.put(printFormatItemId, cell);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public List<Row> getAsRows() {
SummaryFunction function = summaryValue.get(sumItem.getPrintFormatItemId());
groupValueRow.withCell(sumItem.getPrintFormatItemId(), Cell.newInstance().withValue(function.getValue(SummaryFunction.F_SUM)).withFunction(function));
});
rows.add(groupValueRow);
rows.add(groupValueRow.withSummaryRow(true));
});
});
return rows;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/************************************************************************************
* Copyright (C) 2012-2018 E.R.P. Consultores y Asociados, C.A. *
* Contributor(s): Yamel Senih [email protected] *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or *
* (at your option) any later version. *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
************************************************************************************/
package org.spin.report_engine.export;

import org.spin.report_engine.data.ReportInfo;

/**
* Report Xlsx Representation
* @author Yamel Senih, [email protected], ERPCyA http://www.erpya.com
*/
public interface IReportEngineExporter {

/**
* Export report info and return a file path
* @param reportInfo
* @return
*/
public String export(ReportInfo reportInfo);
}
Loading

0 comments on commit 8bce67b

Please sign in to comment.