Skip to content

Commit

Permalink
Add toString method
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed May 16, 2024
1 parent 9228a00 commit b8b8c33
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/spin/report_engine/data/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ public Cell withValue(Object value) {
this.value = value;
return this;
}

@Override
public String toString() {
return "Cell [color=" + color + ", style=" + style + ", value=" + value + "]";
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/spin/report_engine/data/ColumnInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ public ColumnInfo withTitle(Object title) {
this.title = title;
return this;
}

@Override
public String toString() {
return "ColumnInfo [color=" + color + ", style=" + style + ", code=" + code + ", title=" + title + "]";
}
}
6 changes: 6 additions & 0 deletions src/main/java/org/spin/report_engine/data/ReportInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,10 @@ public ReportInfo withSummary(boolean isSummary) {
this.isSummary = isSummary;
return this;
}

@Override
public String toString() {
return "ReportInfo [name=" + name + ", columns=" + columns + ", data=" + data + ", printFormatId="
+ printFormatId + ", reportViewId=" + reportViewId + ", isSummary=" + isSummary + "]";
}
}
4 changes: 4 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 @@ -42,4 +42,8 @@ public Map<String, Cell> getData() {
return data;
}

@Override
public String toString() {
return "Row [data=" + data + "]";
}
}
23 changes: 22 additions & 1 deletion src/main/java/org/spin/report_engine/format/PrintFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
import java.util.ArrayList;
import java.util.List;

import org.adempiere.core.domains.models.I_AD_PrintFormatItem;
import org.adempiere.core.domains.models.I_AD_ReportView;
import org.compiere.model.MReportView;
import org.compiere.model.Query;
import org.compiere.print.MPrintFormat;
import org.compiere.print.MPrintFormatItem;
import org.compiere.util.Env;

/**
Expand All @@ -36,21 +38,29 @@ public class PrintFormat {
private int tableId;
private boolean isSummary;
private List<ReportView> reportViews;
private List<PrintFormatItem> items;

private PrintFormat(MPrintFormat printFormat) {
name = printFormat.getName();
description= printFormat.getDescription();
description = printFormat.getDescription();
printFormatId = printFormat.getAD_PrintFormat_ID();
if(printFormat.getAD_ReportView_ID() > 0) {
reportView = ReportView.newInstance(new MReportView(Env.getCtx(), printFormat.getAD_ReportView_ID(), null));
}
tableId = printFormat.getAD_Table_ID();
isSummary = printFormat.isSummary();
// Get Views
reportViews = new ArrayList<ReportView>();
new Query(Env.getCtx(), I_AD_ReportView.Table_Name, I_AD_ReportView.COLUMNNAME_AD_Table_ID + " = ?", null)
.setParameters(tableId)
.getIDsAsList()
.forEach(reportViewId -> reportViews.add(ReportView.newInstance(new MReportView(Env.getCtx(), reportViewId, null))));
// Get Items
items = new ArrayList<PrintFormatItem>();
new Query(Env.getCtx(), I_AD_PrintFormatItem.Table_Name, I_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormat_ID + " = ?", null)
.setParameters(printFormatId)
.getIDsAsList()
.forEach(printFormatItemId -> items.add(PrintFormatItem.newInstance(new MPrintFormatItem(Env.getCtx(), printFormatItemId, null))));
}

public static PrintFormat newInstance(MPrintFormat printFormat) {
Expand Down Expand Up @@ -84,4 +94,15 @@ public boolean isSummary() {
public List<ReportView> getReportViews() {
return reportViews;
}

public List<PrintFormatItem> getItems() {
return items;
}

@Override
public String toString() {
return "PrintFormat [name=" + name + ", description=" + description + ", printFormatId=" + printFormatId
+ ", reportView=" + reportView + ", tableId=" + tableId + ", isSummary=" + isSummary + ", items="
+ items + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,43 @@
************************************************************************************/
package org.spin.report_engine.format;

import org.adempiere.core.domains.models.I_AD_PrintFormatItem;
import org.compiere.print.MPrintFormatItem;

/**
* Print Format Line Representation
* @author Yamel Senih, ysenih@erpya.com, ERPCyA http://www.erpya.com
*/
public class PrintFormatLine {
public class PrintFormatItem {

private String name;
private String printText;
private int sequence;

private PrintFormatItem(MPrintFormatItem printFormatItem) {
name = printFormatItem.getName();
printText = printFormatItem.get_Translation(I_AD_PrintFormatItem.COLUMNNAME_PrintName);
sequence = printFormatItem.getAD_PrintFormat_ID();
}

public static PrintFormatItem newInstance(MPrintFormatItem printFormatItem) {
return new PrintFormatItem(printFormatItem);
}

public String getName() {
return name;
}

public String getPrintText() {
return printText;
}

public int getSequence() {
return sequence;
}

@Override
public String toString() {
return "PrintFormatItem [name=" + name + ", printText=" + printText + ", sequence=" + sequence + "]";
}
}
6 changes: 6 additions & 0 deletions src/main/java/org/spin/report_engine/format/ReportView.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,10 @@ public String getTitle() {
public String getWhereClause() {
return whereClause;
}

@Override
public String toString() {
return "ReportView [reportViewId=" + reportViewId + ", name=" + name + ", title=" + title + ", whereClause="
+ whereClause + "]";
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/spin/report_engine/mapper/Default.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package org.spin.report_engine.mapper;

import org.spin.report_engine.data.Cell;
import org.spin.report_engine.format.PrintFormatLine;
import org.spin.report_engine.format.PrintFormatItem;

/**
* Default just return the same value of cell
Expand All @@ -29,7 +29,7 @@ public class Default implements IColumnMapper {
* @param value
* @return
*/
public Cell processValue(PrintFormatLine printFormatLine, Object value) {
public Cell processValue(PrintFormatItem printFormatLine, Object value) {
return Cell.newInstance().withValue(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package org.spin.report_engine.mapper;

import org.spin.report_engine.data.Cell;
import org.spin.report_engine.format.PrintFormatLine;
import org.spin.report_engine.format.PrintFormatItem;

/**
* This interface represent a contract of column mapper, you can implement your own mapper based on this format
Expand All @@ -29,5 +29,5 @@ public interface IColumnMapper {
* @param value
* @return
*/
public Cell processValue(PrintFormatLine printFormatLine, Object value);
public Cell processValue(PrintFormatItem printFormatLine, Object value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ public ReportInfo run(int pageSize, String nextPageToken) {
}
MPrintFormat printFormat = new MPrintFormat(Env.getCtx(), getPrintFormatId(), null);
PrintFormat format = PrintFormat.newInstance(printFormat);
System.out.println(format);
return ReportInfo.newInstance();
}

public static void main(String[] args) {
// 50132
// Stocktake Line
ReportBuilder.newInstance(50132).run(50, null);
}
}

0 comments on commit b8b8c33

Please sign in to comment.