Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
122 ashish 1
'''
2
Created on 27-Apr-2010
3
 
4
@author: ashish
5
'''
6
from shop2020.model.v1.catalog.impl import DataService
7
from shop2020.utils.Utils import log_entry
8
from shop2020.model.v1.catalog.impl.DataAcessors import add_item, add_warehouse,\
9
    update_inventory, retire_warehouse, retire_item, change_item_status,\
635 rajveer 10
    get_item, get_all_items, get_all_items_by_status, get_item_inventoy,\
643 chandransh 11
    get_item_availability_for_warehouse, get_item_availability_for_location, get_all_warehouses_by_status,\
122 ashish 12
    get_Warehouse, get_all_warehouses_for_item, get_all_items_for_warehouse,\
766 rajveer 13
    update_item, start_item_on, close_session, \
635 rajveer 14
    retire_item_on, get_item_inventory_by_item_id, get_items_by_catalog_id,\
1308 chandransh 15
    get_best_deals, get_best_deals_catalog_ids, get_best_deals_count, get_best_sellers, get_latest_arrivals, get_latest_arrivals_catalog_ids, get_latest_arrivals_count,\
635 rajveer 16
    is_active, get_best_sellers_catalog_ids, get_best_sellers_count, put_category_object,\
871 chandransh 17
    get_category_object, mark_item_as_content_complete,\
1341 chandransh 18
    reserve_item_in_warehouse, reduce_reservation_count, generate_new_entity_id,\
2116 ankur.sing 19
    get_all_item_pricing, add_vendor_pricing, \
2035 rajveer 20
    get_item_pricing, get_category, get_all_categories, add_category,\
2116 ankur.sing 21
    get_item_status_description, get_all_vendors, check_vendor_item_mapping,\
2286 ankur.sing 22
    get_item_mappings, add_vendor_item_mapping, check_similar_item,\
2809 rajveer 23
    change_risky_flag, get_items_by_vendor_category, get_risky_items,\
3086 rajveer 24
    get_similar_items_catalog_ids, add_product_notification,\
3348 varun.gupt 25
    send_product_notifications, update_inventory_history,\
3557 rajveer 26
    get_all_brands_by_category, is_alive, get_item_pricing_by_source,\
27
    add_source_item_pricing, get_all_sources, get_item_for_source,\
28
    get_all_source_pricing
122 ashish 29
from shop2020.model.v1.catalog.impl.Convertors import to_t_item,\
2065 ankur.sing 30
    to_t_item_inventory, to_t_warehouse, to_t_vendor_item_pricing, to_t_category,\
3557 rajveer 31
    to_t_vendor, to_t_vendor_item_mapping, to_t_source_item_pricing
122 ashish 32
from shop2020.thriftpy.model.v1.catalog.ttypes import status,\
33
    InventoryServiceException
599 chandransh 34
from shop2020.config.client.ConfigClient import ConfigClient
122 ashish 35
 
36
 
37
class InventoryServiceHandler:
38
    '''
39
    classdocs
40
    '''
599 chandransh 41
 
3187 rajveer 42
    def __init__(self, dbname='catalog', db_hostname='localhost'):
122 ashish 43
        '''
44
        Constructor
45
        '''
3187 rajveer 46
        DataService.initialize(dbname, db_hostname)
599 chandransh 47
        try:
621 chandransh 48
            config_client = ConfigClient()
49
            self.latest_arrivals_limit = int(config_client.get_property("LATEST_ARRIVALS_LIMIT"));
50
            self.best_sellers_limit = int(config_client.get_property("BEST_SELLERS_LIMIT"))
599 chandransh 51
        except:
621 chandransh 52
            self.latest_arrivals_limit = 50
53
            self.best_sellers_limit = 50
122 ashish 54
 
55
    #DONE
56
    def addItem(self, item):
57
        """
58
        Availability and inventory attributes
59
 
60
        Parameters:
61
         - item
62
        """
63
        log_entry(self, "addItem called")
785 rajveer 64
        try:
65
            return add_item(item)
66
        finally:
67
            close_session()
122 ashish 68
 
