Subversion Repositories SmartDukaan

Rev

Rev 11890 | Rev 12696 | 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, \
11890 kshitij.so 16
    to_t_tracker, to_t_track_log,to_t_private_deal
11596 amit.gupta 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, \
11890 kshitij.so 34
    is_private_deal_user,add_private_deal_user,change_private_deal_user_status,get_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:
11980 amit.gupta 396
            return validate_cart(cartId, sourceId, None)
766 rajveer 397
        finally:
4323 mandeep.dh 398
            self.closeSession()
766 rajveer 399
 
11980 amit.gupta 400
    def validateCartWithDealerCoupon(self, cartId, sourceId, couponCode):
401
        """
402
        Validates that:
403
        1. The checkout timestamp is greater than the updatedOn timestamp.
404
        2. All of the lines in the cart are active items.
405
        3. The estimate for any of the lines in cart doesn't change.
406
        4. If a Coupon Code is attached, it gets applied and discounted price is computed
407
        If first three are true, returns empty string; else returns appropriate message.
408
 
409
        Parameters:
410
         - cartId
411
        """
412
        try:
413
            return validate_cart(cartId, sourceId, couponCode)
414
        finally:
415
            self.closeSession()
416
 
557 chandransh 417
    def mergeCart(self, fromCartId, toCartId):
513 rajveer 418
        """
419
        Parameters:
557 chandransh 420
         - fromCartId
421
         - toCartId
513 rajveer 422
        """
766 rajveer 423
        try:
424
            merge_cart(fromCartId, toCartId)
425
        finally:
4323 mandeep.dh 426
            self.closeSession()
766 rajveer 427
 
691 chandransh 428
    def checkOut(self, cartId):
429
        """
430
        Sets the checkedOutOn timestamp of the cart. Raises an exception if the specified cart can't be found.
431
 
432
        Parameters:
433
         - cartId
434
        """
766 rajveer 435
        try:
436
            return check_out(cartId)
437
        finally:
4323 mandeep.dh 438
            self.closeSession()
766 rajveer 439
 
691 chandransh 440
    def resetCart(self, cartId, items):
441
        """
442
        The second parameter is a map of item ids and their quantities which have been successfully processed.
443
        This methods removes the specified quantiry of the specified item from the cart.
444
 
445
        Parameters:
446
         - cartId
447
         - items
448
        """
766 rajveer 449
        try:
450
            return reset_cart(cartId, items)
451
        finally:
4323 mandeep.dh 452
            self.closeSession()
772 rajveer 453
 
454
    #Widget related methods
455
    def updateMyResearch(self, userId, itemId):
456
        """
457
        Parameters:
458
         - user_id
459
         - item_id
460
        """
461
        try:
462
            return update_my_research(userId, itemId)
463
        finally:
4323 mandeep.dh 464
            self.closeSession()
772 rajveer 465
 
466
    def deleteItemFromMyResearch(self, userId, itemId):
467
        """
468
        Parameters:
469
         - user_id
470
         - item_id
471
        """
472
        try:
473
            return delete_item_from_my_research(userId, itemId)
474
        finally:
4323 mandeep.dh 475
            self.closeSession()
766 rajveer 476
 
772 rajveer 477
    def updateBrowseHistory(self, userId, itemId):
478
        """
479
        Parameters: 
480
        - user_id
481
        - item_id
482
        """
483
        try:
484
            update_browse_history(userId, itemId)
485
        finally:
4323 mandeep.dh 486
            self.closeSession()
772 rajveer 487
 
488
    def mergeBrowseHistory(self, fromUserId, toUserId):
489
        """
490
        Parameters:
491
         - user_id
492
        """
2981 rajveer 493
        pass
772 rajveer 494
 
1273 varun.gupt 495
    def saveUserCommunication(self, userId, email, communicationType, orderId, awb, product, subject, message):
496
        """
497
        Parameters:
498
         - userId
499
         - email
500
         - communicationType
501
         - orderId
502
         - awb
503
         - product
504
         - subject
505
         - message
506
        """
507
        try:
508
            return create_user_communication(userId, email, communicationType, orderId, awb, product, subject, message)
509
        finally:
4323 mandeep.dh 510
            self.closeSession()
1273 varun.gupt 511
 
1583 varun.gupt 512
    def getUserCommunicationById(self, id):
513
        """
514
        Parameters:
515
         - id
516
        """
517
        try:
518
            return to_t_user_communication(get_user_communication_by_id(id))
519
        finally:
4323 mandeep.dh 520
            self.closeSession()
1583 varun.gupt 521
 
