| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
package org.kuali.student.common.ui.server.gwt; |
| 10 | |
|
| 11 | |
import java.util.ArrayList; |
| 12 | |
import java.util.UUID; |
| 13 | |
|
| 14 | |
import org.apache.log4j.Logger; |
| 15 | |
import org.kuali.student.common.assembly.data.Data; |
| 16 | |
import org.kuali.student.common.ui.client.service.GwtExportRpcService; |
| 17 | |
import org.kuali.student.common.ui.client.util.ExportElement; |
| 18 | |
import org.kuali.student.common.ui.client.util.ExportUtils; |
| 19 | |
import org.kuali.student.common.ui.server.screenreport.ScreenReportProcessor; |
| 20 | |
import org.kuali.student.common.ui.server.screenreport.jasper.JasperScreenReportProcessorImpl; |
| 21 | |
|
| 22 | |
import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
| 23 | |
|
| 24 | |
@SuppressWarnings("serial") |
| 25 | 0 | public class ExportGwtRpcServlet extends RemoteServiceServlet implements GwtExportRpcService { |
| 26 | |
|
| 27 | 0 | final Logger logger = Logger.getLogger(ExportGwtRpcServlet.class); |
| 28 | |
|
| 29 | 0 | private ScreenReportProcessor reportProcessor = new JasperScreenReportProcessorImpl(); |
| 30 | |
|
| 31 | |
@Override |
| 32 | |
public String reportExport(ArrayList<ExportElement> exportElements, Data root, String templateName, String exportFormat, String reportTitle) { |
| 33 | 0 | String exportId = null; |
| 34 | 0 | boolean exportBasedOnView = true; |
| 35 | |
try { |
| 36 | |
|
| 37 | 0 | if (templateName == null) { |
| 38 | 0 | templateName = "base.template"; |
| 39 | |
} |
| 40 | 0 | logger.info("Template Name = " + templateName + " For format = " + exportFormat); |
| 41 | 0 | byte[] exportOutput = null; |
| 42 | 0 | if (exportBasedOnView) { |
| 43 | 0 | exportOutput = exportBasedOnView(exportElements, templateName, exportFormat, reportTitle); |
| 44 | |
|
| 45 | |
} else { |
| 46 | 0 | exportOutput = exportBasedOnDataModel(root, templateName, exportFormat, reportTitle); |
| 47 | |
} |
| 48 | 0 | exportId = this.getExportId(); |
| 49 | 0 | logger.info("Export succesful - Export ID = " + exportId); |
| 50 | 0 | getThreadLocalRequest().getSession(true).setAttribute(exportId, exportOutput); |
| 51 | 0 | } catch (RuntimeException e) { |
| 52 | 0 | e.printStackTrace(); |
| 53 | 0 | throw e; |
| 54 | 0 | } |
| 55 | 0 | return exportId; |
| 56 | |
} |
| 57 | |
|
| 58 | |
private byte[] exportBasedOnDataModel(Data root, String templateName, String exportFormat, String reportTitle) { |
| 59 | 0 | byte[] exportOutput = null; |
| 60 | 0 | if (exportFormat.equals(ExportUtils.PDF)) { |
| 61 | 0 | exportOutput = reportProcessor.createPdf(root, templateName, reportTitle); |
| 62 | 0 | } else if (exportFormat.equals(ExportUtils.DOC)) { |
| 63 | 0 | exportOutput = reportProcessor.createDoc(root, templateName, reportTitle); |
| 64 | |
|
| 65 | 0 | } else if (exportFormat.equals(ExportUtils.XLS)) { |
| 66 | 0 | exportOutput = reportProcessor.createXls(root, templateName, reportTitle); |
| 67 | |
} |
| 68 | 0 | return exportOutput; |
| 69 | |
} |
| 70 | |
|
| 71 | |
private byte[] exportBasedOnView(ArrayList<ExportElement> exportElements, String templateName, String exportFormat, String reportTitle) { |
| 72 | 0 | byte[] exportOutput = null; |
| 73 | 0 | if (exportFormat.equals(ExportUtils.PDF)) { |
| 74 | 0 | exportOutput = reportProcessor.createPdf(exportElements, templateName, reportTitle); |
| 75 | 0 | } else if (exportFormat.equals(ExportUtils.DOC)) { |
| 76 | 0 | exportOutput = reportProcessor.createDoc(exportElements, templateName, reportTitle); |
| 77 | |
|
| 78 | 0 | } else if (exportFormat.equals(ExportUtils.XLS)) { |
| 79 | 0 | exportOutput = reportProcessor.createXls(exportElements, templateName, reportTitle); |
| 80 | |
} |
| 81 | 0 | return exportOutput; |
| 82 | |
} |
| 83 | |
|
| 84 | |
private String getExportId() { |
| 85 | 0 | return UUID.randomUUID().toString(); |
| 86 | |
} |
| 87 | |
|
| 88 | |
} |