Commit 9edc7fda by Matija Obreza

Merge branch '251-excel-corrupted' into 'master'

Resolve "Excel corrupted" Closes #251 See merge request genesys-pgr/genesys-server!148
parents 1ed84078 59ae1911
Pipeline #5172 passed with stages
in 3 minutes 41 seconds
......@@ -31,14 +31,14 @@ import java.util.List;
import com.opencsv.CSVWriter;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.common.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFHyperlink;
// NOTE Excel 2016 has a limit of 66,530 hyperlinks
// import org.apache.poi.xssf.usermodel.XSSFHyperlink;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.genesys2.server.model.genesys.AccessionAlias;
import org.genesys2.server.model.genesys.AccessionBreeding;
......@@ -329,24 +329,33 @@ public class DownloadServiceImpl implements DownloadService {
}
if (accession.getUuid() != null) {
XSSFHyperlink hypr = (XSSFHyperlink) sheet.getWorkbook().getCreationHelper().createHyperlink(Hyperlink.LINK_URL);
hypr.setAddress("http://purl.org/germplasm/id/" + accession.getUuid());
Cell cell = createCell(row, COL_UUID, accession.getUuid().toString());
cell.setHyperlink(hypr);
}
if (accession.getHistoric()) {
createCell(row, COL_HISTORIC, accession.getHistoric());
createCell(row, COL_UUID, accession.getUuid().toString());
// NOTE Excel has a limit on hyperlinks!
// XSSFHyperlink hypr = (XSSFHyperlink)
// sheet.getWorkbook().getCreationHelper().createHyperlink(Hyperlink.LINK_URL);
// hypr.setAddress("http://purl.org/germplasm/id/" + accession.getUuid());
// cell.setHyperlink(hypr);
}
createCell(row, COL_HISTORIC, accession.getHistoric());
if (StringUtils.isNotBlank(accession.getAcceUrl())) {
XSSFHyperlink hypr = (XSSFHyperlink) sheet.getWorkbook().getCreationHelper().createHyperlink(Hyperlink.LINK_URL);
hypr.setAddress(accession.getAcceUrl());
Cell cell = createCell(row, COL_ACCEURL, accession.getAcceUrl());
if (cell != null && hypr != null) {
cell.setHyperlink(hypr);
} else {
LOG.warn("Cell or hyper null for ACCEURL id={} acceUrl={}", accession.getId(), accession.getAcceUrl());
}
createCell(row, COL_ACCEURL, accession.getAcceUrl());
// NOTE Excel has a limit on hyperlinks!
// if (cell != null && hypr != null) {
//
// // XSSFHyperlink hypr = (XSSFHyperlink)
// //
// sheet.getWorkbook().getCreationHelper().createHyperlink(Hyperlink.LINK_URL);
// // hypr.setAddress(accession.getAcceUrl());
// // cell.setHyperlink(hypr);
// } else {
// LOG.warn("Cell or hyper null for ACCEURL id={} acceUrl={}",
// accession.getId(), accession.getAcceUrl());
// }
}
if (remarks != null && remarks.size() > 0) {
......@@ -454,7 +463,8 @@ public class DownloadServiceImpl implements DownloadService {
String year = (row[0] != null) ? String.valueOf(row[0]) : "";
StringBuilder builder = new StringBuilder();
builder.append(day).append("-").append(month).append("-").append(year).append("#").append(institute.getCode()).append("#").append(institute.getFullName()).append("#").append(row[4]);
builder.append(day).append("-").append(month).append("-").append(year).append("#").append(institute.getCode()).append("#").append(institute.getFullName()).append(
"#").append(row[4]);
writer.writeNext(builder.toString().split("#"));
}
......@@ -469,10 +479,12 @@ public class DownloadServiceImpl implements DownloadService {
// Process and write result
AccessionId accession = pdci.getAccession();
if (accession.getUuid() != null) {
XSSFHyperlink hypr = (XSSFHyperlink) sheet.getWorkbook().getCreationHelper().createHyperlink(Hyperlink.LINK_URL);
hypr.setAddress("http://purl.org/germplasm/id/" + accession.getUuid());
Cell cell = createCell(row, 0, accession.getUuid().toString());
cell.setHyperlink(hypr);
createCell(row, 0, accession.getUuid().toString());
// XSSFHyperlink hypr = (XSSFHyperlink)
// sheet.getWorkbook().getCreationHelper().createHyperlink(Hyperlink.LINK_URL);
// hypr.setAddress("http://purl.org/germplasm/id/" + accession.getUuid());
// cell.setHyperlink(hypr);
}
createCell(row, 1, pdci.getScore());
int col = 2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment