Subversion Repositories SmartDukaan

Rev

Rev 21454 | Rev 22364 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
130 ashish 1
'''
2
Created on 28-Apr-2010
3
 
4
@author: ashish
5
'''
12696 amit.gupta 6
from shop2020.helpers.impl.DataAccessor import close_session
11596 amit.gupta 7
from shop2020.model.v1.user.impl import UserDataAccessors, CartDataAccessors
8
from shop2020.model.v1.user.impl.CartDataAccessors import create_cart, get_cart, \
9
    get_cart_by_id, get_carts_between, add_item_to_cart, add_address_to_cart, \
10
    commit_cart, validate_cart, merge_cart, delete_item_from_cart, check_out, \
11
    reset_cart, apply_coupon_to_cart, remove_coupon, get_carts_with_coupon_count, \
12
    delete_discounts_from_cart, save_discounts, show_cod_option, insure_item, \
13
    cancel_insurance, store_insurance_specific_details, is_insurance_detail_present, \
17782 amit.gupta 14
    add_store_to_cart, get_products_added_to_cart, validate_cart_plus, \
20981 amit.gupta 15
    add_items_to_cart, validate_cart_new, set_wallet_amount_in_cart
11596 amit.gupta 16
from shop2020.model.v1.user.impl.Converters import to_t_user, to_t_cart, \
17
    to_t_address, to_t_user_communication, to_t_master_affiliate, to_t_affiliate, \
12790 amit.gupta 18
    to_t_tracker, to_t_track_log, to_t_private_deal_user, to_t_counter
11596 amit.gupta 19
from shop2020.model.v1.user.impl.Dataservice import UserWidgetItem
20
from shop2020.model.v1.user.impl.UserDataAccessors import create_user, \
21
    update_user, get_user_by_id, get_user_by_email, update_password, \
22
    set_user_as_logged_out, set_user_as_logged_in, remove_address_for_user, \
23
    add_address_for_user, authenticate_user, user_exists, initialize, \
24
    set_default_address, create_anonymous_user, forgot_password, \
25
    get_all_addresses_for_user, get_address, get_default_address_id, \
26
    get_default_pincode, create_user_communication, get_user_communication_by_id, \
27
    get_user_communication_by_user, get_all_user_communications, create_affiliate, \
28
    get_affiliate_by_id, get_affiliate_by_name, get_tracker_by_id, add_track_log, \
29
    get_track_log_by_id, get_track_logs_by_affiliate, get_track_logs_by_user, \
30
    get_track_logs, create_master_affiliate, get_master_affiliate_by_id, \
31
    get_master_affiliate_by_name, get_affiliates_by_master_affiliate, \
32
    get_all_master_affiliates, get_my_research_items, get_browse_history_items, \
33
    update_my_research, delete_item_from_my_research, update_browse_history, \
34
    get_user_by_mobile_number, is_alive, increase_trust_level, get_user_by_cart_id, \
11704 amit.gupta 35
    get_trust_level, remove_user_communication, get_user_emails, \
12696 amit.gupta 36
    is_private_deal_user, add_private_deal_user, change_private_deal_user_status, \
12722 amit.gupta 37
    get_private_deal_user, register_counter, search_counter, \
17782 amit.gupta 38
    get_all_users_by_counter, get_active_access_token_for_user, \
18977 amit.gupta 39
    validate_access_token, is_address_editable_for_counter, \
40
    get_billing_address_for_user, is_creditor_assigned, is_tax_invoice_enabled_user, \
22358 ashik.ali 41
    get_cart_by_value, get_counter_by_user_id, tax_invoice_available, \
42
    get_counter_name, update_address
11596 amit.gupta 43
from shop2020.thriftpy.model.v1.user.ttypes import ShoppingCartException
5623 anupam.sin 44
from shop2020.utils.Utils import log_entry, to_py_date
22358 ashik.ali 45
from shop2020.thriftpy.model.v1.user.UserContextService import setWalletAmountInCart_args
3032 mandeep.dh 46
 
576 chandransh 47
 
5623 anupam.sin 48
#from apport.hookutils import ret
130 ashish 49
class UserContextServiceHandler:
50
 
404 rajveer 51
 
3187 rajveer 52
    def __init__(self, dbname='user', db_hostname='localhost'):
53
        initialize(dbname, db_hostname)
557 chandransh 54
 
130 ashish 55
    """
557 chandransh 56
    service
130 ashish 57
    """
557 chandransh 58
    def createAnonymousUser(self, jsessionId):
766 rajveer 59
        try:
5326 rajveer 60
            return to_t_user(create_anonymous_user(jsessionId))
766 rajveer 61
        finally:
4323 mandeep.dh 62
            self.closeSession()
4211 mandeep.dh 63
 
557 chandransh 64
    def getUserById(self, userId):
130 ashish 65
        """
66
        Parameters:
557 chandransh 67
        - userId
130 ashish 68
        """
