Subversion Repositories SmartDukaan

Rev

Rev 2035 | Rev 2717 | 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
 
690 chandransh 444
    def createOrders(self, cartId):
130 ashish 445
        """
446
        Parameters:
557 chandransh 447
         - cartId
130 ashish 448
        """
766 rajveer 449
        try:
450
            return commit_cart(cartId)
451
        finally:
452
            CartDataAccessors.close_session()
1466 ankur.sing 453
 
557 chandransh 454
    def validateCart(self, cartId):
130 ashish 455
        """
1466 ankur.sing 456
        Validates that:
457
        1. The checkout timestamp is greater than the updatedOn timestamp.
458
        2. All of the lines in the cart are active items.
459
        3. The estimate for any of the lines in cart doesn't change.
1976 varun.gupt 460
        4. If a Coupon Code is attached, it gets applied and discounted price is computed
461
        If first three are true, returns empty string; else returns appropriate message.
1466 ankur.sing 462
 
130 ashish 463
        Parameters:
557 chandransh 464
         - cartId
130 ashish 465
        """
766 rajveer 466
        try:
467
            return validate_cart(cartId)
468
        finally:
469
            CartDataAccessors.close_session()
470
 
557 chandransh 471
    def mergeCart(self, fromCartId, toCartId):
513 rajveer 472
        """
473
        Parameters:
557 chandransh 474
         - fromCartId
475
         - toCartId
513 rajveer 476
        """
766 rajveer 477
        try:
478
            merge_cart(fromCartId, toCartId)
479
        finally:
480
            CartDataAccessors.close_session()
481
 
691 chandransh 482
    def checkOut(self, cartId):
483
        """
484
        Sets the checkedOutOn timestamp of the cart. Raises an exception if the specified cart can't be found.
485
 
486
        Parameters:
487
         - cartId
488
        """
766 rajveer 489
        try:
490
            return check_out(cartId)
491
        finally:
492
            CartDataAccessors.close_session()
493
 
691 chandransh 494
    def resetCart(self, cartId, items):
495
        """
496
        The second parameter is a map of item ids and their quantities which have been successfully processed.
497
        This methods removes the specified quantiry of the specified item from the cart.
498
 
499
        Parameters:
500
         - cartId
501
         - items
502
        """
766 rajveer 503
        try:
504
            return reset_cart(cartId, items)
505
        finally:
506
            CartDataAccessors.close_session()
772 rajveer 507
 
508
    #Widget related methods
509
    def getMyResearch(self, userId):
510
        """
511
        Parameters:
512
         - user_id
513
        """
514
        try:
515
            return to_t_widget(get_my_research(userId))
516
        finally:
517
            WidgetDataAccessor.close_session()
518
 
519
    def updateMyResearch(self, userId, itemId):
520
        """
521
        Parameters:
522
         - user_id
523
         - item_id
524
        """
525
        try:
526
            return update_my_research(userId, itemId)
527
        finally:
528
            WidgetDataAccessor.close_session()
529
 
530
    def deleteItemFromMyResearch(self, userId, itemId):
531
        """
532
        Parameters:
533
         - user_id
534
         - item_id
535
        """
536
        try:
537
            return delete_item_from_my_research(userId, itemId)
538
        finally:
539
            WidgetDataAccessor.close_session()
766 rajveer 540
 
772 rajveer 541
    def updateBrowseHistory(self, userId, itemId):
542
        """
543
        Parameters: 
544
        - user_id
545
        - item_id
546
        """
547
        try:
548
            update_browse_history(userId, itemId)
549
        finally:
550
            WidgetDataAccessor.close_session()
551
 
552
    def getBrowseHistory(self, userId):
553
        """
554
        Parameters:
555
         - user_id
556
        """
557
        try:
558
            return to_t_widget(get_browse_history(userId))
559
        finally:
560
            WidgetDataAccessor.close_session()
561
 
562
    def mergeBrowseHistory(self, fromUserId, toUserId):
563
        """
564
        Parameters:
565
         - user_id
566
        """
567
        try:
