Skip to content

Commit

Permalink
Add max character lenght for report
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed Aug 23, 2024
1 parent b2918f3 commit 9ba2ba2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 12 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 @@ -19,6 +19,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -213,6 +214,7 @@ public PrintFormat getPrintFormat() {
}

public ReportInfo completeInfo() {
Map<Integer, Integer> columnLength = new HashMap<>();
groupedRows = summaryHandler.getAsRows();
List<Row> completeRows = Stream.concat(getRows().stream(), groupedRows.stream())
.sorted(getSortingValue(false))
Expand All @@ -233,10 +235,20 @@ public ReportInfo completeInfo() {
} else {
DefaultMapping.newInstance().processValue(printFormatItem, language, cell);
}
int newLength = Optional.ofNullable(cell.getDisplayValue()).orElse("").length();
if(columnLength.containsKey(printFormatItem.getPrintFormatItemId())) {
int characters = columnLength.get(printFormatItem.getPrintFormatItemId());
if(newLength > characters) {
columnLength.put(printFormatItem.getPrintFormatItemId(), newLength);
}
} else {
columnLength.put(printFormatItem.getPrintFormatItemId(), newLength);
}
newRow.withCell(printFormatItem.getPrintFormatItemId(), cell);
});
rows.add(newRow);
});
columns = columns.stream().map(column -> column.withColumnCharactersSize(columnLength.get(column.getPrintFormatItemId()))).collect(Collectors.toList());
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package org.spin.report_engine.format;

import org.adempiere.core.domains.models.I_AD_PrintFormatItem;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MColumn;
import org.compiere.print.MPrintColor;
import org.compiere.print.MPrintFont;
import org.compiere.print.MPrintFormatItem;
import org.compiere.util.CLogger;
import org.compiere.util.DisplayType;
import org.compiere.util.Util;

Expand Down Expand Up @@ -70,6 +70,7 @@ public class PrintFormatItem {
private String fontCode;
private String color;

private static final CLogger logger = CLogger.getCLogger(PrintFormatItem.class);

/** PrintFormatType AD_Reference_ID=255 */
public static final int PRINTFORMATTYPE_AD_Reference_ID=255;
Expand Down Expand Up @@ -202,7 +203,7 @@ private PrintFormatItem(MPrintFormatItem printFormatItem) {
int rgbColor = Integer.parseInt(colorCode);
color = String.format("#%06x", rgbColor & 0x00ffffff);
} catch (Exception e) {
throw new AdempiereException(e);
logger.warning(e.getLocalizedMessage());
}
}
}
Expand Down

0 comments on commit 9ba2ba2

Please sign in to comment.