Subversion Repositories SmartDukaan

Rev

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

Rev 13757 Rev 13761
Line 2... Line 2...
2
 
2
 
3
import in.shop2020.model.v1.catalog.CatalogService.Client;
3
import in.shop2020.model.v1.catalog.CatalogService.Client;
4
import in.shop2020.model.v1.catalog.FlipkartItem;
4
import in.shop2020.model.v1.catalog.FlipkartItem;
5
import in.shop2020.model.v1.catalog.Item;
5
import in.shop2020.model.v1.catalog.Item;
6
import in.shop2020.model.v1.catalog.MarketPlaceItemPrice;
6
import in.shop2020.model.v1.catalog.MarketPlaceItemPrice;
-
 
7
import in.shop2020.serving.services.FlipkartPricingPannel;
7
import in.shop2020.thrift.clients.CatalogClient;
8
import in.shop2020.thrift.clients.CatalogClient;
8
import in.shop2020.utils.GmailUtils;
9
import in.shop2020.utils.GmailUtils;
9
 
10
 
10
import java.io.BufferedReader;
11
import java.io.BufferedReader;
11
import java.io.File;
12
import java.io.File;
Line 28... Line 29...
28
import org.apache.http.client.methods.HttpPost;
29
import org.apache.http.client.methods.HttpPost;
29
import org.apache.http.entity.StringEntity;
30
import org.apache.http.entity.StringEntity;
30
import org.apache.http.impl.client.DefaultHttpClient;
31
import org.apache.http.impl.client.DefaultHttpClient;
31
import org.apache.thrift.TException;
32
import org.apache.thrift.TException;
32
import org.apache.thrift.transport.TTransportException;
33
import org.apache.thrift.transport.TTransportException;
-
 
34
import org.json.JSONException;
33
 
35
 
34
 
36
 
35
 
37
 