568
            return merge_browse_history(fromUserId, toUserId)
569
        finally:
570
            WidgetDataAccessor.close_session()
571
 
1273 varun.gupt 572
    def saveUserCommunication(self, userId, email, communicationType, orderId, awb, product, subject, message):
573
        """
574
        Parameters:
575
         - userId
576
         - email
577
         - communicationType
578
         - orderId
579
         - awb
580
         - product
581
         - subject
582
         - message
583
        """
584
        try:
585
            return create_user_communication(userId, email, communicationType, orderId, awb, product, subject, message)
586
        finally:
1605 varun.gupt 587
            UserDataAccessors.close_session()
1273 varun.gupt 588
 
1583 varun.gupt 589
    def getUserCommunicationById(self, id):
590
        """
591
        Parameters:
592
         - id
593
        """
594
        try:
595
            return to_t_user_communication(get_user_communication_by_id(id))
596
        finally:
1605 varun.gupt 597
            UserDataAccessors.close_session()
1583 varun.gupt 598
 
599
    def getUserCommunicationByUser(self, userId):
600
        """
601
        Parameters:
602
         - userId
603
        """
604
        try:
605
            return [to_t_user_communication(user_communication) for user_communication in get_user_communication_by_user(userId)]
606
        finally:
1605 varun.gupt 607
            UserDataAccessors.close_session()
1583 varun.gupt 608
 
609
    def getAllUserCommunications(self):
610
        try:
611
            return [to_t_user_communication(user_communication) for user_communication in get_all_user_communications()]
612
        finally:
1605 varun.gupt 613
            UserDataAccessors.close_session()
1596 ankur.sing 614
 
1859 vikas 615
    def createMasterAffiliate(self, name, addedOn):
1845 vikas 616
        """
617
        Parameters
618
         - name
1859 vikas 619
         - addedOn
1845 vikas 620
        """
621
        try:
1859 vikas 622
            return to_t_master_affiliate(create_master_affiliate(name, addedOn))
1845 vikas 623
        finally:
624
            UserDataAccessors.close_session()
625
 
1899 vikas 626
    def getAllMasterAffiliates(self):
627
        try:
628
            return [to_t_master_affiliate(masterAffiliate) for masterAffiliate in get_all_master_affiliates()]
629
        finally:
630
            UserDataAccessors.close_session()
631
 
1845 vikas 632
    def getMasterAffiliateById(self, id):
633
        """
634
        Parameters
635
         - id
636
        """
637
        try:
638
            return to_t_master_affiliate(get_master_affiliate_by_id(id))
639
        finally:
640
            UserDataAccessors.close_session()
641
 
642
    def getMasterAffiliateByName(self, name):
643
        """
644
        Parameters
645
         - id
646
        """
647
        try:
648
            return to_t_master_affiliate(get_master_affiliate_by_name(name))
649
        finally:
650
            UserDataAccessors.close_session()
651
 
1859 vikas 652
    def createAffiliate(self, name, url, masterAffiliateId, addedOn):
1845 vikas 653
        """
654
        Parameters
655
         - name
656
         - url
1859 vikas 657
         - masterAffiliateId
658
         - addedOn
1845 vikas 659
        """
660
        try:
1859 vikas 661
            return to_t_affiliate(create_affiliate(name, url, masterAffiliateId, addedOn))
1845 vikas 662
        finally:
663
            UserDataAccessors.close_session()
664
 
665
    def getAffiliateById(self, id):
666
        """
667
        Parameters
668
         - id
669
        """
670
        try:
671
            return to_t_affiliate(get_affiliate_by_id(id))
672
        finally:
673
            UserDataAccessors.close_session()
674
 
675
    def getAffiliateByName(self, name):
676
        """
677
        Parameters
678
         - name
679
        """
680
        try:
681
            return to_t_affiliate(get_affiliate_by_name(name))
682
        finally:
683
            UserDataAccessors.close_session()
684
 
1996 vikas 685
    def getAffiliatesByMasterAffiliate(self, masterAffiliateId):
1845 vikas 686
        """
687
        Parameters
688
         - master_id
689
        """