69
    def addWarehouse(self, warehouse):
70
        """
71
        Parameters:
72
         - warehouse
73
        """
74
        log_entry(self, "addWarehouse called")
785 rajveer 75
        try:
76
            return add_warehouse(warehouse)
77
        finally:
78
            close_session()
122 ashish 79
 
3325 chandransh 80
    def updateInventoryHistory(self, warehouse_id, timestamp, availability):
81
        """
82
        Stores the incremental warehouse updates of items.
83
 
84
        Parameters:
85
         - warehouse_id
86
         - timestamp
87
         - availability
88
        """
89
        try:
90
            return update_inventory_history(warehouse_id, timestamp, availability)
91
        finally:
92
            close_session()
483 rajveer 93
 
94
    def updateInventory(self, warehouse_id, timestamp, availability):
122 ashish 95
        """
96
        Parameters:
97
         - warehouse_id
98
         - timestamp
483 rajveer 99
         - availability
122 ashish 100
        """
101
        log_entry(self, "update Inventory called")
785 rajveer 102
        try:
103
            return update_inventory(warehouse_id, timestamp, availability)
104
        finally:
105
            close_session()
106
 
107
 
635 rajveer 108
    def isActive(self, item_id):
563 chandransh 109
        """
110
        Parameters:
635 rajveer 111
         - item_id
563 chandransh 112
        """
785 rajveer 113
        try:
114
            return is_active(item_id)
115
        finally:
116
            close_session()
122 ashish 117
 
2035 rajveer 118
    def getItemStatusDescription(self, itemId):
119
        """
120
        Parameters:
121
         - itemId
122
        """
123
        try:
124
            return get_item_status_description(itemId)
125
        finally:
126
            close_session()
127
 
122 ashish 128
    def retireWarehouse(self, warehouse_id):
129
        """
130
        Parameters:
131
         - warehouse_id
132
        """
133
        log_entry(self, "retire warehouse called")
785 rajveer 134
        try:
135
            return retire_warehouse(warehouse_id)
136
        finally:
137
            close_session()
138
 
122 ashish 139
 
140
    def retireItem(self, item_id):
141
        """
142
        Parameters:
143
        - item_id
144
        """
145
        log_entry(self, "retire item called")
785 rajveer 146
        try:
147
            return retire_item(item_id)
148
        finally:
149
            close_session()
122 ashish 150
 
151
    def startItemOn(self, item_id, timestamp):
152
        """
153
        Parameters:
154
         - item_id
155
         - timestamp
156
        """
785 rajveer 157
        try:
158
            start_item_on(item_id, timestamp)
159
        finally:
160
            close_session()
122 ashish 161
 
162
    def retireItemOn(self, item_id, timestamp):
163
        """
164
        Parameters:
165
         - item_id
166
         - timestamp
167
        """
785 rajveer 168
        try:
169
            retire_item_on(item_id, timestamp)
170
        finally:
171
            close_session()
122 ashish 172
 
173
    def changeItemStatus(self, item_id, timestamp, newstatus):
174
        """
175
        Parameters:
176
         - item_id
177
         - timestamp
178
         - newstatus
179
        """
180
        log_entry(self, "change item status called")
785 rajveer 181
        try:
182
            return change_item_status(item_id, newstatus)
183
        finally:
184
            close_session()
122 ashish 185
 
785 rajveer 186
 
122 ashish 187
    def getItem(self, item_id):
188
        """
189
        Parameters:
190
         - item_id
191
        """
192
        log_entry(self, "item requested")
785 rajveer 193
        try:
2065 ankur.sing 194
            item = to_t_item( get_item(item_id))
195
            return item
785 rajveer 196
        finally:
197
            close_session()
379 ashish 198
 
635 rajveer 199
    def getItemsByCatalogId(self, catalog_item_id):
379 ashish 200
        """
201
        Parameters:
202
        - catalog_item_id
203
        """
386 ashish 204
        log_entry(self, "item requested")
766 rajveer 205
        try:
206
            return get_items_by_catalog_id(catalog_item_id)
207
        finally:
208
            close_session()
122 ashish 209
 