522
    def getUserCommunicationByUser(self, userId):
523
        """
524
        Parameters:
525
         - userId
526
        """
527
        try:
528
            return [to_t_user_communication(user_communication) for user_communication in get_user_communication_by_user(userId)]
529
        finally:
4323 mandeep.dh 530
            self.closeSession()
1583 varun.gupt 531
 
532
    def getAllUserCommunications(self):
533
        try:
534
            return [to_t_user_communication(user_communication) for user_communication in get_all_user_communications()]
535
        finally:
4323 mandeep.dh 536
            self.closeSession()
5407 amar.kumar 537
 
538
    def removeUserCommunication(self, id):
539
        try:
540
            remove_user_communication(id)
541
        finally:
542
            self.closeSession()
1596 ankur.sing 543
 
1859 vikas 544
    def createMasterAffiliate(self, name, addedOn):
1845 vikas 545
        """
546
        Parameters
547
         - name
1859 vikas 548
         - addedOn
1845 vikas 549
        """
550
        try:
1859 vikas 551
            return to_t_master_affiliate(create_master_affiliate(name, addedOn))
1845 vikas 552
        finally:
4323 mandeep.dh 553
            self.closeSession()
1845 vikas 554
 
1899 vikas 555
    def getAllMasterAffiliates(self):
556
        try:
557
            return [to_t_master_affiliate(masterAffiliate) for masterAffiliate in get_all_master_affiliates()]
558
        finally:
4323 mandeep.dh 559
            self.closeSession()
1899 vikas 560
 
1845 vikas 561
    def getMasterAffiliateById(self, id):
562
        """
563
        Parameters
564
         - id
565
        """
566
        try:
567
            return to_t_master_affiliate(get_master_affiliate_by_id(id))
568
        finally:
4323 mandeep.dh 569
            self.closeSession()
1845 vikas 570
 
571
    def getMasterAffiliateByName(self, name):
572
        """
573
        Parameters
574
         - id
575
        """
576
        try:
577
            return to_t_master_affiliate(get_master_affiliate_by_name(name))
578
        finally:
4323 mandeep.dh 579
            self.closeSession()
1845 vikas 580
 
1859 vikas 581
    def createAffiliate(self, name, url, masterAffiliateId, addedOn):
1845 vikas 582
        """
583
        Parameters
584
         - name
585
         - url
1859 vikas 586
         - masterAffiliateId
587
         - addedOn
1845 vikas 588
        """
589
        try:
1859 vikas 590
            return to_t_affiliate(create_affiliate(name, url, masterAffiliateId, addedOn))
1845 vikas 591
        finally:
4323 mandeep.dh 592
            self.closeSession()
1845 vikas 593
 
594
    def getAffiliateById(self, id):
595
        """
596
        Parameters
597
         - id
598
        """
599
        try:
600
            return to_t_affiliate(get_affiliate_by_id(id))
601
        finally:
4323 mandeep.dh 602
            self.closeSession()
1845 vikas 603
 
604
    def getAffiliateByName(self, name):
605
        """
606
        Parameters
607
         - name
608
        """
609
        try:
610
            return to_t_affiliate(get_affiliate_by_name(name))
611
        finally:
4323 mandeep.dh 612
            self.closeSession()
1845 vikas 613
 
1996 vikas 614
    def getAffiliatesByMasterAffiliate(self, masterAffiliateId):
1845 vikas 615
        """
616
        Parameters
617
         - master_id
618
        """
619
        try:
1996 vikas 620
            return [to_t_affiliate(affiliate) for affiliate in get_affiliates_by_master_affiliate(masterAffiliateId)]
1845 vikas 621
        finally:
4323 mandeep.dh 622
            self.closeSession()
1845 vikas 623
 
1996 vikas 624
    def getTrackerById(self, trackerId):
1845 vikas 625
        """
626
        Parameters
1996 vikas 627
         - trackerId
1845 vikas 628
        """
629
        try:
1996 vikas 630
            return to_t_tracker(get_tracker_by_id(trackerId))
1845 vikas 631
        finally:
4323 mandeep.dh 632
            self.closeSession()
1996 vikas 633
 
634
    def addTrackLog(self, affiliateId, userId, event, url, data, addedOn):
1845 vikas 635
        """
1996 vikas 636
        Parameter
1845 vikas 637
         - affiliateId
638
         - userId
639
         - event
640
         - url
641
         - data
1859 vikas 642
         - addedOn
1845 vikas 643
        """
644
        try:
1996 vikas 645
            return add_track_log(affiliateId, userId, event, url, data, addedOn)
