Subversion Repositories SmartDukaan

Rev

Rev 4762 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2359 ankur.sing 1
package in.shop2020.catalog.dashboard.server;
2
 
3
import in.shop2020.catalog.dashboard.shared.Item;
4
 
5
import java.io.ByteArrayOutputStream;
6
import java.io.IOException;
7
import java.util.List;
4957 phani.kuma 8
import java.util.Map;
2359 ankur.sing 9
 
10
import javax.servlet.ServletException;
11
import javax.servlet.ServletOutputStream;
12
import javax.servlet.http.HttpServlet;
13
import javax.servlet.http.HttpServletRequest;
14
import javax.servlet.http.HttpServletResponse;
15
 
16
import com.google.gwt.core.client.GWT;
17
 
2427 ankur.sing 18
/**
19
 * Servlet to generate and then download master sheet  
20
 * It is invoked from ItemActions.java
21
 */
22
 
2359 ankur.sing 23
@SuppressWarnings("serial")
24
public class FileDownloadServlet extends HttpServlet {
25
 
26
    @Override
27
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
3884 chandransh 28
        long vendorId = Long.parseLong(req.getParameter("vendorId"));
4957 phani.kuma 29
        String vendorName;
4762 phani.kuma 30
        String Category = req.getParameter("Category"); // This parameter is set in ItemActions.java
4957 phani.kuma 31
        String brand = req.getParameter("brand");
3884 chandransh 32
 
2359 ankur.sing 33
        CatalogServiceImpl impl = new CatalogServiceImpl();
4957 phani.kuma 34
        List<Item> itemList = impl.getItemsForMasterSheet(Category, brand);
4762 phani.kuma 35
        GWT.log("Generating master sheet for " + Category + "...Item count = " + itemList.size());
2359 ankur.sing 36
        MasterSheetGenerator msg = new MasterSheetGenerator();
37
        ByteArrayOutputStream baos = msg.generateMasterSheet(vendorId, itemList);
4957 phani.kuma 38
        Map<Long, String> vendors = impl.getAllVendors();
39
        if(vendorId == 0){
40
        	vendorName = "ALL";
41
        }
42
        else{
43
        	vendorName = vendors.get(vendorId);
44
        }
2359 ankur.sing 45
        resp.setContentType("application/vnd.ms-excel");
4957 phani.kuma 46
        resp.setHeader("Content-disposition", "inline; filename=master-sheet-" + Category + "-" + brand + "-" + vendorName + ".xls");
2359 ankur.sing 47
        ServletOutputStream sos;
48
        try {
49
            sos = resp.getOutputStream();
50
            baos.writeTo(sos);
51
            sos.flush();
52
        } catch (IOException e) {
53
            e.printStackTrace();
54
        }
55
    }
56
}