690
        try:
1996 vikas 691
            return [to_t_affiliate(affiliate) for affiliate in get_affiliates_by_master_affiliate(masterAffiliateId)]
1845 vikas 692
        finally:
693
            UserDataAccessors.close_session()
694
 
1996 vikas 695
    def getTrackerById(self, trackerId):
1845 vikas 696
        """
697
        Parameters
1996 vikas 698
         - trackerId
1845 vikas 699
        """
700
        try:
1996 vikas 701
            return to_t_tracker(get_tracker_by_id(trackerId))
1845 vikas 702
        finally:
703
            UserDataAccessors.close_session()
1996 vikas 704
 
705
    def addTrackLog(self, affiliateId, userId, event, url, data, addedOn):
1845 vikas 706
        """
1996 vikas 707
        Parameter
1845 vikas 708
         - affiliateId
709
         - userId
710
         - event
711
         - url
712
         - data
1859 vikas 713
         - addedOn
1845 vikas 714
        """
715
        try:
1996 vikas 716
            return add_track_log(affiliateId, userId, event, url, data, addedOn)
1845 vikas 717
        finally:
718
            UserDataAccessors.close_session()
719
 
720
    def getTrackLogById(self, id):
721
        """
722
        Parameter
723
         - id
724
        """
725
        try:
726
            return to_t_track_log(get_track_log_by_id(id))
727
        finally:
728
            UserDataAccessors.close_session()
729
 
1996 vikas 730
    def getTrackLogsByAffiliate(self, affiliateId):
1845 vikas 731
        """
732
        Parameter
1996 vikas 733
         - affiliate_id
1845 vikas 734
        """
735
        try:
1996 vikas 736
            return [to_t_track_log(track_log) for track_log in get_track_logs_by_affiliate(affiliateId)]
1845 vikas 737
        finally:
738
            UserDataAccessors.close_session()
739
 
740
    def getTrackLogsByUser(self, user_id):
741
        """
742
        Parameter
743
         - user_id
744
        """
745
        try:
746
            return [to_t_track_log(track_log) for track_log in get_track_logs_by_user(user_id)]
747
        finally:
748
            UserDataAccessors.close_session()
749
 
1996 vikas 750
    def getTrackLogs(self, affiliateId, userId, event, url):
1845 vikas 751
        """
752
        Parameter
1996 vikas 753
         - affiliateId
754
         - userId
755
         - event
756
         - url
1845 vikas 757
        """
758
        try:
1996 vikas 759
            return [to_t_track_log(track_log) for track_log in get_track_logs(affiliateId, userId, event, url)]
1845 vikas 760
        finally:
761
            UserDataAccessors.close_session()
762
 
1596 ankur.sing 763
    def getUserCount(self, userType):
764
        """
765
        Returns number of registered users.
1612 ankur.sing 766
        If userType = null, then it returns count of all users, including anonymous
767
        If userType = UserType.ANONYMOUS, then it returns count of anonymous users only
768
        If userType = UserType.USER, then it returns count of non-anonymous users only
1596 ankur.sing 769
 
770
        Parameters:
1612 ankur.sing 771
         - userType
1596 ankur.sing 772
        """
1673 ankur.sing 773
        try:
774
            return UserDataAccessors.get_user_count(userType)
775
        finally:
776
            UserDataAccessors.close_session()
777
 
1891 ankur.sing 778
    def getAllUsers(self, userType, startDate, endDate):
1673 ankur.sing 779
        """
780
        Returns list of users of type userType. If userType is null, then returns all the users.
781
 
782
        Parameters:
783
         - userType
784
        """
785
        try:
1891 ankur.sing 786
            users = UserDataAccessors.get_users(userType, startDate, endDate)
1673 ankur.sing 787
            t_users = list()
788
            for user in users:
789
                t_users.append(to_t_user(user))
790
            return t_users
791
        finally:
792
            UserDataAccessors.close_session()
1583 varun.gupt 793
 
2641 varun.gupt 794
    def putUserNote(self, userId, entityId, slideId, note):