766 rajveer 69
        try:
70
            return to_t_user(get_user_by_id(userId))
71
        finally:
4323 mandeep.dh 72
            self.closeSession()
1491 vikas 73
 
5326 rajveer 74
    def getUserByCartId(self, cartId):
75
        """
76
        Parameters:
77
        - cartId
78
        """
79
        try:
80
            return to_t_user(get_user_by_cart_id(cartId))
81
        finally:
82
            self.closeSession()
83
 
3032 mandeep.dh 84
    def getUserByMobileNumber(self, mobileNumber):
85
        """
86
        Parameters:
87
        - mobileNumber
88
        """
89
        try:
90
            return to_t_user(get_user_by_mobile_number(mobileNumber))
91
        finally:
4323 mandeep.dh 92
            self.closeSession()
3032 mandeep.dh 93
 
1491 vikas 94
    def getUserByEmail(self, email):
95
        """
96
        Parameters:
97
         - email
98
        """
99
        try:
100
            return to_t_user(get_user_by_email(email))
101
        finally:
4323 mandeep.dh 102
            self.closeSession()
1491 vikas 103
 
557 chandransh 104
    def createUser(self, user):
130 ashish 105
        """
106
        Parameters:
557 chandransh 107
        - user
130 ashish 108
        """
766 rajveer 109
        try:
5326 rajveer 110
            return to_t_user(create_user(user))
766 rajveer 111
        finally:
4323 mandeep.dh 112
            self.closeSession()
113
 
557 chandransh 114
    def updateUser(self, user):
130 ashish 115
        """
116
        Parameters:
557 chandransh 117
        - user
130 ashish 118
        """
766 rajveer 119
        try:
120
            return to_t_user(update_user(user))
121
        finally:
4323 mandeep.dh 122
            self.closeSession()
766 rajveer 123
 
557 chandransh 124
    def authenticateUser(self, email, password):
130 ashish 125
        """
126
        Parameters:
557 chandransh 127
        - email
128
        - password
129
        """
130
        log_entry(self, "authenticate user")
766 rajveer 131
        try:
132
            return to_t_user(authenticate_user(email, password))
133
        finally:
4323 mandeep.dh 134
            self.closeSession()
766 rajveer 135
 
557 chandransh 136
    def userExists(self, email):
137
        """
138
        Parameters:
139
        - email
140
        """
141
        log_entry(self, "user exists")
766 rajveer 142
        try:
143
            return user_exists(email)
144
        finally:
4323 mandeep.dh 145
            self.closeSession()
766 rajveer 146
 
567 rajveer 147
    def addAddressForUser(self, userId, address, setDefault):
557 chandransh 148
        """
149
        Parameters:
150
        - userId
151
        - address
152
        - setDefault
153
        """
154
        log_entry(self, "add address for user")
766 rajveer 155
        try:
156
            return add_address_for_user(address, userId, setDefault)
157
        finally:
4323 mandeep.dh 158
            self.closeSession()
766 rajveer 159
 
557 chandransh 160
    def removeAddressForUser(self, userid, addressId):
161
        """
162
        Parameters:
163
        - userid
164
        - addressId
165
        """
166
        log_entry(self, "removing address")
766 rajveer 167
        try:
168
            return remove_address_for_user(userid, addressId)
169
        finally:
4323 mandeep.dh 170
            self.closeSession()
766 rajveer 171
 
557 chandransh 172
    def setUserAsLoggedIn(self, userId, timestamp):
173
        """
174
        Parameters:
175
        - userId
176
        - timestamp
177
        """
178
        log_entry(self, "set_user_as_logged_in")
766 rajveer 179
        try:
180
            return set_user_as_logged_in(userId, timestamp)
181
        finally:
4323 mandeep.dh 182
            self.closeSession()
766 rajveer 183
 
557 chandransh 184
    def setUserAsLoggedOut(self, userId, timestamp):
185
        """
186
        Parameters:
187
        - userId
188
        - timestamp
189
        """
190
        log_entry(self, "set user as logged out")
766 rajveer 191
        try:
192
            return set_user_as_logged_out(userId, timestamp)
193
        finally:
4323 mandeep.dh 194
            self.closeSession()
766 rajveer 195
 
557 chandransh 196
    def setDefaultAddress(self, userId, addressId):
197
        """
198
        Parameters:
199
        - userId
200
        - addressId
201
        """
766 rajveer 202
        try:
203
            return set_default_address(userId, addressId)
204
        finally:
4323 mandeep.dh 205
            self.closeSession()
766 rajveer 206
 
594 rajveer 207
    def updatePassword(self, userid, oldPassword, newPassword):
557 chandransh 208
        """
209
        Parameters:
594 rajveer 210
         - userid
211
         - oldPassword
212
         - newPassword
557 chandransh 213
        """
214
        log_entry(self, "updating password")