483 rajveer 210
 
122 ashish 211
    def getAllItems(self, isActive):
212
        """
213
        Parameters:
214
         - isActive
215
        """
216
        log_entry(self, "all items requested")
766 rajveer 217
        try:
218
            items = get_all_items(isActive)
219
            ret_items = []
220
            for item in items:
221
                if item:
222
                    ret_items.append(to_t_item(item))
223
            return ret_items
224
        finally:
225
            close_session()
226
 
122 ashish 227
    def getAllItemsByStatus(self, itemStatus):
228
        """
229
        Parameters:
230
         - itemStatus
231
        """
232
        log_entry(self, "all items requested")
766 rajveer 233
        try:
234
            items = get_all_items_by_status(itemStatus)
235
            ret_items = []
236
            for item in items:
237
                if item:
238
                    ret_items.append(to_t_item(item))
239
            return ret_items
240
        finally:
241
            close_session()
122 ashish 242
 
243
    def getItemInventory(self, item_id):
244
        """
245
        Parameters:
246
        - item_id
247
        """
248
        log_entry(self, "item inventory requested")
766 rajveer 249
        try:
250
            inventory = get_item_inventoy(item_id)
251
            return to_t_item_inventory(inventory, item_id)
252
        finally:
253
            close_session()
122 ashish 254
 
635 rajveer 255
    def getItemInventoryByItemId(self, item_id):
256
        """
257
        Parameters:
258
         - item_id
259
        """
260
        log_entry(self, "item inventory requested")
766 rajveer 261
        try:
262
            inventory = get_item_inventory_by_item_id(item_id)
263
            return to_t_item_inventory(inventory, item_id)
264
        finally:
265
            close_session()
635 rajveer 266
 
3348 varun.gupt 267
    def getAllBrandsByCategory(self, categoryId):
268
        """
269
        Parameters:
270
         - categoryId
271
        """
272
        try:
273
            return get_all_brands_by_category(categoryId)
274
        finally:
275
            close_session()
276
 
635 rajveer 277
    '''
379 ashish 278
    def getItemInventoryByCatalogId(self, item_id):
279
        """
280
        Parameters:
281
         - item_id
282
        """
383 ashish 283
        log_entry(self, "item inventory requested")
284
        inventory = get_item_inventory_by_catalog_id(item_id)
285
        return to_t_item_inventory(inventory, item_id)
635 rajveer 286
    '''
287
 
379 ashish 288
 
643 chandransh 289
    def getItemAvailabilityAtLocation(self, warehouse_loc, item_id):
290
        """
3355 chandransh 291
        Determines the warehouse that should be used to fulfil an order for the given item.
292
        It first checks all the warehouses which are in the logistics location given by the
293
        warehouse_loc parameter. If none of the warehouses there have any inventory, then the
294
        preferred warehouse for the item is used.
643 chandransh 295
 
3355 chandransh 296
        Returns an ordered list of size 4 with following elements in the given order:
297
        1. Logistics location of the warehouse which was finally picked up to ship the order.
298
        2. Id of the warehouse which was finally picked up.
299
        3. Inventory size in the selected warehouse.
300
        4. Expected delay added by the category manager.
301
 
643 chandransh 302
        Parameters:
303
         - warehouse_loc
304
         - item_id
305
        """
766 rajveer 306
        try:
307
            return get_item_availability_for_location(warehouse_loc, item_id)
308
        finally:
309
            close_session()
310
 
122 ashish 311
    def getItemAvailibilityAtWarehouse(self, warehouse_id, item_id):
312
        """
313
        Parameters:
314
         - warehouse_id
315
         - item_id
316
        """
317
        log_entry(self, "item availability at warehouse requested")
766 rajveer 318
        try:
319
            return get_item_availability_for_warehouse(warehouse_id, item_id)
320
        finally:
321
            close_session()
322
 
2080 rajveer 323
    def markItemAsContentComplete(self, entityId, category, brand, modelName, modelNumber):
324
        """
325
        Parameters:
326
         - entityId
327
         - category
328
         - brand
329
         - modelName
330
         - modelNumber
331
        """
