public FileRepresentation getRepresentation(){
Integer id = RequestUtil.getInteger(getRequestAttributes().get("id"));
String type = RequestUtil.getString(getRequestAttributes().get("type"));
File respFile = null;
FileRepresentation output = null;
InputStream jasperFileStream = getClass().getResourceAsStream("/report/returnreport.jasper");
Map<String, Object> paramMap = new HashMap<String, Object>();
List<ReturnToSupplierDetail> list = coreManager.getReturnToSupplierDetails(id);
/* if(list.size() > 0){
Integer storeId = list.get(0).getPurchasingOrder().getDeliverStoreId();
Store store = coreManager.get(Store.class, storeId);
paramMap.put("storeName", store.getName());
paramMap.put("storeAddress", store.getAddress());
paramMap.put("storeCity", store.getCity());
}
*/
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list);
try {
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperFileStream, paramMap, ds);
if("pdf".equalsIgnoreCase(type)){
respFile = File.createTempFile("sunflower_", ".pdf");
JasperExportManager.exportReportToPdfFile(jasperPrint, respFile.getPath());
}else{
respFile = File.createTempFile("sunflower_", ".txt");
jtextExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
jtextExporter.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT, new Float(10));
jtextExporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH, new Float(5.25));
jtextExporter.setParameter(JRExporterParameter.OUTPUT_FILE, respFile);
jtextExporter.exportReport();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(jasperFileStream != null){
try {
jasperFileStream.close();
} catch (IOException e) {
}
}
}
if("pdf".equalsIgnoreCase(type)){
output = new FileRepresentation(respFile, MediaType.APPLICATION_PDF);
}else{
output = new FileRepresentation(respFile, MediaType.TEXT_PLAIN);
}
return output;
}