766 rajveer 215
        try:
216
            return update_password(userid, oldPassword, newPassword)
217
        finally:
4323 mandeep.dh 218
            self.closeSession()
766 rajveer 219
 
884 rajveer 220
    def forgotPassword(self, email, password):
581 rajveer 221
        """
222
        Parameters:
223
         - email
224
        """
225
        log_entry(self, "forgot password")
766 rajveer 226
        try:
884 rajveer 227
            return forgot_password(email, password)
766 rajveer 228
        finally:
4323 mandeep.dh 229
            self.closeSession()
230
 
594 rajveer 231
    def getAllAddressesForUser(self, userId):
232
        """
233
        Parameters:
234
         - userId
235
        """
766 rajveer 236
        try:
18735 manish.sha 237
            addresses, taxInvoiceMap, creditOptionMap = get_all_addresses_for_user(userId)
766 rajveer 238
 
239
            t_addresses = list()
18735 manish.sha 240
            if len(taxInvoiceMap)==0 and len(creditOptionMap)==0: 
241
                for address in addresses:
242
                    t_addresses.append(to_t_address(address,False,False))
243
            else:
244
                for address in addresses:
245
                    t_addresses.append(to_t_address(address,taxInvoiceMap.get(address.id),creditOptionMap.get(address.id)))
766 rajveer 246
            return t_addresses
247
        finally:
4323 mandeep.dh 248
            self.closeSession()
594 rajveer 249
 
1894 vikas 250
    def getAddressById(self, addressId):
251
        """
252
        Parameters:
253
         - addressId
254
        """
255
        try:
18735 manish.sha 256
            address, taxInvoiceMap, creditOptionMap = get_address(addressId)
257
            return to_t_address(address, taxInvoiceMap.get(address.id), creditOptionMap.get(address.id))
1894 vikas 258
        finally:
4323 mandeep.dh 259
            self.closeSession()
1894 vikas 260
 
594 rajveer 261
    def getDefaultAddressId(self, userId):
262
        """
263
        Parameters:
264
         - userId
265
        """
766 rajveer 266
        try:
785 rajveer 267
            return get_default_address_id(userId)
766 rajveer 268
        finally:
4323 mandeep.dh 269
            self.closeSession()
785 rajveer 270
 
271
    def getDefaultPincode(self, userId):
272
        """
273
        Parameters:
274
         - userId
275
        """
276
        try:
277
            return get_default_pincode(userId)
278
        finally:
4323 mandeep.dh 279
            self.closeSession()
785 rajveer 280
 
557 chandransh 281
    def getCurrentCart(self, userId):
282
        """
283
        Parameters:
130 ashish 284
         - userId
285
        """
766 rajveer 286
        try:
287
            cart = get_cart(userId)
288
            if cart:
289
                return to_t_cart(cart)
290
            else:
291
                raise ShoppingCartException(101, "not cart attached to this user")
292
        finally:
4323 mandeep.dh 293
            self.closeSession()
766 rajveer 294
 
557 chandransh 295
    def getCart(self, cartId):
296
        """
297
        Parameters:
298
         - cartId
299
        """
766 rajveer 300
        try:
301
            cart = get_cart_by_id(cartId)
302
            if cart:
303
                return to_t_cart(cart)
304
            else:
305
                raise ShoppingCartException(101, "not cart attached to this id")
306
        finally:
4323 mandeep.dh 307
            self.closeSession()
766 rajveer 308
 
557 chandransh 309
    def getCartsByTime(self, from_time, to_time, status):
130 ashish 310
        """
311
        Parameters:
557 chandransh 312
         - from_time
313
         - to_time
314
         - status
130 ashish 315
        """
766 rajveer 316
        try:
317
            carts = get_carts_between(from_time, to_time, status)
318
            t_carts = []
319
            if carts:
320
                for cart in carts:
321
                    t_carts.append(to_t_cart(cart))
322
            return t_carts
323
        finally:
4323 mandeep.dh 324
            self.closeSession()
766 rajveer 325
 
3557 rajveer 326
    def addItemToCart(self, cartId, itemId, quantity, sourceId):
130 ashish 327
        """
328
        Parameters:
557 chandransh 329
         - cartId
330
         - itemId
331
         - quantity
130 ashish 332
        """
766 rajveer 333
        try:
3557 rajveer 334
            return add_item_to_cart(cartId, itemId, quantity, sourceId)
766 rajveer 335
        finally:
4323 mandeep.dh 336
            self.closeSession()
766 rajveer 337
 
557 chandransh 338
    def deleteItemFromCart(self, cartId, itemId):
130 ashish 339
        """
340
        Parameters:
557 chandransh 341
         - cartId
342
         - itemId
130 ashish 343
        """
766 rajveer 344
        try:
345
            delete_item_from_cart(cartId, itemId)
346
        finally:
4323 mandeep.dh 347
            self.closeSession()