332
        try:
333
            return mark_item_as_content_complete(entityId, category, brand, modelName, modelNumber)
334
        finally:
335
            close_session()
2075 rajveer 336
 
337
 
122 ashish 338
    def getItemInventoryHistory(self, id, item_id, warehouse_id, from_date, to_date):
339
        """
340
        Parameters:
341
         - id
342
         - item_id
343
         - warehouse_id
344
         - from_date
345
         - to_date
346
        """
347
        pass
348
 
349
    def getAllWarehouses(self, isActive):
350
        """
351
        Parameters:
352
        - isActive
353
        """
766 rajveer 354
        try:
355
            if isActive:
356
                warehouses = get_all_warehouses_by_status(status.ACTIVE)
357
            else:
358
                warehouses = get_all_warehouses_by_status(None)
359
 
360
            ret_warehouses = []
361
 
362
            for warehouse in warehouses:
363
                ret_warehouses.append(to_t_warehouse(warehouse))
364
            return ret_warehouses
365
        finally:
366
            close_session()
367
 
122 ashish 368
    def getWarehouse(self, warehouse_id):
369
        """
370
        Parameters:
371
         - warehouse_id
372
        """
373
        log_entry(self, "get warehouse call")
766 rajveer 374
        try:
375
            warehouse = get_Warehouse(warehouse_id)
376
            if warehouse:
377
                return to_t_warehouse(warehouse)
378
            else:
379
                raise InventoryServiceException(101, "no such warehouse")
380
        finally:
381
            close_session()
382
 
122 ashish 383
    def getAllWarehousesForItem(self, item_id):
384
        """
385
        Parameters:
386
         - item_id
387
        """
388
        log_entry(self, "getting all warehouses for item")
766 rajveer 389
        try:
390
            all_warehouses = get_all_warehouses_for_item(item_id)
391
            t_warehouses = []
392
            for warehouse in all_warehouses:
393
                t_warehouses.append(to_t_warehouse(warehouse))
394
            return t_warehouses
395
        finally:
396
            close_session()
397
 
122 ashish 398
    def getAllItemsForWarehouse(self, warehouse_id):
399
        """
400
        Parameters:
401
         - warehouse_id
402
        """
403
        log_entry(self, "getting all items for warehouse")
766 rajveer 404
        try:
405
            all_items = get_all_items_for_warehouse(warehouse_id)
406
            t_items = []
407
            for item in all_items:
408
                t_items.append(to_t_item(item))
409
            return t_items
410
        finally:
411
            close_session()
871 chandransh 412
 
413
    def reserveItemInWarehouse(self, itemId, warehouseId, quantity):
414
        """
415
        Increases the reservation count for an item in a warehouse. Should always succeed normally.
416
 
417
        Parameters:
418
         - itemId
419
         - warehouseId
420
        """
421
        log_entry(self, "reserveItemInWarehouse called")
422
        try:
423
            return reserve_item_in_warehouse(itemId, warehouseId, quantity)
424
        finally:
425
            close_session()
426
 
427
    def reduceReservationCount(self, itemId, warehouseId, quantity):
428
        """
429
        Decreases the reservation count for an item in a warehouse. Should always succeed normally.
430
 
431
        Parameters:
432
         - itemId
433
         - warehouseId
434
        """
435
        log_entry(self, "reduceReservationCount called")
436
        try:
437
            return reduce_reservation_count(itemId, warehouseId, quantity)
438
        finally:
439
            close_session()
766 rajveer 440
 
122 ashish 441
    def updateItem(self, item):
442
        """
443
        Parameters:
444
         - item
445
        """
446
        log_entry(self, "addItem called")
766 rajveer 447
        try:
448
            return update_item(item)
449
        finally:
450
            close_session()
451
 
626 chandransh 452
    def getBestSellers(self, start_index=0, total_items=None, category=-1):
766 rajveer 453
        try:
454
            if total_items is None:
455
                total_items = self.best_sellers_limit
456
            stop_index = start_index + total_items
457
            return get_best_sellers(start_index, stop_index, category)
458
        finally:
459
            close_session()
460
 
