Subversion Repositories SmartDukaan

Rev

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