766 rajveer 348
 
557 chandransh 349
    def addAddressToCart(self, cartId, addressId):
350
        """
351
        Parameters:
352
         - cartId
130 ashish 353
         - addressId
354
        """
766 rajveer 355
        try:
356
            return add_address_to_cart(cartId, addressId)
357
        finally:
4323 mandeep.dh 358
            self.closeSession()
1976 varun.gupt 359
 
6922 anupam.sin 360
    def applyCouponToCart(self, t_cart, couponCode):
1976 varun.gupt 361
        '''
362
        Parameters:
363
        - cartId
364
        - couponCode
365
        - totalPrice
366
        - discountedPrice
367
        '''
368
        try:
6922 anupam.sin 369
            apply_coupon_to_cart(t_cart, couponCode)
1976 varun.gupt 370
        finally:
4323 mandeep.dh 371
            self.closeSession()
1976 varun.gupt 372
 
373
    def removeCoupon(self, cartId):
374
        '''
375
        Parameters:
376
        - cartId
377
        '''
378
        try:
379
            remove_coupon(cartId)
380
        finally:
4323 mandeep.dh 381
            self.closeSession()
1976 varun.gupt 382
 
21454 amit.gupta 383
    def createOrders(self, cartId, sessionSource, sessionTime, firstSource, firstSourceTime, userId, schemeId, orderSource, selfPickup=False):
130 ashish 384
        """
385
        Parameters:
557 chandransh 386
         - cartId
2815 vikas 387
         - sessionSource
130 ashish 388
        """
766 rajveer 389
        try:
21454 amit.gupta 390
            return commit_cart(cartId, sessionSource, sessionTime, firstSource, firstSourceTime, userId, schemeId, orderSource, selfPickup)
766 rajveer 391
        finally:
4323 mandeep.dh 392
            self.closeSession()
1466 ankur.sing 393
 
3557 rajveer 394
    def validateCart(self, cartId, sourceId):
130 ashish 395
        """
1466 ankur.sing 396
        Validates that:
397
        1. The checkout timestamp is greater than the updatedOn timestamp.
398
        2. All of the lines in the cart are active items.
399
        3. The estimate for any of the lines in cart doesn't change.
1976 varun.gupt 400
        4. If a Coupon Code is attached, it gets applied and discounted price is computed
401
        If first three are true, returns empty string; else returns appropriate message.
1466 ankur.sing 402
 
130 ashish 403
        Parameters:
557 chandransh 404
         - cartId
130 ashish 405
        """
766 rajveer 406
        try:
11980 amit.gupta 407
            return validate_cart(cartId, sourceId, None)
766 rajveer 408
        finally:
4323 mandeep.dh 409
            self.closeSession()
766 rajveer 410
 
11980 amit.gupta 411
    def validateCartWithDealerCoupon(self, cartId, sourceId, couponCode):
412
        """
413
        Validates that:
414
        1. The checkout timestamp is greater than the updatedOn timestamp.
415
        2. All of the lines in the cart are active items.
416
        3. The estimate for any of the lines in cart doesn't change.
417
        4. If a Coupon Code is attached, it gets applied and discounted price is computed
418
        If first three are true, returns empty string; else returns appropriate message.
419
 
420
        Parameters:
421
         - cartId
422
        """
423
        try:
424
            return validate_cart(cartId, sourceId, couponCode)
425
        finally:
426
            self.closeSession()
427
 
557 chandransh 428
    def mergeCart(self, fromCartId, toCartId):
513 rajveer 429
        """
430
        Parameters:
557 chandransh 431
         - fromCartId
432
         - toCartId
513 rajveer 433
        """
766 rajveer 434
        try:
435
            merge_cart(fromCartId, toCartId)
436
        finally:
4323 mandeep.dh 437
            self.closeSession()
766 rajveer 438
 
691 chandransh 439
    def checkOut(self, cartId):
440
        """
441
        Sets the checkedOutOn timestamp of the cart. Raises an exception if the specified cart can't be found.
442
 
443
        Parameters:
444
         - cartId
445
        """
766 rajveer 446
        try:
447
            return check_out(cartId)
448
        finally:
4323 mandeep.dh 449
            self.closeSession()
766 rajveer 450
 
691 chandransh 451
    def resetCart(self, cartId, items):
452
        """
453
        The second parameter is a map of item ids and their quantities which have been successfully processed.
454
        This methods removes the specified quantiry of the specified item from the cart.
455
 
456
        Parameters:
457
         - cartId
458
         - items
459
        """
766 rajveer 460
        try:
461
            return reset_cart(cartId, items)
462
        finally:
4323 mandeep.dh 463
            self.closeSession()
772 rajveer 464
 
465
    #Widget related methods
466
    def updateMyResearch(self, userId, itemId):
467
        """
468
        Parameters:
469
         - user_id
470
         - item_id
471
        """
472
        try:
473
            return update_my_research(userId, itemId)
474
        finally:
4323 mandeep.dh 475
            self.closeSession()
772 rajveer 476
 
477
    def deleteItemFromMyResearch(self, userId, itemId):
478
        """
479
        Parameters:
480
         - user_id
481
         - item_id
482
        """
483
        try:
484
            return delete_item_from_my_research(userId, itemId)
485
        finally:
4323 mandeep.dh 486
            self.closeSession()
766 rajveer 487
 
772 rajveer 488
    def updateBrowseHistory(self, userId, itemId):
489
        """
490
        Parameters: 
491
        - user_id
492
        - item_id
493
        """
494
        try:
495
            update_browse_history(userId, itemId)
496
        finally:
4323 mandeep.dh 497
            self.closeSession()
772 rajveer 498
 
499
    def mergeBrowseHistory(self, fromUserId, toUserId):
500
        """
501
        Parameters:
502
         - user_id
503
        """
2981 rajveer 504
        pass
772 rajveer 505
 
1273 varun.gupt 506
    def saveUserCommunication(self, userId, email, communicationType, orderId, awb, product, subject, message):
507
        """
508
        Parameters:
509
         - userId
510
         - email
511
         - communicationType
512
         - orderId
513
         - awb
514
         - product
515
         - subject
516
         - message
517
        """
518
        try:
519
            return create_user_communication(userId, email, communicationType, orderId, awb, product, subject, message)
520
        finally:
4323 mandeep.dh 521
            self.closeSession()
1273 varun.gupt 522
 
1583 varun.gupt 523
    def getUserCommunicationById(self, id):
524
        """
525
        Parameters:
526
         - id
527
        """
528
        try:
529
            return to_t_user_communication(get_user_communication_by_id(id))
530
        finally:
4323 mandeep.dh 531
            self.closeSession()
1583 varun.gupt 532
 
533
    def getUserCommunicationByUser(self, userId):
534
        """
535
        Parameters:
536
         - userId
537
        """
538
        try:
539
            return [to_t_user_communication(user_communication) for user_communication in get_user_communication_by_user(userId)]
540
        finally:
4323 mandeep.dh 541
            self.closeSession()
1583 varun.gupt 542
 
543
    def getAllUserCommunications(self):
544
        try:
545
            return [to_t_user_communication(user_communication) for user_communication in get_all_user_communications()]
546
        finally:
4323 mandeep.dh 547
            self.closeSession()
5407 amar.kumar 548
 
549
    def removeUserCommunication(self, id):
550
        try:
551
            remove_user_communication(id)
552
        finally:
553
            self.closeSession()
1596 ankur.sing 554
 
1859 vikas 555
    def createMasterAffiliate(self, name, addedOn):
1845 vikas 556
        """
557
        Parameters
558
         - name
1859 vikas 559
         - addedOn
1845 vikas 560
        """
561
        try:
1859 vikas 562
            return to_t_master_affiliate(create_master_affiliate(name, addedOn))
1845 vikas 563
        finally:
4323 mandeep.dh 564
            self.closeSession()
1845 vikas 565
 
1899 vikas 566
    def getAllMasterAffiliates(self):
567
        try:
568
            return [to_t_master_affiliate(masterAffiliate) for masterAffiliate in get_all_master_affiliates()]
569
        finally:
4323 mandeep.dh 570
            self.closeSession()
1899 vikas 571
 
1845 vikas 572
    def getMasterAffiliateById(self, id):
573
        """
574
        Parameters
575
         - id
576
        """
577
        try:
578
            return to_t_master_affiliate(get_master_affiliate_by_id(id))
579
        finally:
4323 mandeep.dh 580
            self.closeSession()
1845 vikas 581
 
582
    def getMasterAffiliateByName(self, name):
583
        """
584
        Parameters
585
         - id
586
        """
587
        try:
588
            return to_t_master_affiliate(get_master_affiliate_by_name(name))
589
        finally:
4323 mandeep.dh 590
            self.closeSession()
1845 vikas 591
 
1859 vikas 592
    def createAffiliate(self, name, url, masterAffiliateId, addedOn):
1845 vikas 593
        """
594
        Parameters
595
         - name
596
         - url
1859 vikas 597
         - masterAffiliateId
598
         - addedOn
1845 vikas 599
        """
600
        try:
1859 vikas 601
            return to_t_affiliate(create_affiliate(name, url, masterAffiliateId, addedOn))
1845 vikas 602
        finally:
4323 mandeep.dh 603
            self.closeSession()
1845 vikas 604
 
605
    def getAffiliateById(self, id):
606
        """
607
        Parameters
608
         - id
609
        """
610
        try:
611
            return to_t_affiliate(get_affiliate_by_id(id))
612
        finally:
4323 mandeep.dh 613
            self.closeSession()
1845 vikas 614
 
615
    def getAffiliateByName(self, name):
