Subversion Repositories SmartDukaan

Rev

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

Rev 8642 Rev 8645
Line 38... Line 38...
38
import javax.xml.bind.Marshaller;
38
import javax.xml.bind.Marshaller;
39
import javax.xml.bind.Unmarshaller;
39
import javax.xml.bind.Unmarshaller;
40
 
40
 
41
import org.apache.thrift.TException;
41
import org.apache.thrift.TException;
42
import org.apache.thrift.transport.TTransportException;
42
import org.apache.thrift.transport.TTransportException;
-
 
43
import org.slf4j.Logger;
-
 
44
import org.slf4j.LoggerFactory;
43
 
45
 
44
import order.SaholicAPI;
46
import order.SaholicAPI;
45
import order.ObjectFactory;
47
import order.ObjectFactory;
46
import order.SaholicAPI.Order;
48
import order.SaholicAPI.Order;
47
 
49
 
Line 52... Line 54...
52
	private static final String DELHIVERY = "DELHIVERY";
54
	private static final String DELHIVERY = "DELHIVERY";
53
	private static final String BLUEDART = "Bluedart";
55
	private static final String BLUEDART = "Bluedart";
54
	private static final String CHHOTU = "CHHOTU";
56
	private static final String CHHOTU = "CHHOTU";
55
	private static String transactionId;
57
	private static String transactionId;
56
	private static final int SNAPDEAL_GATEWAY_ID = 18;
58
	private static final int SNAPDEAL_GATEWAY_ID = 18;
-
 
59
	private static Logger logger = LoggerFactory.getLogger(ProcessSnapdealOrder.class);
57
 
60
 
