Commit 9edc7fda authored by Matija Obreza's avatar 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
...@@ -31,14 +31,14 @@ import java.util.List; ...@@ -31,14 +31,14 @@ import java.util.List;
import com.opencsv.CSVWriter; import com.opencsv.CSVWriter;
import org.apache.commons.lang.StringUtils; 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.Cell;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook; 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.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.genesys2.server.model.genesys.AccessionAlias; import org.genesys2.server.model.genesys.AccessionAlias;
import org.genesys2.server.model.genesys.AccessionBreeding; import org.genesys2.server.model.genesys.AccessionBreeding;
...@@ -329,24 +329,33 @@ public class DownloadServiceImpl implements DownloadService { ...@@ -329,24 +329,33 @@ public class DownloadServiceImpl implements DownloadService {
} }
if (accession.getUuid() != null) { if (accession.getUuid() != null) {
XSSFHyperlink hypr = (XSSFHyperlink) sheet.getWorkbook().getCreationHelper().createHyperlink(Hyperlink.LINK_URL); createCell(row, COL_UUID, accession.getUuid().toString());
hypr.setAddress("http://purl.org/germplasm/id/" + accession.getUuid()); // NOTE Excel has a limit on hyperlinks!
Cell cell = createCell(row, COL_UUID, accession.getUuid().toString());
cell.setHyperlink(hypr); // XSSFHyperlink hypr = (XSSFHyperlink)
} // sheet.getWorkbook().getCreationHelper().createHyperlink(Hyperlink.LINK_URL);
if (accession.getHistoric()) { // hypr.setAddress("http://purl.org/germplasm/id/" + accession.getUuid());
createCell(row, COL_HISTORIC, accession.getHistoric()); // cell.setHyperlink(hypr);
} }
createCell(row, COL_HISTORIC, accession.getHistoric());
if (StringUtils.isNotBlank(accession.getAcceUrl())) { if (StringUtils.isNotBlank(accession.getAcceUrl())) {
XSSFHyperlink hypr = (XSSFHyperlink) sheet.getWorkbook().getCreationHelper().createHyperlink(Hyperlink.LINK_URL); createCell(row, COL_ACCEURL, accession.getAcceUrl());
hypr.setAddress(accession.getAcceUrl());
Cell cell = createCell(row, COL_ACCEURL, accession.getAcceUrl()); // NOTE Excel has a limit on hyperlinks!
if (cell != null && hypr != null) {
cell.setHyperlink(hypr); // if (cell != null && hypr != null) {
} else { //
LOG.warn("Cell or hyper null for ACCEURL id={} acceUrl={}", accession.getId(), accession.getAcceUrl()); // // 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) { if (remarks != null && remarks.size() > 0) {
...@@ -454,7 +463,8 @@ public class DownloadServiceImpl implements DownloadService { ...@@ -454,7 +463,8 @@ public class DownloadServiceImpl implements DownloadService {
String year = (row[0] != null) ? String.valueOf(row[0]) : ""; String year = (row[0] != null) ? String.valueOf(row[0]) : "";
StringBuilder builder = new StringBuilder(); 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("#")); writer.writeNext(builder.toString().split("#"));
} }
...@@ -469,10 +479,12 @@ public class DownloadServiceImpl implements DownloadService { ...@@ -469,10 +479,12 @@ public class DownloadServiceImpl implements DownloadService {
// Process and write result // Process and write result
AccessionId accession = pdci.getAccession(); AccessionId accession = pdci.getAccession();
if (accession.getUuid() != null) { if (accession.getUuid() != null) {
XSSFHyperlink hypr = (XSSFHyperlink) sheet.getWorkbook().getCreationHelper().createHyperlink(Hyperlink.LINK_URL); createCell(row, 0, accession.getUuid().toString());
hypr.setAddress("http://purl.org/germplasm/id/" + accession.getUuid());
Cell cell = createCell(row, 0, accession.getUuid().toString()); // XSSFHyperlink hypr = (XSSFHyperlink)
cell.setHyperlink(hypr); // sheet.getWorkbook().getCreationHelper().createHyperlink(Hyperlink.LINK_URL);
// hypr.setAddress("http://purl.org/germplasm/id/" + accession.getUuid());
// cell.setHyperlink(hypr);
} }
createCell(row, 1, pdci.getScore()); createCell(row, 1, pdci.getScore());
int col = 2; 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