Subversion Repositories SmartDukaan

Rev

Rev 9622 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9622 Rev 9855
Line 7... Line 7...
7
import in.shop2020.logistics.LogisticsService;
7
import in.shop2020.logistics.LogisticsService;
8
import in.shop2020.model.v1.catalog.CatalogService;
8
import in.shop2020.model.v1.catalog.CatalogService;
9
import in.shop2020.model.v1.catalog.CatalogServiceException;
9
import in.shop2020.model.v1.catalog.CatalogServiceException;
10
import in.shop2020.model.v1.catalog.Item;
10
import in.shop2020.model.v1.catalog.Item;
11
import in.shop2020.model.v1.catalog.ProductFeedSubmit;
11
import in.shop2020.model.v1.catalog.ProductFeedSubmit;
-
 
12
import in.shop2020.logistics.ItemText;
12
import in.shop2020.thrift.clients.CatalogClient;
13
import in.shop2020.thrift.clients.CatalogClient;
13
import in.shop2020.thrift.clients.LogisticsClient;
14
import in.shop2020.thrift.clients.LogisticsClient;
14
 
15
 
-
 
16
import java.io.BufferedInputStream;
-
 
17
import java.io.File;
-
 
18
import java.io.FileInputStream;
-
 
19
import java.io.FileNotFoundException;
-
 
20
import java.io.FileOutputStream;
15
import java.io.IOException;
21
import java.io.IOException;
-
 
22
import java.io.InputStream;
-
 
23
import java.util.ArrayList;
16
import java.util.List;
24
import java.util.List;
17
 
25
 
-
 
26
import javax.servlet.ServletOutputStream;
-
 
27
import javax.servlet.http.HttpServletRequest;
-
 
28
import javax.servlet.http.HttpServletResponse;
-
 
29
import javax.servlet.http.HttpSession;
-
 
30
 
-
 
31
import org.apache.poi.hssf.usermodel.HSSFRow;
-
 
32
import org.apache.poi.hssf.usermodel.HSSFSheet;
-
 
33
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
18
import org.apache.thrift.TException;
34
import org.apache.thrift.TException;
19
import org.apache.thrift.transport.TTransportException;
35
import org.apache.thrift.transport.TTransportException;
20
 
36
 
21
 
37
 
