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