Subversion Repositories SmartDukaan

Rev

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

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