795
        """
796
        Saves user's note for a particular slide of an entity
797
 
798
        Parameters:
799
        - userId
800
        - entityId
801
        - slideId
802
        - note
803
        """
804
        try:
805
            put_user_note(userId, entityId, slideId, note)
806
        finally:
807
            UserDataAccessors.close_session()
808
 
809
    def getUserNotes(self, userId, entityId):
810
        """
811
        Retrieves user's notes associated with an entity
812
 
813
        Parameters:
814
        - userId
815
        - entityId
816
        """
817
        try:
818
            return [to_t_user_note(user_note) for user_note in get_user_notes(userId, entityId)]
819
        finally:
820
            UserDataAccessors.close_session()
821
 
772 rajveer 822
    def closeSession(self, ):
823
        CartDataAccessors.close_session()
824
        UserDataAccessors.close_session()
825
        WidgetDataAccessor.close_session()
1596 ankur.sing 826
 
772 rajveer 827
 
828
    '''        
557 chandransh 829
    def addWidget(self, widget):
130 ashish 830
        """
831
        Parameters:
557 chandransh 832
         - widget
130 ashish 833
        """
766 rajveer 834
        try:
835
            add_widget(widget)
836
        finally:
837
            WidgetDataAccessor.close_session()
130 ashish 838
 
557 chandransh 839
    def addItemToWidget(self, widget_id, items):
130 ashish 840
        """
841
        Parameters:
557 chandransh 842
         - widget_id
843
         - items
130 ashish 844
        """
766 rajveer 845
        try:
846
            add_items_to_widget(widget_id, items)
847
        finally:
848
            WidgetDataAccessor.close_session()
849
 
557 chandransh 850
    def updateWidget(self, widgetId, enable):
130 ashish 851
        """
852
        Parameters:
557 chandransh 853
         - widgetId
854
         - enable
130 ashish 855
        """
766 rajveer 856
        try:
857
            update_widget(widgetId, enable)
858
        finally:
859
            WidgetDataAccessor.close_session()
860
 
557 chandransh 861
    def updateWidgetItem(self, widgetId, enable):
130 ashish 862
        """
863
        Parameters:
557 chandransh 864
         - widgetId
865
         - enable
130 ashish 866
        """
766 rajveer 867
        try:
868
            update_widget(widgetId, enable)
869
        finally:
870
            WidgetDataAccessor.close_session()
871
 
557 chandransh 872
    def deleteItemFromWidget(self, widget_id, item_id):
873
        """
874
        Parameters:
875
         - widget_id
876
         - item_id
877
        """
766 rajveer 878
        try:
879
            return delete_item_from_widget(widget_id, item_id)
880
        finally:
881
            WidgetDataAccessor.close_session()
882
 
557 chandransh 883
    def getWidget(self, type, userId, onlyEnabled):
130 ashish 884
        """
885
        Parameters:
557 chandransh 886
         - type
887
         - userId
888
         - onlyEnabled
130 ashish 889
        """
766 rajveer 890
        try:
891
            widget = get_widget_by_type(type, userId, onlyEnabled)
892
            return to_t_widget(widget)
893
        finally:
894
            WidgetDataAccessor.close_session()
895
 
557 chandransh 896
    def updateRatings(self, item_id, type, rating, user_id):
130 ashish 897
        """
898
        Parameters:
557 chandransh 899
        - item_id
900
        - type
901
        - rating
902
        - user_id
130 ashish 903
        """
766 rajveer 904
        try:
905
            update_ratings(user_id, item_id, rating, type)
906
        finally:
907
            WidgetDataAccessor.close_session()
557 chandransh 908
 
909
    def getRatings(self, item_id, user_id):
910
        """
911
        Parameters:
912
        - item_id
913
        - user_id
914
        """
766 rajveer 915
        try:
916
            all_ratings, user_ratings = get_ratings(user_id, item_id)
917
            return to_t_ratings(user_ratings, all_ratings, item_id, user_id)
918
        finally:
919
            WidgetDataAccessor.close_session()
920
 
772 rajveer 921
    '''
922