Subversion Repositories SmartDukaan

Rev

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