View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may
3    * not use this file except in compliance with the License. You may obtain a copy of the License at
4    * http://www.osedu.org/licenses/ECL-2.0 Unless required by applicable law or agreed to in writing, software distributed
5    * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
6    * implied. See the License for the specific language governing permissions and limitations under the License.
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.ui.client.service.GwtExportRpcService;
16  import org.kuali.student.common.ui.client.util.ExportElement;
17  import org.kuali.student.common.ui.client.util.ExportUtils;
18  import org.kuali.student.common.ui.server.screenreport.ScreenReportProcessor;
19  import org.kuali.student.r1.common.assembly.data.Data;
20  
21  import com.google.gwt.user.server.rpc.RemoteServiceServlet;
22  
23  @Deprecated
24  @SuppressWarnings("serial")
25  public class ExportGwtRpcServlet extends RemoteServiceServlet implements GwtExportRpcService {
26  
27      final Logger logger = Logger.getLogger(ExportGwtRpcServlet.class);
28  
29      private ScreenReportProcessor reportProcessor;
30  
31      public ScreenReportProcessor getReportProcessor() {
32          return reportProcessor;
33      }
34  
35      public void setReportProcessor(ScreenReportProcessor reportProcessor) {
36          this.reportProcessor = reportProcessor;
37      }
38  
39      @Override
40      public String reportExport(List<ExportElement> exportElements, Data root, String templateName, String exportFormat, String reportTitle) {
41          String exportId = null;
42          boolean exportBasedOnView = true; // TODO Nina do we want this as a system Property??
43          try {
44              // If templateName is null, then default to default Template ie base.template
45              if (templateName == null) {
46                  templateName = "base.template";
47              }
48              logger.info("Template Name = " + templateName + " For format = " + exportFormat);
49              byte[] exportOutput = null;
50              if (exportBasedOnView) {
51                  exportOutput = exportBasedOnView(exportElements, templateName, exportFormat, reportTitle);
52  
53              } else {
54                  exportOutput = exportBasedOnDataModel(root, templateName, exportFormat, reportTitle);
55              }
56              exportId = this.getExportId();
57              logger.info("Export succesful - Export ID = " + exportId);
58              getThreadLocalRequest().getSession(true).setAttribute(exportId, exportOutput);
59          } catch (RuntimeException e) {
60              e.printStackTrace();
61              throw e;
62          }
63          return exportId;
64      }
65  
66      private byte[] exportBasedOnDataModel(Data root, String templateName, String exportFormat, String reportTitle) {
67          byte[] exportOutput = null;
68          if (exportFormat.equals(ExportUtils.PDF)) {
69              exportOutput = reportProcessor.createPdf(root, templateName, reportTitle);
70          } else if (exportFormat.equals(ExportUtils.DOC)) {
71              exportOutput = reportProcessor.createDoc(root, templateName, reportTitle);
72  
73          } else if (exportFormat.equals(ExportUtils.XLS)) {
74              exportOutput = reportProcessor.createXls(root, templateName, reportTitle);
75          }
76          return exportOutput;
77      }
78  
79      private byte[] exportBasedOnView(List<ExportElement> exportElements, String templateName, String exportFormat, String reportTitle) {
80          byte[] exportOutput = null;
81          if (exportFormat.equals(ExportUtils.PDF)) {
82              exportOutput = reportProcessor.createPdf(exportElements, templateName, reportTitle);
83          } else if (exportFormat.equals(ExportUtils.DOC)) {
84              exportOutput = reportProcessor.createDoc(exportElements, templateName, reportTitle);
85  
86          } else if (exportFormat.equals(ExportUtils.XLS)) {
87              exportOutput = reportProcessor.createXls(exportElements, templateName, reportTitle);
88          }
89          return exportOutput;
90      }
91  
92      private String getExportId() {
93          return UUID.randomUUID().toString();
94      }
95  
96  }