Subversion Repositories SmartDukaan

Rev

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

Rev 5527 Rev 5945
Line 1... Line 1...
1
/**
1
/**
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.support.controllers;
4
package in.shop2020.support.controllers;
5
 
5
 
6
import in.shop2020.model.v1.catalog.InventoryServiceException;
6
import in.shop2020.model.v1.catalog.CatalogServiceException;
7
import in.shop2020.model.v1.catalog.Item;
7
import in.shop2020.model.v1.catalog.Item;
8
import in.shop2020.model.v1.order.LineItem;
8
import in.shop2020.model.v1.order.LineItem;
9
import in.shop2020.model.v1.order.Order;
9
import in.shop2020.model.v1.order.Order;
10
import in.shop2020.model.v1.order.OrderStatus;
10
import in.shop2020.model.v1.order.OrderStatus;
11
import in.shop2020.model.v1.order.OrderType;
11
import in.shop2020.model.v1.order.OrderType;
Line 191... Line 191...
191
            addActionError("Error while finding customer: " + customerEmailId);
191
            addActionError("Error while finding customer: " + customerEmailId);
192
            log.error("Could not fetch user for email Id: " + customerEmailId, e);
192
            log.error("Could not fetch user for email Id: " + customerEmailId, e);
193
        } catch (TransactionServiceException e) {
193
        } catch (TransactionServiceException e) {
194
            addActionError("Error creating transaction");
194
            addActionError("Error creating transaction");
195
            log.error("Could not create transction Id", e);
195
            log.error("Could not create transction Id", e);
196
        } catch (InventoryServiceException e) {
196
        } catch (CatalogServiceException e) {
197
            addActionError("Error updating inventory");
197
            addActionError("Error updating inventory");
198
            log.error("Error in CatalogService", e);
198
            log.error("Error in CatalogService", e);
199
        } catch (NumberFormatException e) {
199
        } catch (NumberFormatException e) {
200
            addActionError("Error parsing transaction Id: " + transactionId);
200
            addActionError("Error parsing transaction Id: " + transactionId);
201
            log.error("Error parsing transaction Id: " + transactionId, e);
201
            log.error("Error parsing transaction Id: " + transactionId, e);
Line 214... Line 214...
214
 
214
 
215
    public String getModelName() {
215
    public String getModelName() {
216
        output = "Invalid Item Id: " + itemId;
216
        output = "Invalid Item Id: " + itemId;
217
 
217
 
218
        try {
218
        try {
219
            in.shop2020.model.v1.catalog.InventoryService.Client client = new CatalogClient().getClient();
219
            in.shop2020.model.v1.catalog.CatalogService.Client client = new CatalogClient().getClient();
220
            Item item = client.getItem(Long.parseLong(itemId));
220
            Item item = client.getItem(Long.parseLong(itemId));
221
            if (item != null && item.getId() != 0) {
221
            if (item != null && item.getId() != 0) {
222
                output = ModelUtils.extractProductNameFromItem(item);
222
                output = ModelUtils.extractProductNameFromItem(item);
223
            }
223
            }
224
        } catch (NumberFormatException e) {
224
        } catch (NumberFormatException e) {
225
            log.error("Could not parse itemId: " + itemId, e);
225
            log.error("Could not parse itemId: " + itemId, e);
226
        } catch (InventoryServiceException e) {
226
        } catch (CatalogServiceException e) {
227
            log.error("Could not lookup itemId: " + itemId, e);
227
            log.error("Could not lookup itemId: " + itemId, e);
228
        } catch (TException e) {
228
        } catch (TException e) {
229
            log.error("Could not find itemId: " + itemId, e);
229
            log.error("Could not find itemId: " + itemId, e);
230
        }
230
        }
231
 
231
 
Line 243... Line 243...
243
        in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
243
        in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
244
        long paymentId = client.createPayment(user.getUserId(), Double.valueOf(amount), RTGS_GATEWAY_ID, Long.valueOf(transactionId));
244
        long paymentId = client.createPayment(user.getUserId(), Double.valueOf(amount), RTGS_GATEWAY_ID, Long.valueOf(transactionId));
245
        client.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.SUCCESS, null, paymentAttributes);
245
        client.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.SUCCESS, null, paymentAttributes);
246
    }
246
    }
247
 
247
 
248
    private long createTransaction(User user) throws TransactionServiceException, TException, InventoryServiceException {
248
    private long createTransaction(User user) throws TransactionServiceException, TException, CatalogServiceException {
249
        Transaction txn = new Transaction();
249
        Transaction txn = new Transaction();
250
        txn.setShoppingCartid(user.getActiveCartId());
250
        txn.setShoppingCartid(user.getActiveCartId());
251
        txn.setCustomer_id(user.getUserId());
251
        txn.setCustomer_id(user.getUserId());
252
        txn.setCreatedOn(new Date().getTime());
252
        txn.setCreatedOn(new Date().getTime());
253
        txn.setTransactionStatus(TransactionStatus.INIT);
253
        txn.setTransactionStatus(TransactionStatus.INIT);
Line 255... Line 255...
255
        txn.setOrders(createOrders(user));
255
        txn.setOrders(createOrders(user));
256
        Client transaction_client = new TransactionClient().getClient();
256
        Client transaction_client = new TransactionClient().getClient();
257
        return transaction_client.createTransaction(txn);
257
        return transaction_client.createTransaction(txn);
258
    }
258
    }
259
 
259
 
260
    private List<Order> createOrders(User user) throws InventoryServiceException, TException {
260
    private List<Order> createOrders(User user) throws CatalogServiceException, TException {
261
        List<Order> orders = new ArrayList<Order>();
261
        List<Order> orders = new ArrayList<Order>();
262
 
262
 
263
        // Extracting default address
263
        // Extracting default address
264
        Address defaultAddress = null;
264
        Address defaultAddress = null;
265
        for (Address address : user.getAddresses()) {
265
        for (Address address : user.getAddresses()) {
Line 294... Line 294...
294
 
294
 
295
        return orders;
295
        return orders;
296
    }
296
    }
297
 
297
 
298
    private LineItem enrichLineItem(LineItem lineItem)
298
    private LineItem enrichLineItem(LineItem lineItem)
299
            throws InventoryServiceException, TException {
299
            throws CatalogServiceException, TException {
300
        in.shop2020.model.v1.catalog.InventoryService.Client client = new CatalogClient().getClient();
300
        in.shop2020.model.v1.catalog.CatalogService.Client client = new CatalogClient().getClient();
301
 
301
 
302
        Item item = client.getItem(lineItem.getItem_id());
302
        Item item = client.getItem(lineItem.getItem_id());
303
 
303
 
304
        lineItem.setProductGroup(item.getProductGroup());
304
        lineItem.setProductGroup(item.getProductGroup());
305
        lineItem.setBrand(item.getBrand());
305
        lineItem.setBrand(item.getBrand());