1926 rajveer 461
    def getBestSellersCatalogIds(self, start_index, total_items, brand, category=-1):
548 rajveer 462
        """
463
        Parameters:
464
         - beginIndex
465
         - totalItems
466
        """
766 rajveer 467
        try:
468
            if total_items is None:
469
                total_items = self.best_sellers_limit
470
            stop_index = start_index + total_items
1926 rajveer 471
            return get_best_sellers_catalog_ids(start_index, stop_index, brand, category)
766 rajveer 472
        finally:
473
            close_session()
474
 
591 chandransh 475
    def getBestSellersCount(self, ):
766 rajveer 476
        try:
2093 chandransh 477
            return get_best_sellers_count()
766 rajveer 478
        finally:
479
            close_session()
480
 
591 chandransh 481
    def getBestDeals(self,):
766 rajveer 482
        try:
483
            return get_best_deals()
484
        finally:
485
            close_session()
486
 
1926 rajveer 487
    def getBestDealsCatalogIds(self, start_index, total_items, brand,category=-1):
548 rajveer 488
        """
489
        Parameters:
490
         - beginIndex
491
         - totalItems
492
        """
766 rajveer 493
        try:
494
            stop_index = start_index + total_items
1926 rajveer 495
            return get_best_deals_catalog_ids(start_index, stop_index, brand, category)
766 rajveer 496
        finally:
497
            close_session()
498
 
591 chandransh 499
    def getBestDealsCount(self, ):
766 rajveer 500
        try:
501
            return get_best_deals_count()
502
        finally:
503
            close_session()
504
 
591 chandransh 505
    def getLatestArrivals(self,):
766 rajveer 506
        try:
507
            return get_latest_arrivals(self.latest_arrivals_limit)
508
        finally:
509
            close_session()
2975 chandransh 510
 
511
    def getLatestArrivalsCatalogIds(self, beginIndex, totalItems, brand, categories):
548 rajveer 512
        """
2975 chandransh 513
        Returns the list of catalog ids of latest arrivals in the given categories of the given brand.
514
        To ignore the categories, pass the list as empty. To ignore brand, pass it as null.
515
 
548 rajveer 516
        Parameters:
517
         - beginIndex
518
         - totalItems
2975 chandransh 519
         - brand
520
         - categories
548 rajveer 521
        """
766 rajveer 522
        try:
2975 chandransh 523
            if beginIndex > self.latest_arrivals_limit:
766 rajveer 524
                return []
2975 chandransh 525
            stopIndex = beginIndex + totalItems
526
            if stopIndex > self.latest_arrivals_limit:
527
                stopIndex = self.latest_arrivals_limit
528
            return get_latest_arrivals_catalog_ids(beginIndex, stopIndex, brand, categories)
766 rajveer 529
        finally:
530
            close_session()
531
 
591 chandransh 532
    def getLatestArrivalsCount(self, ):
766 rajveer 533
        try:
534
            return get_latest_arrivals_count(self.latest_arrivals_limit)
535
        finally:
536
            close_session()
591 chandransh 537
 
1334 chandransh 538
    def getItemPricing(self, itemId, warehouseId):
539
        """
540
        Returns the pricing information of an item associated with the vendor of the given warehouse.
541
        Raises an exception if either the item, vendor or the associated pricing information can't be found.
542
 
543
        Parameters:
544
         - itemId
545
         - warehouseId
546
        """
1341 chandransh 547
        try:
1347 chandransh 548
            return to_t_vendor_item_pricing(get_item_pricing(itemId, warehouseId))
1341 chandransh 549
        finally:
550
            close_session()
1991 ankur.sing 551
 
552
 
553
    def getAllItemPricing(self, itemId):
554
        """
555
        Returns list of the pricing information of an item associated an item.
556
        Raises an exception if the item can't be found.
557
 
558
        Parameters:
559
         - itemId
560
        """
561
        try:
562
            return [to_t_vendor_item_pricing(vid) for vid in get_all_item_pricing(itemId)]
563
        finally:
564
            close_session()
1334 chandransh 565
 
1155 rajveer 566
    def generateNewEntityID(self, ):
