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