Subversion Repositories SmartDukaan

Rev

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