616
        """
617
        Parameters
618
         - name
619
        """
620
        try:
621
            return to_t_affiliate(get_affiliate_by_name(name))
622
        finally:
4323 mandeep.dh 623
            self.closeSession()
1845 vikas 624
 
1996 vikas 625
    def getAffiliatesByMasterAffiliate(self, masterAffiliateId):
1845 vikas 626
        """
627
        Parameters
628
         - master_id
629
        """
630
        try:
1996 vikas 631
            return [to_t_affiliate(affiliate) for affiliate in get_affiliates_by_master_affiliate(masterAffiliateId)]
1845 vikas 632
        finally:
4323 mandeep.dh 633
            self.closeSession()
1845 vikas 634
 
1996 vikas 635
    def getTrackerById(self, trackerId):
1845 vikas 636
        """
637
        Parameters
1996 vikas 638
         - trackerId
1845 vikas 639
        """
640
        try:
1996 vikas 641
            return to_t_tracker(get_tracker_by_id(trackerId))
1845 vikas 642
        finally:
4323 mandeep.dh 643
            self.closeSession()
1996 vikas 644
 
645
    def addTrackLog(self, affiliateId, userId, event, url, data, addedOn):
1845 vikas 646
        """
1996 vikas 647
        Parameter
1845 vikas 648
         - affiliateId
649
         - userId
650
         - event
651
         - url
652
         - data
1859 vikas 653
         - addedOn
1845 vikas 654
        """
655
        try:
1996 vikas 656
            return add_track_log(affiliateId, userId, event, url, data, addedOn)
1845 vikas 657
        finally:
4323 mandeep.dh 658
            self.closeSession()
1845 vikas 659
 
660
    def getTrackLogById(self, id):
661
        """
662
        Parameter
663
         - id
664
        """
665
        try:
666
            return to_t_track_log(get_track_log_by_id(id))
667
        finally:
4323 mandeep.dh 668
            self.closeSession()
1845 vikas 669
 
3293 vikas 670
    def getTrackLogsByAffiliate(self, affiliateId, startDate, endDate):
1845 vikas 671
        """
672
        Parameter
1996 vikas 673
         - affiliate_id
1845 vikas 674
        """
675
        try:
3293 vikas 676
            return [to_t_track_log(track_log) for track_log in get_track_logs_by_affiliate(affiliateId, startDate, endDate)]
1845 vikas 677
        finally:
4323 mandeep.dh 678
            self.closeSession()
1845 vikas 679
 
680
    def getTrackLogsByUser(self, user_id):
681
        """
682
        Parameter
683
         - user_id
684
        """
685
        try:
686
            return [to_t_track_log(track_log) for track_log in get_track_logs_by_user(user_id)]
687
        finally:
4323 mandeep.dh 688
            self.closeSession()
1845 vikas 689
 
1996 vikas 690
    def getTrackLogs(self, affiliateId, userId, event, url):
1845 vikas 691
        """
692
        Parameter
1996 vikas 693
         - affiliateId
694
         - userId
695
         - event
696
         - url
1845 vikas 697
        """
698
        try:
1996 vikas 699
            return [to_t_track_log(track_log) for track_log in get_track_logs(affiliateId, userId, event, url)]
1845 vikas 700
        finally:
4323 mandeep.dh 701
            self.closeSession()
1845 vikas 702
 
1596 ankur.sing 703
    def getUserCount(self, userType):
704
        """
705
        Returns number of registered users.
1612 ankur.sing 706
        If userType = null, then it returns count of all users, including anonymous
707
        If userType = UserType.ANONYMOUS, then it returns count of anonymous users only
708
        If userType = UserType.USER, then it returns count of non-anonymous users only
1596 ankur.sing 709
 
710
        Parameters:
1612 ankur.sing 711
         - userType
1596 ankur.sing 712
        """
1673 ankur.sing 713
        try:
714
            return UserDataAccessors.get_user_count(userType)
715
        finally:
4323 mandeep.dh 716
            self.closeSession()
1673 ankur.sing 717
 
1891 ankur.sing 718
    def getAllUsers(self, userType, startDate, endDate):
1673 ankur.sing 719
        """
720
        Returns list of users of type userType. If userType is null, then returns all the users.
721
 
722
        Parameters:
723
         - userType
724
        """
725
        try:
1891 ankur.sing 726
            users = UserDataAccessors.get_users(userType, startDate, endDate)
1673 ankur.sing 727
            t_users = list()
728
            for user in users:
729
                t_users.append(to_t_user(user))
730
            return t_users
731
        finally:
4323 mandeep.dh 732
            self.closeSession()
1583 varun.gupt 733
 
2981 rajveer 734
    def getMyResearchItems(self, userId):
130 ashish 735
        """
736
        Parameters:
2981 rajveer 737
         - userId
130 ashish 738
        """
766 rajveer 739
        try:
2981 rajveer 740
            return get_my_research_items(userId)
