Coverage Report - org.kuali.student.common.ui.server.gwt.ExportGwtRpcServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
ExportGwtRpcServlet
0%
0/39
0%
0/16
2.667
 
 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.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; // TODO Nina do we want this as a system Property??
 42  
         try {
 43  
             // If templateName is null, then default to default Template ie base.template
 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  
 }