36
public class CreateSubmitFlipkartPricingFeed {
38
public class CreateSubmitFlipkartPricingFeed {
37
	private static long time = System.currentTimeMillis();
39
	private static long time = System.currentTimeMillis();
Line 42... Line 44...
42
	static java.text.SimpleDateFormat sdf;
44
	static java.text.SimpleDateFormat sdf;
43
	static String emailFromAddress;
45
	static String emailFromAddress;
44
	static String password;
46
	static String password;
45
	static GmailUtils mailer;
47
	static GmailUtils mailer;
46
	static String sendTo[];
48
	static String sendTo[];
-
 
49
	static String errorSendTo[];
47
	private static List<MarketPlaceItemPrice> flipkartPricingUpdateItems;
50
	private static List<MarketPlaceItemPrice> flipkartPricingUpdateItems;
48
	static
51
	static
49
	{
52
	{
50
		sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
53
		sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
51
		emailFromAddress = "build@shop2020.in";
54
		emailFromAddress = "build@shop2020.in";
Line 53... Line 56...
53
		mailer = new GmailUtils();
56
		mailer = new GmailUtils();
54
		//sendTo = new String[]{"vikram.raghav@shop2020.in"};
57
		//sendTo = new String[]{"vikram.raghav@shop2020.in"};
55
		sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "manish.sharma@shop2020.in", "rajneesh.arora@shop2020.in",
58
		sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "manish.sharma@shop2020.in", "rajneesh.arora@shop2020.in",
56
				"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
59
				"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
57
				"yukti.jain@shop2020.in","manisha.sharma@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","anikendra.das@shop2020.in"};
60
				"yukti.jain@shop2020.in","manisha.sharma@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","anikendra.das@shop2020.in"};
-
 
61
		errorSendTo = new String[]{"kshitij.sood@shop2020.in","manish.sharma@shop2020.in","amit.gupta@shop2020.in","anikendra.das@shop2020.in"};
58
		Client catalogServiceClient = null;
62
		Client catalogServiceClient = null;
59
		try {
63
		try {
60
			catalogServiceClient = new CatalogClient().getClient();
64
			catalogServiceClient = new CatalogClient().getClient();
61
		} catch (TTransportException e) {
65
		} catch (TTransportException e) {
62
			e.printStackTrace();
66
			e.printStackTrace();
Line 143... Line 147...
143
			+"<td><b>" + "Item ID" + "</b></td>"
147
			+"<td><b>" + "Item ID" + "</b></td>"
144
			+"<td><b>" + "Selling Price" + "</b></td>"
148
			+"<td><b>" + "Selling Price" + "</b></td>"
145
			+"</tr>";
149
			+"</tr>";
146
		String tableFooter = "</table></html>";
150
		String tableFooter = "</table></html>";
147
		Item item;
151
		Item item;
148
		StringBuffer feedResponse = null;
152
		Map<Long, Boolean> feedResponseMap = new HashMap<Long, Boolean>();
-
 
153
		FlipkartPricingPannel fkPricing = new FlipkartPricingPannel();
149
		for(MarketPlaceItemPrice entry:flipkartPricingItems){
154
		for(MarketPlaceItemPrice entry:flipkartPricingItems){
150
			updatedItems.add(entry.getItem_id());
-
 
151
			feedResponse=  new StringBuffer();
-
 
152
			if(aliveItemsMap.containsKey(entry.getItem_id())){
155
			if(aliveItemsMap.containsKey(entry.getItem_id())){
153
				item = aliveItemsMap.get(entry.getItem_id());	
156
				item = aliveItemsMap.get(entry.getItem_id());	
154
			}
157
			}
155
			else{
158
			else{
156
				continue;
159
				continue;
157
			}
160
			}
158
			System.out.println("Item ID  " + entry.getItem_id());
161
			System.out.println("Item ID  " + entry.getItem_id());
159
			System.out.println("Product Name " + getProductName(item));
162
			System.out.println("Product Name " + getProductName(item));
160
			System.out.println("Selling Price " + entry.getSellingPrice());
163
			System.out.println("Selling Price " + entry.getSellingPrice());
-
 
164
			try {
-
 
165
				feedResponseMap.put(entry.getItem_id(), fkPricing.updatePrice(flipkartItemsMap.get(entry.getItem_id()).getSkuAtFlipkart(), entry.getSellingPrice()+""));
-
 
166
			} catch (Exception e) {
-
 
167
				try {
-
 
168
					mailer.sendSSLMessage(errorSendTo, "Error While Flipkart Pricing Updation Item Id: "+ entry.getItem_id(), "Due to Json Exception in Flipkart Pricing Panel", emailFromAddress, password,new ArrayList<File>());
-
 
169
				}
-
 
170
				catch (MessagingException ex) {
-
 
171
					ex.printStackTrace();
-
 
172
				}
-
 
173
			}
161
			jsonRequest.append("{\"skuId\":"+"\""+flipkartItemsMap.get(entry.getItem_id()).getSkuAtFlipkart()+
174
			/*jsonRequest.append("{\"skuId\":"+"\""+flipkartItemsMap.get(entry.getItem_id()).getSkuAtFlipkart()+
162
					"\","+"\"attributeValues\""+":"+
175
					"\","+"\"attributeValues\""+":"+
163
					"{\"selling_price\""+":"+"\""+ new Double(entry.getSellingPrice()).intValue()+"\""+"},"+"\"listingValidations\":" +
176
					"{\"selling_price\""+":"+"\""+ new Double(entry.getSellingPrice()).intValue()+"\""+"},"+"\"listingValidations\":" +
164
			        "{\"PRICE_ERROR_CHECK\":" +
177
			        "{\"PRICE_ERROR_CHECK\":" +
165
			        "\"disable\"}"+"}");
178
			        "\"disable\"}"+"}");
166
 
179
 
Line 219... Line 232...
219
 
232
 
220
					}
233
					}
221
				} catch (IOException e) {
234
				} catch (IOException e) {
222
					e.printStackTrace();
235
					e.printStackTrace();
223
				}
236
				}
224
			}
237
			}*/
225
		}
238
		}
226
		System.out.println("Before sending email");
239
		System.out.println("Before sending email");
227
		String text = tableHeader+pricingItems.toString()+tableFooter;
240
		String text = tableHeader+pricingItems.toString()+tableFooter;
228
		try {
241
		try {
229
			mailer.sendSSLMessage(sendTo,"Flipkart Pricing Sent Details ", emailFromAddress, password, text);
242
			mailer.sendSSLMessage(sendTo,"Flipkart Pricing Sent Details ", emailFromAddress, password, text);
230
		} catch (MessagingException e) {
243
		} catch (MessagingException e) {
231
			e.printStackTrace();
244
			e.printStackTrace();
232
		}
245
		}
233
		Client catalogClient = null;
246
		Client catalogClient = null;
-
 
247
		
234
		if(feedResponse.toString().length()>0){
248
		StringBuffer feedResponse = new StringBuffer();
-
 
249
		for(Long itemId: feedResponseMap.keySet()){
-
 
250
			boolean updated = feedResponseMap.get(itemId);
235
			try {
251
			if(updated){
236
				mailer.sendSSLMessage(sendTo, "Flipkart Pricing could not be updated ", feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
252
				feedResponse.append("Price Updated at Flipkart for Item Id : "+itemId +" Status:  Successful");
237
			} catch (MessagingException e) {
253
				updatedItems.add(itemId);
238
				e.printStackTrace();
254
			}else{
-
 
255
				feedResponse.append("Price Updated at Flipkart for Item Id : "+itemId +" Status: Failed");
239
			}
256
			}
-
 
257
			
240
		}
258
		}
-
 
259
		if(feedResponse.toString().length()>0){
241
		else{
260
			
242
			try {
261
			try {
243
				mailer.sendSSLMessage(sendTo, "Flipkart Pricing updated successfully ", feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
262
				mailer.sendSSLMessage(sendTo, "Flipkart Pricing Updation Response ", feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
244
				try {
-
 
245
					catalogClient = new CatalogClient().getClient();
-
 
246
					catalogClient.updateMarketPlacePriceUpdateStatus(updatedItems,time,8);
-
 
247
				} catch (TException e) {
263
				if(updatedItems.size()>0){
248
					try {
264
					try {
-
 
265
						catalogClient = new CatalogClient().getClient();
-
 
266
						catalogClient.updateMarketPlacePriceUpdateStatus(updatedItems,time,8);
-
 
267
					} catch (TException e) {
-
 
268
						try {
249
						new CatalogClient().getClient().updateMarketPlacePriceUpdateStatus(updatedItems, time,8);
269
							new CatalogClient().getClient().updateMarketPlacePriceUpdateStatus(updatedItems, time,8);
250
					} catch (TTransportException e1) {
270
						} catch (TTransportException e1) {
251
						e1.printStackTrace();
271
							e1.printStackTrace();
252
					} catch (TException e1) {
272
						} catch (TException e1) {
253
						e1.printStackTrace();
273
							e1.printStackTrace();
-
 
274
						}
-
 
275
						e.printStackTrace();
254
					}
276
					}
255
					e.printStackTrace();
-
 
256
				}
277
				}
257
 
278
 
258
			} catch (MessagingException e) {
279
			} catch (MessagingException e) {
259
				try {
280
				try {
260
					catalogClient = new CatalogClient().getClient();
281
					catalogClient = new CatalogClient().getClient();