766 rajveer 741
        finally:
4323 mandeep.dh 742
            self.closeSession()
2981 rajveer 743
 
744
    def getBrowseHistoryItems(self, userId):
130 ashish 745
        """
746
        Parameters:
557 chandransh 747
         - userId
130 ashish 748
        """
766 rajveer 749
        try:
2981 rajveer 750
            return get_browse_history_items(userId)
766 rajveer 751
        finally:
4323 mandeep.dh 752
            self.closeSession()
2981 rajveer 753
 
3386 varun.gupt 754
    def getCartsWithCouponCount(self, couponCode):
755
        '''
756
        Parameters:
757
         - couponCode
758
        '''
759
        try:
760
            return get_carts_with_coupon_count(couponCode)
761
        finally:
4323 mandeep.dh 762
            self.closeSession()
3499 mandeep.dh 763
 
764
    def increaseTrustLevel(self, userId, trustLevelDelta):
765
        """
766
        Parameters:
767
         - userId
768
         - trustLevelDelta
769
        """
770
        try:
771
            return increase_trust_level(userId, trustLevelDelta)
772
        finally:
4323 mandeep.dh 773
            self.closeSession()
3554 varun.gupt 774
 
5407 amar.kumar 775
    def getTrustLevel(self, userId):
776
        try:
777
            return get_trust_level(userId)
778
        finally:
779
            self.closeSession()
780
 
3554 varun.gupt 781
    def deleteDiscountsFromCart(self, cartId):
782
        '''
783
        Parameters:
784
         - cartId
785
        '''
786
        try:
787
            return delete_discounts_from_cart(cart_id = cartId)
788
        finally:
4323 mandeep.dh 789
            self.closeSession()
3554 varun.gupt 790
 
791
    def saveDiscounts(self, discounts):
792
        '''
793
        Parameters:
794
         - discounts
795
        '''
796
        try:
797
            return save_discounts(discounts)
798
        finally:
4323 mandeep.dh 799
            self.closeSession()
3499 mandeep.dh 800
 
4668 varun.gupt 801
    def showCODOption(self, cartId, sourceId, pincode):
802
        '''
803
        Parameters:
804
         - cartId
805
         - pincode
806
        '''
807
        try:
808
            return show_cod_option(cartId, sourceId, pincode)
809
        finally:
810
            self.closeSession()
5555 rajveer 811
 
812
 
813
    def addStoreToCart(self, cartId, storeId):
814
        """
815
        Parameters:
816
         - cartId
817
         - storeId
818
        """
819
        try:
820
            return add_store_to_cart(cartId, storeId)
821
        finally:
822
            self.closeSession()
823
 
5623 anupam.sin 824
    def getUserEmails(self, startDate, endDate):
825
        '''
826
        Get email addresses for users activated within a given date range
827
 
828
        Parameters:
829
         - startDate
830
         - endDate
831
        '''
832
        try:
833
            return get_user_emails(to_py_date(startDate), to_py_date(endDate))
834
        finally:
835
            self.closeSession()
6821 amar.kumar 836
 
9791 rajveer 837
    def getProductsAddedToCart(self, startDate, endDate):
6821 amar.kumar 838
        """
9791 rajveer 839
        Returns list of products added to cart from startDate to endDate
6821 amar.kumar 840
        """        
841
        try:
9791 rajveer 842
            return get_products_added_to_cart(startDate, endDate)
6821 amar.kumar 843
        finally:
844
            self.closeSession()
845
 
846
 
9299 kshitij.so 847
    def insureItem(self, itemId, cartId, toInsure, insurerType):
6903 anupam.sin 848
        try:
9299 kshitij.so 849
            return insure_item(itemId, cartId, toInsure, insurerType)
6903 anupam.sin 850
        finally:
851
            self.closeSession()
852
 
853
    def cancelInsurance(self, cartId):
854
        try:
855
            return cancel_insurance(cartId)
856
        finally:
857
            self.closeSession()
858
 
859
    def storeInsuranceSpecificDetails (self, addressId, dob, guardianName):
860
        try:
861
            return store_insurance_specific_details(addressId, dob, guardianName)
862
        finally:
863
            self.closeSession()
864
 
865
    def isInsuranceDetailPresent(self, addressId):
866
        try:
867
            return is_insurance_detail_present(addressId)
868
        finally:
869
            self.closeSession()
11592 amit.gupta 870
 
11980 amit.gupta 871
    def validateCartPlus(self, cartId, sourceId, couponCode):
17859 amit.gupta 872
        try:
873
            return validate_cart_plus(cartId, sourceId, couponCode)
874
        finally:
875
            self.closeSession()
6903 anupam.sin 876
 
17782 amit.gupta 877
    def addItemsToCart(self, cartId, itemQty, couponCode):
878
        try:
879
            return add_items_to_cart(cartId, itemQty, couponCode)