1845 vikas 646
        finally:
4323 mandeep.dh 647
            self.closeSession()
1845 vikas 648
 
649
    def getTrackLogById(self, id):
650
        """
651
        Parameter
652
         - id
653
        """
654
        try:
655
            return to_t_track_log(get_track_log_by_id(id))
656
        finally:
4323 mandeep.dh 657
            self.closeSession()
1845 vikas 658
 
3293 vikas 659
    def getTrackLogsByAffiliate(self, affiliateId, startDate, endDate):
1845 vikas 660
        """
661
        Parameter
1996 vikas 662
         - affiliate_id
1845 vikas 663
        """
664
        try:
3293 vikas 665
            return [to_t_track_log(track_log) for track_log in get_track_logs_by_affiliate(affiliateId, startDate, endDate)]
1845 vikas 666
        finally:
4323 mandeep.dh 667
            self.closeSession()
1845 vikas 668
 
669
    def getTrackLogsByUser(self, user_id):
670
        """
671
        Parameter
672
         - user_id
673
        """
674
        try:
675
            return [to_t_track_log(track_log) for track_log in get_track_logs_by_user(user_id)]
676
        finally:
4323 mandeep.dh 677
            self.closeSession()
1845 vikas 678
 
1996 vikas 679
    def getTrackLogs(self, affiliateId, userId, event, url):
1845 vikas 680
        """
681
        Parameter
1996 vikas 682
         - affiliateId
683
         - userId
684
         - event
685
         - url
1845 vikas 686
        """
687
        try:
1996 vikas 688
            return [to_t_track_log(track_log) for track_log in get_track_logs(affiliateId, userId, event, url)]
1845 vikas 689
        finally:
4323 mandeep.dh 690
            self.closeSession()
1845 vikas 691
 
1596 ankur.sing 692
    def getUserCount(self, userType):
693
        """
694
        Returns number of registered users.
1612 ankur.sing 695
        If userType = null, then it returns count of all users, including anonymous
696
        If userType = UserType.ANONYMOUS, then it returns count of anonymous users only
697
        If userType = UserType.USER, then it returns count of non-anonymous users only
1596 ankur.sing 698
 
699
        Parameters:
1612 ankur.sing 700
         - userType
1596 ankur.sing 701
        """
1673 ankur.sing 702
        try:
703
            return UserDataAccessors.get_user_count(userType)
704
        finally:
4323 mandeep.dh 705
            self.closeSession()
1673 ankur.sing 706
 
1891 ankur.sing 707
    def getAllUsers(self, userType, startDate, endDate):
1673 ankur.sing 708
        """
709
        Returns list of users of type userType. If userType is null, then returns all the users.
710
 
711
        Parameters:
712
         - userType
713
        """
714
        try:
1891 ankur.sing 715
            users = UserDataAccessors.get_users(userType, startDate, endDate)
1673 ankur.sing 716
            t_users = list()
717
            for user in users:
718
                t_users.append(to_t_user(user))
719
            return t_users
720
        finally:
4323 mandeep.dh 721
            self.closeSession()
1583 varun.gupt 722
 
2981 rajveer 723
    def getMyResearchItems(self, userId):
130 ashish 724
        """
725
        Parameters:
2981 rajveer 726
         - userId
130 ashish 727
        """
766 rajveer 728
        try:
2981 rajveer 729
            return get_my_research_items(userId)
766 rajveer 730
        finally:
4323 mandeep.dh 731
            self.closeSession()
2981 rajveer 732
 
733
    def getBrowseHistoryItems(self, userId):
130 ashish 734
        """
735
        Parameters:
557 chandransh 736
         - userId
130 ashish 737
        """
766 rajveer 738
        try:
2981 rajveer 739
            return get_browse_history_items(userId)
766 rajveer 740
        finally:
4323 mandeep.dh 741
            self.closeSession()
2981 rajveer 742
 
3386 varun.gupt 743
    def getCartsWithCouponCount(self, couponCode):
744
        '''
745
        Parameters:
746
         - couponCode
747
        '''
748
        try:
749
            return get_carts_with_coupon_count(couponCode)
750
        finally:
4323 mandeep.dh 751
            self.closeSession()
3499 mandeep.dh 752
 
753
    def increaseTrustLevel(self, userId, trustLevelDelta):
754
        """
755
        Parameters:
756
         - userId
757
         - trustLevelDelta
758
        """
759
        try:
760
            return increase_trust_level(userId, trustLevelDelta)
761
        finally:
4323 mandeep.dh 762
            self.closeSession()
