Subversion Repositories SmartDukaan

Rev

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