Subversion Repositories SmartDukaan

Rev

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