3554 varun.gupt 763
 
5407 amar.kumar 764
    def getTrustLevel(self, userId):
765
        try:
766
            return get_trust_level(userId)
767
        finally:
768
            self.closeSession()
769
 
3554 varun.gupt 770
    def deleteDiscountsFromCart(self, cartId):
771
        '''
772
        Parameters:
773
         - cartId
774
        '''
775
        try:
776
            return delete_discounts_from_cart(cart_id = cartId)
777
        finally:
4323 mandeep.dh 778
            self.closeSession()
3554 varun.gupt 779
 
780
    def saveDiscounts(self, discounts):
781
        '''
782
        Parameters:
783
         - discounts
784
        '''
785
        try:
786
            return save_discounts(discounts)
787
        finally:
4323 mandeep.dh 788
            self.closeSession()
3499 mandeep.dh 789
 
4668 varun.gupt 790
    def showCODOption(self, cartId, sourceId, pincode):
791
        '''
792
        Parameters:
793
         - cartId
794
         - pincode
795
        '''
796
        try:
797
            return show_cod_option(cartId, sourceId, pincode)
798
        finally:
799
            self.closeSession()
5555 rajveer 800
 
801
 
802
    def addStoreToCart(self, cartId, storeId):
803
        """
804
        Parameters:
805
         - cartId
806
         - storeId
807
        """
808
        try:
809
            return add_store_to_cart(cartId, storeId)
810
        finally:
811
            self.closeSession()
812
 
5623 anupam.sin 813
    def getUserEmails(self, startDate, endDate):
814
        '''
815
        Get email addresses for users activated within a given date range
816
 
817
        Parameters:
818
         - startDate
819
         - endDate
820
        '''
821
        try:
822
            return get_user_emails(to_py_date(startDate), to_py_date(endDate))
823
        finally:
824
            self.closeSession()
6821 amar.kumar 825
 
9791 rajveer 826
    def getProductsAddedToCart(self, startDate, endDate):
6821 amar.kumar 827
        """
9791 rajveer 828
        Returns list of products added to cart from startDate to endDate
6821 amar.kumar 829
        """        
830
        try:
9791 rajveer 831
            return get_products_added_to_cart(startDate, endDate)
6821 amar.kumar 832
        finally:
833
            self.closeSession()
834
 
835
 
9299 kshitij.so 836
    def insureItem(self, itemId, cartId, toInsure, insurerType):
6903 anupam.sin 837
        try:
9299 kshitij.so 838
            return insure_item(itemId, cartId, toInsure, insurerType)
6903 anupam.sin 839
        finally:
840
            self.closeSession()
841
 
842
    def cancelInsurance(self, cartId):
843
        try:
844
            return cancel_insurance(cartId)
845
        finally:
846
            self.closeSession()
847
 
848
    def storeInsuranceSpecificDetails (self, addressId, dob, guardianName):
849
        try:
850
            return store_insurance_specific_details(addressId, dob, guardianName)
851
        finally:
852
            self.closeSession()
853
 
854
    def isInsuranceDetailPresent(self, addressId):
855
        try:
856
            return is_insurance_detail_present(addressId)
857
        finally:
858
            self.closeSession()
11592 amit.gupta 859
 
11980 amit.gupta 860
    def validateCartPlus(self, cartId, sourceId, couponCode):
861
        return validate_cart_plus(cartId, sourceId, couponCode)
6903 anupam.sin 862
 
2981 rajveer 863
    def closeSession(self, ):
864
        CartDataAccessors.close_session()
865
        UserDataAccessors.close_session()
11679 vikram.rag 866
 
867
    def isPrivateDealUser(self,userId):
868
        return is_private_deal_user(userId)
11890 kshitij.so 869
 
870
    def addPrivateDealUser(self,userId):
871
        try:
872
            return add_private_deal_user(userId)
873
        finally:
874
            self.closeSession()
875
 
876
    def changePrivateDealUserStatus(self,userId,isActive):
877
        try:
878
            return change_private_deal_user_status(userId,isActive)
879
        finally:
880
            self.closeSession()
881
 
882
    def getPrivateDealUser(self,userId):
883
        try:
884
            return to_t_private_deal(get_private_deal_user(userId))
885
        finally:
886
            self.closeSession()
3376 rajveer 887
 
888
    def isAlive(self, ):
889
        """
890
        For checking weather service is active alive or not. It also checks connectivity with database
891
        """
892
        try:
893
            return is_alive()
894
        finally:
4323 mandeep.dh 895
            self.closeSession()
11890 kshitij.so 896
 
772 rajveer 897