567
        try:
568
            return generate_new_entity_id()
569
        finally:
570
            close_session()
571
 
635 rajveer 572
    def putCategoryObject(self, object):
573
        """
574
        Parameters:
575
         - object
576
        """
766 rajveer 577
        try:
578
            return put_category_object(object)
579
        finally:
580
            close_session()
581
 
635 rajveer 582
    def getCategoryObject(self, ):
766 rajveer 583
        try:
584
            return get_category_object()
585
        finally:
586
            close_session()
1970 rajveer 587
 
588
    def addCategory(self, category):
589
        """
590
        Parameters:
591
         - category
592
        """
593
        try:
594
            return add_category(category)
595
        finally:
596
            close_session()
597
 
598
    def getCategory(self, id):
599
        """
600
        Parameters:
601
         - id
602
        """
603
        try:
604
            return to_t_category(get_category(id))
605
        finally:
606
            close_session()
607
 
608
    def getAllCategories(self, ):
609
        try:
610
            categories = get_all_categories()
611
            return [to_t_category(category) for category in categories]
612
        finally:
613
            close_session()
614
 
615
 
2116 ankur.sing 616
    def addVendorItemPricing(self, vendorItemPricing):
1991 ankur.sing 617
        """
2116 ankur.sing 618
        Adds vendor prices corresponding to the item. If pricing already exists then updates the prices. 
1991 ankur.sing 619
        Raises an exception if either the item or vendor can't be found corresponding to their ids.
620
 
621
        Parameters:
622
         - vendorItemPricing
623
        """
624
        log_entry(self, "updateVendorItemPricing called")
625
        try:
2116 ankur.sing 626
            return add_vendor_pricing(vendorItemPricing)
1991 ankur.sing 627
        finally:
628
            close_session()
629
 
2065 ankur.sing 630
    def getAllVendors(self, ):
631
        """
632
        Return list of all vendors
633
        """
634
        return [to_t_vendor(v) for v in get_all_vendors()]
2116 ankur.sing 635
 
636
    def itemExists(self, productGroup, brand, modelNumber, color, vendorId, category):
637
        try:
638
            return check_vendor_item_mapping(productGroup, brand, modelNumber, color, vendorId, category)
639
        finally:
640
            close_session()
2065 ankur.sing 641
 
2358 ankur.sing 642
    def addVendorItemMapping(self, key, vendorItemMapping):
2116 ankur.sing 643
        """
2358 ankur.sing 644
        Adds VendorItemMapping. Updates VendorItemMapping if exists corresponding to the item key.
2116 ankur.sing 645
 
646
        Parameters:
2358 ankur.sing 647
         - key
2116 ankur.sing 648
         - vendorItemMapping
649
        """
650
        log_entry(self, "addVendorItemMapping called")
651
        try:
2358 ankur.sing 652
            return add_vendor_item_mapping(key, vendorItemMapping)
2116 ankur.sing 653
        finally:
654
            close_session()
655
 
656
    def getVendorItemMappings(self, itemId):
657
        """
658
        Returns the list of vendor item mapping corresponding to itemId passed as parameter.
659
        Raises an exception if item not found corresponding to itemId
660
 
661
        Parameters:
662
         - itemId
663
        """
664
        try:
2120 ankur.sing 665
            item_mappings = get_item_mappings(itemId)
666
            return [to_t_vendor_item_mapping(vim) for vim in item_mappings]
2116 ankur.sing 667
        finally:
668
            close_session()
669
 
670
    def checkSimilarItem(self, productGroup, brand, modelNumber, color):
671
        """
672
        Checks if similar item exists (with same ProductGroup, Brand, ModelNumber, Color)
673
        If yes, returns the itemId else returns 0
674
 
675
        Parameters:
676
         - productGroup
677
         - brand
678
         - modelNumber
679
         - color
680
        """
681
        try:
682
            return check_similar_item(productGroup, brand, modelNumber, color)
683
        finally:
684
            close_session()
685
 
2286 ankur.sing 686
    def changeItemRiskyFlag(self, itemId, risky):
