Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

'''
Created on 22-Mar-2010

@author: ashish
'''
from shop2020.thriftpy.model.v1.catalog import CatalogService
from shop2020.model.v1.catalog.impl import DataService, Convertors
from shop2020.model.v1.catalog.impl.DataAcessors import is_category_present,\
    add_category, add_item_to_category, update_inventory, get_category,\
    get_item_inventoy, get_all_categories, get_Item, get_all_items_for_category,\
    get_Warehouse, get_all_warehouses_for_item, add_vendor, add_warehouse
from shop2020.thriftpy.model.v1.catalog.ttypes import CatalogServiceException
from shop2020.model.v1.catalog.impl.Convertors import to_t_category,\
    to_t_item_inventory, to_t_item, to_t_warehouse

class CatalogServiceHandler:
    '''
    classdocs
    '''
    def __init__(self,params):
        '''
        Constructor
        '''
        DataService.initialize()
       
    def addCategory(self, category):
        """
        Availability and inventory attributes
        
        Parameters:
         - category
        """
        if category.id:
            if is_category_present(id):
                #throw an exception here.
                raise CatalogServiceException(101, "This category is already present")
        
        #Create a category and add it.
        if not add_category(category):
            raise CatalogServiceException(102, "This category could not be added")
        

    def addItemToCategory(self, item, category_id):
        """
        Parameters:
         - item
         - category_id
        """
        if not add_item_to_category(category_id, item):
            raise CatalogServiceException(105, "Item could not be added")

    #===========================================================================
    # This methos will be filled later after consulting @naveen
    #===========================================================================
    def addItemAttribsToItem(self, itemattribs, item_id):
      """
      Parameters:
       - itemattribs
       - item_id
      """
      pass
    
    def addItemInventoryToItem(self, iteminventory, item_id):
        """
        Parameters:
         - iteminventory
         - item_id
        """
        #This method is redundant and has to be removed
        pass
    
    def addWarehouse(self, warehouse):
        """
        Parameters:
         - warehouse
        """
        add_warehouse(warehouse)
    
    def addVendor(self, vendor):
        """
        Parameters:
         - vendor
        """
        add_vendor(vendor)
    
    def updateInventory(self, item_id, warehouse_id, quantity, timestamp):
        """
        Parameters:
         - item_id
         - warehouse_id
         - quantity
         - timestamp
        """
        update_inventory(item_id, warehouse_id, quantity, timestamp)
    
    def getCategory(self, id):
        """
        Parameters:
         - id
        """
        category = get_category(id)
        if not category:
            raise CatalogServiceException(101, "Could not loacet the category")
    
        return to_t_category(category)
    
    def getAllCategories(self):
        t_categories = []
        all_categories = get_all_categories()
        for category in all_categories:
            t_categories.append(to_t_category(category))
        return t_categories
    
    def getItem(self, item_id):
        """
        Parameters:
         - item_id
        """
        item = get_Item(item_id)
        return to_t_item(item)
    
    def getAllItemsForCategory(self, category_id):
        """
        Parameters:
         - category_id
        """
        items = get_all_items_for_category(category_id)
        t_items = []
        for item in items:
            t_items.append(to_t_item(item))
        
        return t_items
    
    def getItemAtttribs(self, item_id):
      """
      Parameters:
       - item_id
      """
      pass
    
    def getItemInventory(self, item_id):
        """
        Parameters:
         - item_id
        """
        inventory = get_item_inventoy(item_id)
        return to_t_item_inventory(inventory, item_id)
        
    def getItemInventoryHistory(self, id, item_id, warehouse_id, from_date, to_date):
      """
      Parameters:
       - id
       - item_id
       - warehouse_id
       - from_date
       - to_date
      """
      pass
    
    def getWarehouse(self, warehouse_id):
        """
        Parameters:
         - warehouse_id
        """
        warehouse = get_Warehouse(warehouse_id)
        return to_t_warehouse(warehouse)
    
    def getAllWarehousesForItem(self, item_id):
        """
        Parameters:
         - item_is
        """
        warehouses = get_all_warehouses_for_item(item_id)
        t_warehouses = []
        for warehouse in warehouses:
            t_warehouses.append(to_t_warehouse(warehouse))
        return warehouse
    
    def getExpectedDeliveryTime(self, item_id):
        """
        Parameters:
         - item_id
        """
        #TODO - To be implemented later
        pass