| Line 1... |
Line 1... |
| 1 |
package in.shop2020;
|
1 |
package in.shop2020;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.logistics.DeliveryType;
|
- |
|
| 4 |
import in.shop2020.logistics.LogisticsInfo;
|
- |
|
| 5 |
import in.shop2020.logistics.LogisticsServiceException;
|
- |
|
| 6 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
3 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
| 7 |
import in.shop2020.model.v1.catalog.FlipkartItem;
|
4 |
import in.shop2020.model.v1.catalog.FlipkartItem;
|
| 8 |
import in.shop2020.model.v1.catalog.Item;
|
5 |
import in.shop2020.model.v1.catalog.Item;
|
| 9 |
import in.shop2020.model.v1.catalog.MarketPlaceItemPrice;
|
6 |
import in.shop2020.model.v1.catalog.MarketPlaceItemPrice;
|
| 10 |
import in.shop2020.model.v1.catalog.status;
|
- |
|
| 11 |
import in.shop2020.model.v1.inventory.InventoryType;
|
- |
|
| 12 |
import in.shop2020.model.v1.inventory.ItemInventory;
|
- |
|
| 13 |
import in.shop2020.model.v1.inventory.Warehouse;
|
- |
|
| 14 |
import in.shop2020.model.v1.inventory.WarehouseLocation;
|
- |
|
| 15 |
import in.shop2020.model.v1.inventory.WarehouseType;
|
- |
|
| 16 |
import in.shop2020.model.v1.order.OrderSource;
|
- |
|
| 17 |
import in.shop2020.serving.model.Order;
|
- |
|
| 18 |
import in.shop2020.serving.model.OrderItems;
|
- |
|
| 19 |
import in.shop2020.thrift.clients.CatalogClient;
|
7 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 20 |
import in.shop2020.thrift.clients.InventoryClient;
|
- |
|
| 21 |
import in.shop2020.thrift.clients.LogisticsClient;
|
- |
|
| 22 |
import in.shop2020.thrift.clients.TransactionClient;
|
- |
|
| 23 |
import in.shop2020.utils.GmailUtils;
|
8 |
import in.shop2020.utils.GmailUtils;
|
| 24 |
import inventory.FlipkartInventoryItem;
|
- |
|
| 25 |
|
9 |
|
| 26 |
import java.io.BufferedReader;
|
10 |
import java.io.BufferedReader;
|
| 27 |
import java.io.File;
|
11 |
import java.io.File;
|
| 28 |
import java.io.IOException;
|
12 |
import java.io.IOException;
|
| 29 |
import java.io.InputStreamReader;
|
13 |
import java.io.InputStreamReader;
|
| 30 |
import java.io.UnsupportedEncodingException;
|
14 |
import java.io.UnsupportedEncodingException;
|
| 31 |
import java.util.ArrayList;
|
15 |
import java.util.ArrayList;
|
| 32 |
import java.util.HashMap;
|
16 |
import java.util.HashMap;
|
| 33 |
import java.util.List;
|
17 |
import java.util.List;
|
| 34 |
import java.util.Map;
|
18 |
import java.util.Map;
|
| 35 |
import java.util.Map.Entry;
|
- |
|
| 36 |
|
- |
|
| 37 |
import javax.mail.MessagingException;
|
19 |
import javax.mail.MessagingException;
|
| 38 |
|
- |
|
| 39 |
import org.apache.http.HttpResponse;
|
20 |
import org.apache.http.HttpResponse;
|
| 40 |
import org.apache.http.NameValuePair;
|
- |
|
| 41 |
import org.apache.http.auth.AuthScope;
|
21 |
import org.apache.http.auth.AuthScope;
|
| 42 |
import org.apache.http.auth.UsernamePasswordCredentials;
|
22 |
import org.apache.http.auth.UsernamePasswordCredentials;
|
| 43 |
import org.apache.http.client.ClientProtocolException;
|
23 |
import org.apache.http.client.ClientProtocolException;
|
| 44 |
import org.apache.http.client.HttpClient;
|
- |
|
| 45 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
- |
|
| 46 |
import org.apache.http.client.methods.HttpGet;
|
- |
|
| 47 |
import org.apache.http.client.methods.HttpPost;
|
24 |
import org.apache.http.client.methods.HttpPost;
|
| 48 |
import org.apache.http.entity.StringEntity;
|
25 |
import org.apache.http.entity.StringEntity;
|
| 49 |
import org.apache.http.impl.client.DefaultHttpClient;
|
26 |
import org.apache.http.impl.client.DefaultHttpClient;
|
| 50 |
import org.apache.http.message.BasicNameValuePair;
|
- |
|
| 51 |
import org.apache.thrift.TException;
|
27 |
import org.apache.thrift.TException;
|
| 52 |
import org.apache.thrift.transport.TTransportException;
|
28 |
import org.apache.thrift.transport.TTransportException;
|
| 53 |
|
29 |
|
| 54 |
import com.google.gson.Gson;
|
- |
|
| 55 |
|
- |
|
| 56 |
|
30 |
|
| 57 |
|
31 |
|
| 58 |
public class CreateSubmitFlipkartPricingFeed {
|
32 |
public class CreateSubmitFlipkartPricingFeed {
|
| - |
|
33 |
private static long time = System.currentTimeMillis();
|
| 59 |
private static List<MarketPlaceItemPrice> flipkartPricingItems;
|
34 |
private static List<MarketPlaceItemPrice> flipkartPricingItems;
|
| 60 |
private static Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>();
|
35 |
private static Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>();
|
| 61 |
private static Map<Long,FlipkartItem> flipkartItemsMap = new HashMap<Long,FlipkartItem>();
|
36 |
private static Map<Long,FlipkartItem> flipkartItemsMap = new HashMap<Long,FlipkartItem>();
|
| - |
|
37 |
static List<Long> updatedItems = new ArrayList<Long>();
|
| 62 |
static java.text.SimpleDateFormat sdf;
|
38 |
static java.text.SimpleDateFormat sdf;
|
| 63 |
static String emailFromAddress;
|
39 |
static String emailFromAddress;
|
| 64 |
static String password;
|
40 |
static String password;
|
| 65 |
static GmailUtils mailer;
|
41 |
static GmailUtils mailer;
|
| 66 |
static String sendTo[];
|
42 |
static String sendTo[];
|
| Line 80... |
Line 56... |
| 80 |
catalogServiceClient = new CatalogClient().getClient();
|
56 |
catalogServiceClient = new CatalogClient().getClient();
|
| 81 |
} catch (TTransportException e) {
|
57 |
} catch (TTransportException e) {
|
| 82 |
e.printStackTrace();
|
58 |
e.printStackTrace();
|
| 83 |
}
|
59 |
}
|
| 84 |
try {
|
60 |
try {
|
| - |
|
61 |
time = System.currentTimeMillis();
|
| 85 |
flipkartPricingItems = catalogServiceClient.getMarketPlaceItemsForPriceUpdate(8);
|
62 |
flipkartPricingItems = catalogServiceClient.getMarketPlaceItemsForPriceUpdate(8);
|
| 86 |
List<Item> aliveItems = catalogServiceClient.getAllAliveItems();
|
63 |
List<Item> aliveItems = catalogServiceClient.getAllAliveItems();
|
| 87 |
for(in.shop2020.model.v1.catalog.Item thriftItem:aliveItems){
|
64 |
for(in.shop2020.model.v1.catalog.Item thriftItem:aliveItems){
|
| 88 |
aliveItemsMap.put(thriftItem.getId(), thriftItem);
|
65 |
aliveItemsMap.put(thriftItem.getId(), thriftItem);
|
| 89 |
}
|
66 |
}
|
| Line 96... |
Line 73... |
| 96 |
e.printStackTrace();
|
73 |
e.printStackTrace();
|
| 97 |
}
|
74 |
}
|
| 98 |
if(flipkartPricingItems.size()==0){
|
75 |
if(flipkartPricingItems.size()==0){
|
| 99 |
String text = "";
|
76 |
String text = "";
|
| 100 |
try {
|
77 |
try {
|
| 101 |
mailer.sendSSLMessage(sendTo,"No items to send prices ", emailFromAddress, password, text);
|
78 |
mailer.sendSSLMessage(sendTo,"No Change in Flipkart item Prices ", emailFromAddress, password, text);
|
| 102 |
System.exit(0);
|
79 |
System.exit(0);
|
| 103 |
} catch (MessagingException e) {
|
80 |
} catch (MessagingException e) {
|
| 104 |
e.printStackTrace();
|
81 |
e.printStackTrace();
|
| 105 |
}
|
82 |
}
|
| 106 |
}
|
83 |
}
|
| Line 133... |
Line 110... |
| 133 |
+"</tr>";
|
110 |
+"</tr>";
|
| 134 |
String tableFooter = "</table></html>";
|
111 |
String tableFooter = "</table></html>";
|
| 135 |
Item item;
|
112 |
Item item;
|
| 136 |
StringBuffer feedResponse = null;
|
113 |
StringBuffer feedResponse = null;
|
| 137 |
for(MarketPlaceItemPrice entry:flipkartPricingItems){
|
114 |
for(MarketPlaceItemPrice entry:flipkartPricingItems){
|
| - |
|
115 |
if(!(entry.getLastUpdatedOn() > entry.getLastUpdatedOnMarketplace() && !entry.isIsPriceOverride() && entry.isIsListedOnSource() && entry.getSellingPrice()!=0)){
|
| - |
|
116 |
continue;
|
| - |
|
117 |
}
|
| - |
|
118 |
updatedItems.add(entry.getItem_id());
|
| 138 |
feedResponse= new StringBuffer();
|
119 |
feedResponse= new StringBuffer();
|
| 139 |
item = aliveItemsMap.get(entry.getItem_id());
|
120 |
item = aliveItemsMap.get(entry.getItem_id());
|
| 140 |
System.out.println("Item ID " + entry.getItem_id());
|
121 |
System.out.println("Item ID " + entry.getItem_id());
|
| 141 |
System.out.println("Product Name " + getProductName(item));
|
122 |
System.out.println("Product Name " + getProductName(item));
|
| 142 |
System.out.println("Selling Price " + entry.getSellingPrice());
|
123 |
System.out.println("Selling Price " + entry.getSellingPrice());
|
| Line 158... |
Line 139... |
| 158 |
try {
|
139 |
try {
|
| 159 |
input = new StringEntity(jsonStart+jsonRequest.toString()+jsonEnd);
|
140 |
input = new StringEntity(jsonStart+jsonRequest.toString()+jsonEnd);
|
| 160 |
System.out.println("Json input " + jsonStart+jsonRequest.toString()+jsonEnd);
|
141 |
System.out.println("Json input " + jsonStart+jsonRequest.toString()+jsonEnd);
|
| 161 |
jsonRequest = new StringBuffer();
|
142 |
jsonRequest = new StringBuffer();
|
| 162 |
} catch (UnsupportedEncodingException e) {
|
143 |
} catch (UnsupportedEncodingException e) {
|
| 163 |
// TODO Auto-generated catch block
|
- |
|
| 164 |
e.printStackTrace();
|
144 |
e.printStackTrace();
|
| 165 |
}
|
145 |
}
|
| 166 |
input.setContentType("application/json");
|
146 |
input.setContentType("application/json");
|
| 167 |
|
147 |
|
| 168 |
httppost.setEntity(input);
|
148 |
httppost.setEntity(input);
|
| Line 170... |
Line 150... |
| 170 |
try {
|
150 |
try {
|
| 171 |
System.out.println("Before send " );
|
151 |
System.out.println("Before send " );
|
| 172 |
response = httpclient.execute(httppost);
|
152 |
response = httpclient.execute(httppost);
|
| 173 |
System.out.println("After send " );
|
153 |
System.out.println("After send " );
|
| 174 |
} catch (IOException e) {
|
154 |
} catch (IOException e) {
|
| 175 |
// TODO Auto-generated catch block
|
- |
|
| 176 |
e.printStackTrace();
|
155 |
e.printStackTrace();
|
| 177 |
}
|
156 |
}
|
| 178 |
BufferedReader rd = null;
|
157 |
BufferedReader rd = null;
|
| 179 |
try {
|
158 |
try {
|
| 180 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
159 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 181 |
} catch (IllegalStateException e) {
|
160 |
} catch (IllegalStateException e) {
|
| 182 |
// TODO Auto-generated catch block
|
- |
|
| 183 |
e.printStackTrace();
|
161 |
e.printStackTrace();
|
| 184 |
} catch (IOException e) {
|
162 |
} catch (IOException e) {
|
| 185 |
// TODO Auto-generated catch block
|
- |
|
| 186 |
e.printStackTrace();
|
163 |
e.printStackTrace();
|
| 187 |
}
|
164 |
}
|
| 188 |
String line;
|
165 |
String line;
|
| 189 |
try {
|
166 |
try {
|
| 190 |
while ((line = rd.readLine()) != null) {
|
167 |
while ((line = rd.readLine()) != null) {
|
| Line 203... |
Line 180... |
| 203 |
}
|
180 |
}
|
| 204 |
}
|
181 |
}
|
| 205 |
System.out.println("Before sending email");
|
182 |
System.out.println("Before sending email");
|
| 206 |
String text = tableHeader+pricingItems.toString()+tableFooter;
|
183 |
String text = tableHeader+pricingItems.toString()+tableFooter;
|
| 207 |
try {
|
184 |
try {
|
| 208 |
mailer.sendSSLMessage(sendTo,"Flipkart Inventory Sent Details ", emailFromAddress, password, text);
|
185 |
mailer.sendSSLMessage(sendTo,"Flipkart Pricing Sent Details ", emailFromAddress, password, text);
|
| 209 |
} catch (MessagingException e) {
|
186 |
} catch (MessagingException e) {
|
| 210 |
e.printStackTrace();
|
187 |
e.printStackTrace();
|
| 211 |
}
|
188 |
}
|
| - |
|
189 |
Client catalogClient = null;
|
| 212 |
if(feedResponse.toString().length()>0){
|
190 |
if(feedResponse.toString().length()>0){
|
| 213 |
try {
|
191 |
try {
|
| 214 |
mailer.sendSSLMessage(sendTo, "Flipkart Inventory could not be updated ", feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
|
192 |
mailer.sendSSLMessage(sendTo, "Flipkart Pricing could not be updated ", feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
|
| - |
|
193 |
try {
|
| - |
|
194 |
catalogClient = new CatalogClient().getClient();
|
| - |
|
195 |
catalogClient.updateMarketPlacePriceUpdateStatus(updatedItems,time,8);
|
| - |
|
196 |
} catch (TException e) {
|
| - |
|
197 |
try {
|
| - |
|
198 |
new CatalogClient().getClient().updateMarketPlacePriceUpdateStatus(updatedItems, time,8);
|
| - |
|
199 |
} catch (TTransportException e1) {
|
| - |
|
200 |
e1.printStackTrace();
|
| - |
|
201 |
} catch (TException e1) {
|
| - |
|
202 |
e1.printStackTrace();
|
| - |
|
203 |
}
|
| - |
|
204 |
e.printStackTrace();
|
| - |
|
205 |
}
|
| - |
|
206 |
|
| 215 |
} catch (MessagingException e) {
|
207 |
} catch (MessagingException e) {
|
| - |
|
208 |
try {
|
| - |
|
209 |
catalogClient = new CatalogClient().getClient();
|
| - |
|
210 |
catalogClient.updateMarketPlacePriceUpdateStatus(updatedItems,time,8);
|
| - |
|
211 |
} catch (TException ex) {
|
| - |
|
212 |
try {
|
| - |
|
213 |
new CatalogClient().getClient().updateMarketPlacePriceUpdateStatus(updatedItems, time,8);
|
| - |
|
214 |
} catch (TTransportException e1) {
|
| - |
|
215 |
e1.printStackTrace();
|
| - |
|
216 |
} catch (TException e1) {
|
| - |
|
217 |
e1.printStackTrace();
|
| - |
|
218 |
}
|
| - |
|
219 |
ex.printStackTrace();
|
| - |
|
220 |
}
|
| 216 |
e.printStackTrace();
|
221 |
e.printStackTrace();
|
| 217 |
}
|
222 |
}
|
| 218 |
}
|
223 |
}
|
| 219 |
else{
|
224 |
else{
|
| 220 |
try {
|
225 |
try {
|
| 221 |
mailer.sendSSLMessage(sendTo, "Flipkart Inventory updated successfully ", feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
|
226 |
mailer.sendSSLMessage(sendTo, "Flipkart Pricing updated successfully ", feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
|
| 222 |
} catch (MessagingException e) {
|
227 |
} catch (MessagingException e) {
|
| 223 |
e.printStackTrace();
|
228 |
e.printStackTrace();
|
| 224 |
}
|
229 |
}
|
| 225 |
}
|
230 |
}
|
| 226 |
}
|
231 |
}
|