22
public class ProductFeedsController extends BaseController{
38
public class ProductFeedsController extends BaseController{
Line 25... Line 41...
25
	private String sentFeedResult;
41
	private String sentFeedResult;
26
	private String catalogItemIdDelete;
42
	private String catalogItemIdDelete;
27
	private String deleteFeedResult;
43
	private String deleteFeedResult;
28
	private String stockLinkFeed;
44
	private String stockLinkFeed;
29
	private boolean stockLinkedFeed = false;
45
	private boolean stockLinkedFeed = false;
30
	
-
 
31
	public String index() {
46
	public String index() {
32
		return "index";
47
		return "index";
33
	}
48
	}
34
	
49
	
-
 
50
	public void downloadAllProductFeeds() throws IOException{
-
 
51
		File file = new File("/tmp/Product-Feeds.xls");
-
 
52
		HSSFWorkbook hwb=new HSSFWorkbook();
-
 
53
		HSSFSheet sheet =  hwb.createSheet("Product Feeds");
-
 
54
		HSSFRow rowhead=   sheet.createRow(0);
-
 
55
		rowhead.createCell(0).setCellValue("Catalog Item Id");
-
 
56
		rowhead.createCell(1).setCellValue("Product Name");
-
 
57
		rowhead.createCell(2).setCellValue("Stock Linked");
-
 
58
		
-
 
59
		CatalogClient catalogClient = null;
-
 
60
		try {
-
 
61
			catalogClient = new CatalogClient();
-
 
62
		} catch (Exception e1) {
-
 
63
			e1.printStackTrace();
-
 
64
		}
-
 
65
		
-
 
66
		List<ProductFeedSubmit> feedSubmits = new ArrayList<ProductFeedSubmit>();
-
 
67
		
-
 
68
		try{
-
 
69
			feedSubmits = catalogClient.getClient().getAllProductFeedSubmit();
-
 
70
		} catch(Exception e){
-
 
71
			e.printStackTrace();
-
 
72
		}
-
 
73
		
-
 
74
		int i = 1;
-
 
75
		try{
-
 
76
			for(ProductFeedSubmit feedSubmit : feedSubmits){
-
 
77
				HSSFRow rowToAdd = sheet.createRow(i);
-
 
78
				rowToAdd.createCell(0).setCellValue(feedSubmit.getCatalogItemId());
-
 
79
				Item item = catalogClient.getClient().getItemsByCatalogId(feedSubmit.getCatalogItemId()).get(0);
-
 
80
				rowToAdd.createCell(1).setCellValue(item.getBrand() + " "+ item.getModelName() + " " + item.getModelNumber());
-
 
81
				rowToAdd.createCell(2).setCellValue(feedSubmit.isStockLinkedFeed());
-
 
82
				i++;
-
 
83
			}
-
 
84
		} catch(Exception e){
-
 
85
			e.printStackTrace();
-
 
86
		}
-
 
87
		
-
 
88
		FileOutputStream fileOut = null;
-
 
89
		try {
-
 
90
			fileOut = new FileOutputStream(file);
-
 
91
		} catch (FileNotFoundException e) {
-
 
92
			// TODO Auto-generated catch block
-
 
93
			e.printStackTrace();
-
 
94
		}
-
 
95
		try {
-
 
96
			hwb.write(fileOut);
-
 
97
		} catch (IOException e) {
-
 
98
			// TODO Auto-generated catch block
-
 
99
			e.printStackTrace();
-
 
100
		}
-
 
101
		try {
-
 
102
			fileOut.close();
-
 
103
		} catch (IOException e) {
-
 
104
			// TODO Auto-generated catch block
-
 
105
			e.printStackTrace();
-
 
106
		}
-
 
107
		byte[] buffer = new byte[(int)file.length()];
-
 
108
		InputStream input = null;
-
 
109
		try {
-
 
110
			int totalBytesRead = 0;
-
 
111
			input = new BufferedInputStream(new FileInputStream(file));
-
 
112
			while(totalBytesRead < buffer.length){
-
 
113
				int bytesRemaining = buffer.length - totalBytesRead;
-
 
114
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
-
 
115
				if (bytesRead > 0){
-
 
116
					totalBytesRead = totalBytesRead + bytesRead;
-
 
117
				}
-
 
118
			}
-
 
119
		}
-
 
120
		finally {
-
 
121
			input.close();
-
 
122
			file.delete();
-
 
123
		}
-
 
124
 
-
 
125
		response.setHeader("Content-Disposition", "attachment; filename=\"Product-Feeds.xls\"");
-
 
126
		response.setContentType("application/octet-stream");
-
 
127
		ServletOutputStream sos;
-
 
128
		try {
-
 
129
			sos = response.getOutputStream();
-
 
130
			sos.write(buffer);
-
 
131
			sos.flush();
-
 
132
		} catch (IOException e) {
-
 
133
			System.out.println("Unable to stream the manifest file");
-
 
134
		}   
-
 
135
	}
-
 
136
	
35
	public String sendProductFeeds(){
137
	public String sendProductFeeds(){
36
		//boolean sendFeedsResult = false;
138
		//boolean sendFeedsResult = false;
37
		processStockLinkFeed();
139
		processStockLinkFeed();
38
		Product insertedProduct = null;
140
		Product insertedProduct = null;
39
		CatalogClient catalogClient = null;
141
		CatalogClient catalogClient = null;
Line 162... Line 264...
162
		
264
		
163
		return "output";
265
		return "output";
164
	}
266
	}
165
	
267
	
166
	public List<Long> getEntityLogisticsEstimation(long productId){
268
	public List<Long> getEntityLogisticsEstimation(long productId){
167
    	List<Long> items=null; 
269
    	List<ItemText> items=null;
-
 
270
    	List<Long> itemIds = new ArrayList<Long>();
168
    	try {
271
    	try {
169
    		LogisticsClient cl = new LogisticsClient();
272
    		LogisticsClient cl = new LogisticsClient();
170
            LogisticsService.Client client = cl.getClient();
273
            LogisticsService.Client client = cl.getClient();
171
            items = client.getEntityLogisticsEstimation(productId, "110001", DeliveryType.PREPAID );
274
            items = client.getEntityLogisticsEstimation(productId, "110001", DeliveryType.PREPAID );
-
 
275
            for(ItemText text : items)
-
 
276
            	itemIds.add(text.getItemId());
172
        } catch (Exception e1) {
277
        } catch (Exception e1) {
173
            System.out.println("Unable to get items by catalog item id"+e1.getMessage());
278
            System.out.println("Unable to get items by catalog item id"+e1.getMessage());
174
        }
279
        }
175
        return items;
280
        return itemIds;
176
    }
281
    }
177
	
282
	
178
	public void processStockLinkFeed(){
283
	public void processStockLinkFeed(){
179
		if(stockLinkFeed!=null && ("on").equalsIgnoreCase(stockLinkFeed)){
284
		if(stockLinkFeed!=null && ("on").equalsIgnoreCase(stockLinkFeed)){
180
			stockLinkedFeed = true;
285
			stockLinkedFeed = true;