880
        finally:
881
            self.closeSession()
882
 
883
    def validateCartNew(self, cartId, pinCode, sourceId):
17859 amit.gupta 884
        try:
20981 amit.gupta 885
            return validate_cart_new(cartId, pinCode, sourceId)
17859 amit.gupta 886
        finally:
887
            self.closeSession()
17782 amit.gupta 888
 
2981 rajveer 889
    def closeSession(self, ):
890
        CartDataAccessors.close_session()
891
        UserDataAccessors.close_session()
11679 vikram.rag 892
 
893
    def isPrivateDealUser(self,userId):
894
        return is_private_deal_user(userId)
11890 kshitij.so 895
 
896
    def addPrivateDealUser(self,userId):
897
        try:
898
            return add_private_deal_user(userId)
899
        finally:
900
            self.closeSession()
901
 
902
    def changePrivateDealUserStatus(self,userId,isActive):
903
        try:
904
            return change_private_deal_user_status(userId,isActive)
905
        finally:
906
            self.closeSession()
907
 
908
    def getPrivateDealUser(self,userId):
909
        try:
12790 amit.gupta 910
            return to_t_private_deal_user(get_private_deal_user(userId))
11890 kshitij.so 911
        finally:
912
            self.closeSession()
12696 amit.gupta 913
 
914
    def registerCounter(self, tCounter, userId):
915
        try:
916
            return register_counter(tCounter, userId)
917
        finally:
918
            self.closeSession()
12722 amit.gupta 919
 
920
    def searchCounter(self, type1, searchString):
921
        try:
922
            return [to_t_counter(counter) for counter in search_counter(type1, searchString)]
923
        finally:
924
            self.closeSession()
18977 amit.gupta 925
 
926
    def getCounterByUserId(self, userId):
927
        return to_t_counter(get_counter_by_user_id(userId))
12722 amit.gupta 928
 
929
    def getAllUsersByCounter(self, counterid):
930
        try:
931
            return [to_t_user(user) for user in get_all_users_by_counter(counterid)]
932
        finally:
933
            self.closeSession()
15251 manish.sha 934
 
935
    def getActiveAccessTokenForUser(self, userId, source):
936
        try:
937
            return get_active_access_token_for_user(userId, source)
938
        finally:
939
            self.closeSession()
940
 
941
    def validateAccessToken(self, accessToken):
942
        try:
943
            return validate_access_token(accessToken)
944
        finally:
945
            self.closeSession()
946
 
18634 manish.sha 947
    def isAddressEditableForCounter(self, userId):
18530 manish.sha 948
        try:
18634 manish.sha 949
            return is_address_editable_for_counter(userId)
18530 manish.sha 950
        except:
18735 manish.sha 951
            return True
18530 manish.sha 952
        finally:
953
            self.closeSession()
954
 
955
    def getBillingAddressForUser(self, userId):
956
        try:
18744 manish.sha 957
            address, taxInvoiceMap, creditAvailableMap = get_billing_address_for_user(userId)
958
            if address is not None:
959
                return to_t_address(address, taxInvoiceMap, creditAvailableMap)
960
            else:
961
                return None
18530 manish.sha 962
        finally:
963
            self.closeSession()
964
 
18590 manish.sha 965
    def isCreditorAssigned(self, userId):
966
        try:
967
            return is_creditor_assigned(userId)
968
        finally:
969
            self.closeSession()
970
 
18735 manish.sha 971
    def isTaxInvoiceEnabledUser(self, userId):
972
        try:
973
            return is_tax_invoice_enabled_user(userId)
974
        finally:
975
            self.closeSession()
976
 
18764 kshitij.so 977
    def getCartByValue(self,cartIds):
978
        try:
979
            return get_cart_by_value(cartIds)
980
        finally:
981
            self.closeSession()
19182 amit.gupta 982
 
983
    def taxInvoiceAvailable(self,address_id):
984
        try:
985
            return tax_invoice_available(address_id)
986
        finally:
987
            self.closeSession()
18764 kshitij.so 988
 
3376 rajveer 989
    def isAlive(self, ):
990
        """
991
        For checking weather service is active alive or not. It also checks connectivity with database
992
        """
993
        try:
994
            return is_alive()
995
        finally:
19889 manas 996
            self.closeSession()
997
 
998
    def getCounterName(self,userIds):
999
        try:
1000
            return get_counter_name(userIds)
1001
        finally:
20873 kshitij.so 1002
            self.closeSession()
1003
 
1004
    def setWalletAmountInCart(self, cartId, wallet_amount):
1005
        try:
1006
            return set_wallet_amount_in_cart(cartId, wallet_amount)
1007
        finally:
22358 ashik.ali 1008
            self.closeSession()
1009
 
1010
 
1011
    def updateAddress(self, address):
1012
        try:
1013
            return update_address(address)
1014
        finally:
1015
            self.closeSession()
1016