Subversion Repositories SmartDukaan

Rev

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