Subversion Repositories SmartDukaan

Rev

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