Subversion Repositories SmartDukaan

Rev

Rev 19889 | Rev 20981 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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