Subversion Repositories SmartDukaan

Rev

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