Subversion Repositories SmartDukaan

Rev

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