687
        """
688
        Marks/Unmarks an item as risky. This flag is used for automatic marking of an item as INACTIVE in case of zero inventory.
689
 
690
        Parameters:
691
         - itemId
692
         - risky
693
        """
694
        try:
695
            change_risky_flag(itemId, risky)
696
        finally:
697
            close_session()
2116 ankur.sing 698
 
2358 ankur.sing 699
    def getItemsByVendorCategory(self, vendorCategory):
700
        """
701
        Return list of items filtered by vendor category.
702
        Raises exception if vendorCategory is null.
703
 
704
        Parameters:
705
         - vendorCategory
706
        """
707
        try:
708
            return [to_t_item(item) for item in get_items_by_vendor_category(vendorCategory)]
709
        finally:
710
            close_session()
711
 
712
    def getItemsByRiskyFlag(self, ):
713
        """
714
        Returns list of items marked as risky.
715
        """
716
        try:
717
            return [to_t_item(item) for item in get_risky_items()]
718
        finally:
719
            close_session()
2809 rajveer 720
 
721
    def getSimilarItemsCatalogIds(self, beginIndex, totalItems, itemId):
722
        """
723
        Returns list of catalog ids of items with same similarity index as of the given itemId
724
 
725
        Parameters:
726
         - beginIndex
727
         - totalItems
728
         - itemId
729
        """
730
        try:
731
            return get_similar_items_catalog_ids(beginIndex, beginIndex+totalItems, itemId)
732
        finally:
733
            close_session()
3079 rajveer 734
 
735
    def addProductNotification(self, itemId, email):
736
        """
737
        Add user requests for out of stock items. Once user will ask for notify me an entry will
738
 
739
        Parameters:
740
        - itemId
741
        - email
742
        """
743
        try:
744
            return add_product_notification(itemId, email)
745
        finally:
746
            close_session()
2358 ankur.sing 747
 
3086 rajveer 748
    def sendProductNotifications(self, ):
749
        """
750
        Send the product notifications to the users for items which has stock.
751
        """
752
        try:
753
            return send_product_notifications()
754
        finally:
755
            close_session()
3557 rajveer 756
 
757
 
758
    def getAllSources(self, ):
759
        """
760
        Return list of all sources
761
        """
762
        try:
763
            return get_all_sources()
764
        finally:
765
            close_session()
766
 
767
    def getItemPricingBySource(self, itemId, sourceId):
768
        """
769
        Returns the pricing information of an item. If no information is found, exception will be thrown.
3376 rajveer 770
 
3557 rajveer 771
        Parameters:
772
         - itemId
773
         - sourceId
774
        """
775
        try:
776
            return to_t_source_item_pricing(get_item_pricing_by_source(itemId, sourceId))
777
        finally:
778
            close_session()
779
 
780
    def addSourceItemPricing(self, sourceItemPricing):
781
        """
782
        Adds prices to be displayed corresponding to the item if user comes from a source.
783
 
784
        Parameters:
785
         - sourceItemPricing
786
        """
787
        try:
788
            add_source_item_pricing(sourceItemPricing)
789
        finally:
790
            close_session()
791
 
792
    def getAllSourcePricing(self, itemId):
793
        """
794
        Returns the list of source pricing information of an item.
795
        Raises an exception if item not found corresponding to itemId
796
 
797
        Parameters:
798
         - itemId
799
        """
800
        try:
801
            return [to_t_source_item_pricing(source_item_pricing) for source_item_pricing in get_all_source_pricing(itemId)]
802
#        return [to_t_item(item) for item in get_risky_items()]
803
        finally:
804
            close_session()
805
 
806
    def getItemForSource(self, item_id, sourceId):
807
        """
808
        Parameters:
809
         - item_id
810
         - sourceId
811
        """
812
        try:
813
            return to_t_item(get_item_for_source(item_id, sourceId))
814
        finally:
815
            close_session()
816
 
3376 rajveer 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:
824
            close_session()
825
 
766 rajveer 826
    def closeSession(self, ):
3376 rajveer 827
        """
828
        For closing the open session in sqlalchemy
829
        """
830
        close_session()        
831