Skip to content

Commit

Permalink
handle the case when fontconfig is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Feb 26, 2020
1 parent fb287e2 commit 4a6788b
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/main/java/io/lavagna/service/ExcelExportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang3.builder.CompareToBuilder;
import org.apache.commons.text.WordUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
Expand All @@ -43,6 +45,8 @@
@Transactional(readOnly = true)
public class ExcelExportService {

private static final Logger LOG = LogManager.getLogger();

private final CardRepository cardRepository;
private final CardDataService cardDataService;
private final CardLabelRepository cardLabelRepository;
Expand Down Expand Up @@ -143,27 +147,20 @@ private HSSFWorkbook getWorkbookFromSearchFilters(int projectId, String sheetNam
UserWithPermission user) {

List<CardLabel> labels = cardLabelRepository.findLabelsByProject(projectId);
CollectionUtils.filter(labels, new Predicate<CardLabel>() {
@Override
public boolean evaluate(CardLabel cl) {
if (cl.getDomain().equals(CardLabel.LabelDomain.SYSTEM)) {
if (cl.getName().equals(SYSTEM_LABEL_ASSIGNED) ||
cl.getName().equals(SYSTEM_LABEL_DUE_DATE) ||
cl.getName().equals(SYSTEM_LABEL_MILESTONE)) {
return true;
}
return false;
CollectionUtils.filter(labels, cl -> {
if (cl.getDomain().equals(CardLabel.LabelDomain.SYSTEM)) {
if (cl.getName().equals(SYSTEM_LABEL_ASSIGNED) ||
cl.getName().equals(SYSTEM_LABEL_DUE_DATE) ||
cl.getName().equals(SYSTEM_LABEL_MILESTONE)) {
return true;
}
return true;
}
});
Collections.sort(labels, new Comparator<CardLabel>() {
public int compare(CardLabel l1, CardLabel l2) {
return new CompareToBuilder().append(l1.getDomain(), l2.getDomain())
.append(l1.getName(), l2.getName())
.toComparison();
return false;
}
return true;
});
Collections.sort(labels, (l1, l2) -> new CompareToBuilder().append(l1.getDomain(), l2.getDomain())
.append(l1.getName(), l2.getName())
.toComparison());

SearchResults cards = searchService.find(filters, projectId, null, user);

Expand Down Expand Up @@ -226,7 +223,11 @@ public int compare(CardLabel l1, CardLabel l2) {
// Auto size the columns except for the description
for (int i = 0; i < headerColPos; i++) {
if (!header.getCell(i).getStringCellValue().equals("Description")) {
sheet.autoSizeColumn(i);
try {
sheet.autoSizeColumn(i);
} catch (NullPointerException e) {
LOG.warn("No fontconfig installed, the columns in the excel will not be autosized");
}
} else {
sheet.setColumnWidth(i, 30 * 256);
}
Expand All @@ -235,8 +236,7 @@ public int compare(CardLabel l1, CardLabel l2) {
return wb;
}

public HSSFWorkbook exportMilestoneToExcel(String projectShortName, String milestone, UserWithPermission user)
throws IOException {
public HSSFWorkbook exportMilestoneToExcel(String projectShortName, String milestone, UserWithPermission user) {

int projectId = projectService.findIdByShortName(projectShortName);
LabelListValueWithMetadata ms = getMilestone(projectId, milestone);
Expand All @@ -251,8 +251,7 @@ public HSSFWorkbook exportMilestoneToExcel(String projectShortName, String miles

}

public HSSFWorkbook exportProjectToExcel(String projectShortName, UserWithPermission user)
throws IOException {
public HSSFWorkbook exportProjectToExcel(String projectShortName, UserWithPermission user) {

Project project = projectService.findByShortName(projectShortName);

Expand Down

0 comments on commit 4a6788b

Please sign in to comment.