Skip to content

Commit

Permalink
Add support to reports
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed May 18, 2024
1 parent c829277 commit cfb8b1e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
40 changes: 36 additions & 4 deletions src/main/java/org/spin/report_engine/data/ReportInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,33 @@
import java.util.ArrayList;
import java.util.List;

import org.spin.report_engine.format.PrintFormat;
import org.spin.report_engine.format.PrintFormatItem;


/**
* CAll Report information is here, name, columns and other
* Call Report information is here, name, columns and other
* @author Yamel Senih, ysenih@erpya.com, ERPCyA http://www.erpya.com
*/
public class ReportInfo {
private String name;
private String description;
private List<ColumnInfo> columns;
private List<Row> rows;
private Row temporaryRow;
private int printFormatId;
private int reportViewId;
private boolean isSummary;

private ReportInfo() {
private ReportInfo(PrintFormat printFormat) {
name = printFormat.getName();
description = printFormat.getDescription();
columns = new ArrayList<>();
rows = new ArrayList<>();
}

public static ReportInfo newInstance() {
return new ReportInfo();
public static ReportInfo newInstance(PrintFormat printFormat) {
return new ReportInfo(printFormat);
}

public String getName() {
Expand All @@ -48,6 +55,15 @@ public ReportInfo withName(String name) {
return this;
}

public String getDescription() {
return description;
}

public ReportInfo withDescription(String description) {
this.description = description;
return this;
}

public List<ColumnInfo> getColumns() {
return columns;
}
Expand All @@ -67,6 +83,22 @@ public ReportInfo addRow(Row row) {
return this;
}

public ReportInfo addRow() {
if(temporaryRow != null) {
addRow(Row.newInstance().withCells(temporaryRow.getData()));
}
temporaryRow = Row.newInstance();
return this;
}

public ReportInfo addCell(PrintFormatItem printFormatItem, Cell cell) {
if(temporaryRow == null) {
temporaryRow = Row.newInstance();
}
temporaryRow.withCell(printFormatItem.getPrintFormatItemId(), cell);
return this;
}

public List<Row> getRows() {
return rows;
}
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/org/spin/report_engine/data/Row.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
public class Row {
/** Data for Row */
private Map<String, Cell> data;
private Map<Integer, Cell> data;

private Row() {
data = new HashMap<>();
Expand All @@ -33,12 +33,17 @@ public static Row newInstance() {
return new Row();
}

public Row withCell(String columnCode, Cell cell) {
data.put(columnCode, cell);
public Row withCell(int printFormatItemId, Cell cell) {
data.put(printFormatItemId, cell);
return this;
}

public Map<String, Cell> getData() {
public Row withCells(Map<Integer, Cell> cells) {
data = cells;
return this;
}

public Map<Integer, Cell> getData() {
return data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.spin.report_engine.data.Cell;
import org.spin.report_engine.data.ColumnInfo;
import org.spin.report_engine.data.ReportInfo;
import org.spin.report_engine.data.Row;
import org.spin.report_engine.format.PrintFormat;
import org.spin.report_engine.format.QueryDefinition;
import org.spin.service.grpc.util.query.Filter;
Expand Down Expand Up @@ -108,10 +107,9 @@ public ReportInfo run(int limit, int offset) {
MPrintFormat printFormat = new MPrintFormat(Env.getCtx(), getPrintFormatId(), null);
PrintFormat format = PrintFormat.newInstance(printFormat);
QueryDefinition queryDefinition = format.getQuery().withConditions(conditions).withLimit(limit, offset).buildQuery();
ReportInfo reportInfo = ReportInfo.newInstance();
ReportInfo reportInfo = ReportInfo.newInstance(format);
DB.runResultSet(null, queryDefinition.getCompleteQuery(), queryDefinition.getParameters(), resulset -> {
while (resulset.next()) {
Row row = Row.newInstance();
format.getItems().forEach(item -> {
reportInfo.addColumn(ColumnInfo.newInstance(item));
Cell cell = Cell.newInstance();
Expand All @@ -129,11 +127,12 @@ public ReportInfo run(int limit, int offset) {
e.printStackTrace();
}
});
row.withCell(item.getColumnName(), cell);
reportInfo.addCell(item, cell);
});
reportInfo.addRow(row);
reportInfo.addRow();
}
});
System.out.println(reportInfo);
return reportInfo;
}

Expand Down

0 comments on commit cfb8b1e

Please sign in to comment.