Subversion Repositories SmartDukaan

Rev

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