1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
   | package com.citrusstv.core.pages.domain;
 
import com.project.core.domain.entities.Activity;
import com.project.core.domain.entities.Sale;
import com.project.core.domain.export.ExportType;
import com.project.core.domain.services.SaleSearchCriterion;
import com.project.core.domain.services.SaleService;
import com.project.core.utils.ExcelStreamResponse;
import org.apache.tapestry5.Asset;
import org.apache.tapestry5.SelectModel;
import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.SelectModelFactory;
import org.slf4j.Logger;
 
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
 
@Import(stylesheet = "context:layout/pages/sales.css")
public class SalesExpo {
 
    @Inject
    private Logger log;
 
    @Inject
    private SaleService saleservice;
 
    @Inject
    private SelectModelFactory selectModelFactory;
 
    @Inject
    @Path("context:layout/images/export/excel-export.jpg")
    private Asset excelExportSales;
 
    @SessionState
    private SaleSearchCriterion _saleSearchCriterion;
 
    @Property
    private Sale curSale;
 
 
    @Property    
    private SelectModel actModel;
 
    @Property
    private List<Sale> _sales;
 
    public SaleSearchCriterion getSaleSearchCriterion() {
        return _saleSearchCriterion;
    }
 
    public boolean isListExist(){
        return  (_sales!=null && _sales.size()>0)?true:false;
    }
 
    /**
     *
    public List<Sale> getSales() {
        return _sales;
    }
     *
     */
 
    public Asset getExcelExportSales() {
        return excelExportSales;
    }
 
    public void onActivate() {
        //initializeValue();
        System.out.println("Default on Activate Method *********************** ");
        log.info("on Load");
    }
 
    @SetupRender
    public void initialize()
    {
        actModel = selectModelFactory.create(Activity.findAll(), "description");        
    }
 
    //@AfterRender    
 
    public void onActionFromsearch(){
 
    	//System.out.println("******************************* BEGIN onActionFromsearch *********************** ");
        List<Sale> saleList = saleservice.findSales(_saleSearchCriterion);
        log.info(saleList.size()+"sale was found");
        _sales = saleList;
        //System.out.println("******************************* END onActionFromsearch *********************** ");
    }
 
    public StreamResponse onActionFromExportSalesToExcel()
    {
        log.debug("try Exporting");
 
        return new ExcelStreamResponse()
        {
            @Override
            protected String performExport(ByteArrayOutputStream outputStream) {
                try {
 
                    saleservice.exportSales(ExportType.Excel, _saleSearchCriterion, outputStream);
                    return "sales-export-" + System.currentTimeMillis();
 
                } catch (IOException e) {
                    log.error(e.getMessage(), e);
                    throw new RuntimeException("Cannot generate file");
                }
            }
        };
    }
} | 
Partager