Subversion Repositories SmartDukaan

Rev

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