58
	public static void processSnapdealOrders(File file) throws JAXBException{
61
	public static void processSnapdealOrders(File file) throws JAXBException{
59
		JAXBContext jc = JAXBContext.newInstance(SaholicAPI.class);
62
		JAXBContext jc = JAXBContext.newInstance(SaholicAPI.class);
60
		Unmarshaller unmarshaller = jc.createUnmarshaller();
63
		Unmarshaller unmarshaller = jc.createUnmarshaller();
61
		SaholicAPI orders = (SaholicAPI) unmarshaller.unmarshal(file);
64
		SaholicAPI orders = (SaholicAPI) unmarshaller.unmarshal(file);
Line 67... Line 70...
67
		TransactionClient tsc = null;
70
		TransactionClient tsc = null;
68
		try {
71
		try {
69
			tsc = new TransactionClient();
72
			tsc = new TransactionClient();
70
			sourceDetail = tsc.getClient().getSourceDetail(SNAPDEAL_SOURCE_ID);
73
			sourceDetail = tsc.getClient().getSourceDetail(SNAPDEAL_SOURCE_ID);
71
		} catch (Exception e) {
74
		} catch (Exception e) {
-
 
75
			logger.error("Unable to establish connection to the transaction service while getting Snapdeal Source Detail", e);
72
		}
76
		}
73
		try {   
77
		try {   
74
			in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
78
			in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
75
			user = userClient.getUserByEmail(sourceDetail.getEmail());
79
			user = userClient.getUserByEmail(sourceDetail.getEmail());
76
		} catch (Exception e) {
80
		} catch (Exception e) {
-
 
81
	        logger.error("Unable to establish connection to the User service", e);
77
		}
82
		}
78
		for(Order order:orders.getOrder()){
83
		for(Order order:orders.getOrder()){
79
			long subOrderId = (long) order.getSuborderId();
84
			long subOrderId = (long) order.getSuborderId();
80
			Client transaction_client = null;
85
			Client transaction_client = null;
81
			try {
86
			try {
Line 108... Line 113...
108
			LineItem lineItem = null;
113
			LineItem lineItem = null;
109
			try {
114
			try {
110
				lineItem = createLineItem(order.getSKUCode(),order.getSellingPricePerItem());
115
				lineItem = createLineItem(order.getSKUCode(),order.getSellingPricePerItem());
111
				System.out.println("Line item created");
116
				System.out.println("Line item created");
112
			} catch (CatalogServiceException e) {
117
			} catch (CatalogServiceException e) {
113
				// TODO Auto-generated catch block
118
				logger.error("Unable to create order for suborderid  " + order.getSuborderId());
114
				e.printStackTrace();
119
				e.printStackTrace();
115
			} catch (TException e) {
120
			} catch (TException e) {
116
				// TODO Auto-generated catch block
121
				logger.error("Unable to create order for suborderid  " + order.getSuborderId());
117
				e.printStackTrace();
122
				e.printStackTrace();
118
			}
123
			}
119
			in.shop2020.model.v1.order.Order t_order = new in.shop2020.model.v1.order.Order();
124
			in.shop2020.model.v1.order.Order t_order = new in.shop2020.model.v1.order.Order();
120
			t_order.setCustomer_id(user.getUserId());
125
			t_order.setCustomer_id(user.getUserId());
121
			t_order.setCustomer_email(sourceDetail.getEmail());
126
			t_order.setCustomer_email(sourceDetail.getEmail());
Line 142... Line 147...
142
				time.add(Calendar.DAY_OF_MONTH, 3);
147
				time.add(Calendar.DAY_OF_MONTH, 3);
143
				t_order.setPromised_delivery_time(time.getTimeInMillis());
148
				t_order.setPromised_delivery_time(time.getTimeInMillis());
144
				t_order.setExpected_delivery_time(time.getTimeInMillis());
149
				t_order.setExpected_delivery_time(time.getTimeInMillis());
145
				System.out.println("Dates set in transaction");
150
				System.out.println("Dates set in transaction");
146
			} catch(Exception e) {
151
			} catch(Exception e) {
-
 
152
				logger.error("Error in updating Shipping or Delivery Time for suborderid  " + order.getSuborderId());
147
				continue;
153
				continue;
148
			}
154
			}
149
			/*InventoryService.Client inventoryClient = null;
155
			/*InventoryService.Client inventoryClient = null;
150
            //Warehouse fulfillmentWarehouse= null; 
156
            //Warehouse fulfillmentWarehouse= null; 
151
            try {
157
            try {
Line 169... Line 175...
169
			} else if(order.getCourier().equalsIgnoreCase(BLUEDART)) {
175
			} else if(order.getCourier().equalsIgnoreCase(BLUEDART)) {
170
				t_order.setLogistics_provider_id(14);
176
				t_order.setLogistics_provider_id(14);
171
			}else if(order.getCourier().equalsIgnoreCase(CHHOTU)) {
177
			}else if(order.getCourier().equalsIgnoreCase(CHHOTU)) {
172
				t_order.setLogistics_provider_id(16);
178
				t_order.setLogistics_provider_id(16);
173
			} else {
179
			} else {
174
				System.out.println("No Courier Match");
180
				logger.error("Error No Courier Match please add courier to our system");
175
				continue;
181
				continue;
176
			}
182
			}
177
 
183
 
178
			t_order.setAirwaybill_no(String.valueOf(order.getAWBNumber()));
184
			t_order.setAirwaybill_no(String.valueOf(order.getAWBNumber()));
179
			t_order.setTracking_id(String.valueOf(order.getAWBNumber()));
185
			t_order.setTracking_id(String.valueOf(order.getAWBNumber()));
Line 206... Line 212...
206
				snapdealOrder.setProductName(productName);
212
				snapdealOrder.setProductName(productName);
207
				snapdealOrder.setSnapdealTxnDate(snapdealTxnDate.getTime());
213
				snapdealOrder.setSnapdealTxnDate(snapdealTxnDate.getTime());
208
				snapdealOrder.setListingPrice(lineItem.getTotal_price());
214
				snapdealOrder.setListingPrice(lineItem.getTotal_price());
209
				transaction_client.createSnapdealOrder(snapdealOrder);
215
				transaction_client.createSnapdealOrder(snapdealOrder);
210
 
216
 
211
			} catch (Exception e) {
217
			} catch (TException e) {
-
 
218
				logger.error("Error in creating payment  " + order.getSuborderId());
-
 
219
				continue;
-
 
220
			}
-
 
221
			catch (PaymentException e) {
-
 
222
				logger.error("Error in creating payment  " + order.getSuborderId());
-
 
223
				continue;
-
 
224
			}
-
 
225
			catch (Exception e) {
212
				System.out.println("Exception in finding suborderid");
226
				logger.error("Error in creating transaction  " + order.getSuborderId());
213
				continue;
227
				continue;
214
			}
228
			}
215
 
-
 
216
 
-
 
217
		}
229
		}
218
 
230
 
219
	}
231
	}
220
 
232
 
221
	public static void createPayment(User user, String subOrderId, double amount) throws NumberFormatException, PaymentException, TException {
233
	public static void createPayment(User user, String subOrderId, double amount) throws NumberFormatException, PaymentException, TException {