Subversion Repositories SmartDukaan

Rev

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