com.konakart.bl
Class CategoryMgr

java.lang.Object
  extended by com.konakart.bl.BaseMgr
      extended by com.konakart.bl.CategoryMgr
All Implemented Interfaces:
CategoryMgrIf

public class CategoryMgr
extends BaseMgr
implements CategoryMgrIf

Manages all business logic relevant to the management of categories within the system.


Nested Class Summary
protected  class CategoryMgr.StaticData
          Used to store the static data of this manager
 
Field Summary
protected static org.apache.commons.logging.Log log
          the log
protected static java.lang.String mutex
           
protected static java.util.Map<java.lang.String,CategoryMgr.StaticData> staticDataHM
          Hash Map that contains the static data
 
Fields inherited from class com.konakart.bl.BaseMgr
templateBaseDir
 
Constructor Summary
CategoryMgr(KKEngIf eng)
          Constructor
 
Method Summary
protected  void fillCatTreeWithProductNumbers(Category[] catTree)
          Receives an array of Categories as input and compiles the numberOfProducts field for each Category
 Category[] getCategoriesFromIds(java.util.ArrayList<java.lang.Integer> catIdList, int languageId)
          Return an array of categories for the ids passed in through the catIdList parameter.
 Category[] getCategoriesPerManufacturer(int manufacturerId, int languageId)
          Returns an array of leaf Category objects for the given manufacturer.
 Category[] getCategoriesPerProduct(int productId, int languageId)
          Returns an array of Category objects that the product belongs to.
 Category getCategory(int categoryId, int languageId)
           
protected  Category[] getCategoryTree(int languageId)
          Calls getCategoryTree(int languageId, boolean getNumProducts)
 Category[] getCategoryTree(int languageId, boolean getNumProducts)
          Returns an array of top level categories each of which includes an array of child categories etc.
protected  Category[] getChildren(Category parent, int languageId)
          Returns an array of child categories, children of the input parameter, parent.
 int[] getChildren(int categoryId)
          Returns an array of categoryId describing the children of the given category.
 CategoryStats getLastModifiedData()
          Retrieves the date of the last modified category and the number of categories in the database.
protected  int getNumProductsPerCategory(int categoryId)
          Returns the number of products for a leaf category by doing a direct query on the database.
 int[] getParents(int categoryId)
          Returns an array of categoryId describing the given category and its parents.
protected  java.util.HashMap<java.lang.Integer,java.lang.Integer> getProductsPerCategory()
          Returns a HashMap with CategoryId as the key and Number of Products for that category as the value.
protected  Category[] getTopLevelCategories(int languageId)
          Returns all of the top level categories which are those that have a parentId = 0.
protected  void initStaticVariables(CategoryStats catStats)
          A synchronized method to initialise the static variables
protected  void setChildrenProductNumbers(Category parent, java.util.HashMap<java.lang.Integer,java.lang.Integer> hm)
          Recurses through all of the category tree setting the numberOfProducts attribute.
protected  void setCriteriaWithStandardAttributes(KKCriteria c, int languageId)
          Sets the criteria with the standard attributes so as not to have to repeat this code many times.
protected  void setCriteriaWithStandardAttributes(KKCriteria c, int languageId, boolean addDescription)
          Sets the criteria with the standard attributes so as not to have to repeat this code many times.
 
Methods inherited from class com.konakart.bl.BaseMgr
addInsertAttr, addInsertAttr, checkRequired, getAdminEngMgr, getBasketMgr, getBillingMgr, getBookableProductMgr, getCatMgr, getConfigMgr, getCookieMgr, getCurrMgr, getCustMgr, getCustomerIdFromSession, getCustomerStatsMgr, getCustomerTagMgr, getEmailMgr, getEng, getLangMgr, getManuMgr, getMiscItemMgr, getMode, getModeString, getMqMgr, getMultiStoreMgr, getNewCriteria, getNewCriteria, getOrderMgr, getOrderTotalMgr, getPaymentMgr, getProdMgr, getPromMgr, getRewardPointMgr, getSecMgr, getShippingMgr, getSolrMgr, getStoreId, getTaxMgr, getTemplate, getTemplateRoot, getVelocityContextMgr, getWishListMgr, init, isEnterprise, isMultiStoreShareCustomers, isMultiStoreShareProducts
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.commons.logging.Log log
the log


mutex

protected static java.lang.String mutex

staticDataHM

protected static java.util.Map<java.lang.String,CategoryMgr.StaticData> staticDataHM
Hash Map that contains the static data

Constructor Detail

CategoryMgr

public CategoryMgr(KKEngIf eng)
            throws java.lang.Exception
Constructor

Parameters:
eng -
Throws:
java.lang.Exception
Method Detail

getCategoryTree

protected Category[] getCategoryTree(int languageId)
                              throws java.lang.Exception
Calls getCategoryTree(int languageId, boolean getNumProducts)

Parameters:
languageId -
Returns:
Array of Category Objects
Throws:
org.apache.torque.TorqueException
java.lang.Exception

getCategoryTree

public Category[] getCategoryTree(int languageId,
                                  boolean getNumProducts)
                           throws java.lang.Exception
Returns an array of top level categories each of which includes an array of child categories etc. so that the category tree structure can be navigated. Since the categories are not changed very often and the process of building the tree requires the execution of many database queries, we keep a static version of the tree which is only changed if we realise that a category has been modified by looking at the last_modified field. Since a category may also be deleted, we look at the number of categories also to see whether it has changed.

Each Category class contains a field that describes how many products exist for that category. This field is not set in the static tree and we calculate it each time on demand since it only involves one database query and the product information is a lot more dynamic than that of the categories. We only calculate it if getNumProducts is set.

Specified by:
getCategoryTree in interface CategoryMgrIf
Parameters:
languageId -
getNumProducts -
Returns:
Array of Category Objects
Throws:
java.lang.Exception

initStaticVariables

protected void initStaticVariables(CategoryStats catStats)
                            throws KKException
A synchronized method to initialise the static variables

Parameters:
catStats -
Throws:
KKException

getTopLevelCategories

protected Category[] getTopLevelCategories(int languageId)
                                    throws org.apache.torque.TorqueException,
                                           com.workingdogs.village.DataSetException
Returns all of the top level categories which are those that have a parentId = 0. They are returned in the order of the sort order defined in the DB.

Parameters:
languageId -
Returns:
Array of Category Objects
Throws:
org.apache.torque.TorqueException
com.workingdogs.village.DataSetException

getChildren

protected Category[] getChildren(Category parent,
                                 int languageId)
                          throws org.apache.torque.TorqueException,
                                 com.workingdogs.village.DataSetException
Returns an array of child categories, children of the input parameter, parent. It is recursive and so fetches the grandchildren etc.

Parameters:
parent -
languageId -
Returns:
Array of Category Objects
Throws:
org.apache.torque.TorqueException
com.workingdogs.village.DataSetException

getCategoriesPerManufacturer

public Category[] getCategoriesPerManufacturer(int manufacturerId,
                                               int languageId)
                                        throws java.lang.Exception
Returns an array of leaf Category objects for the given manufacturer.

Specified by:
getCategoriesPerManufacturer in interface CategoryMgrIf
Parameters:
manufacturerId -
languageId -
Returns:
Return an array of category objects
Throws:
java.lang.Exception

getCategoriesPerProduct

public Category[] getCategoriesPerProduct(int productId,
                                          int languageId)
                                   throws java.lang.Exception
Returns an array of Category objects that the product belongs to.

Specified by:
getCategoriesPerProduct in interface CategoryMgrIf
Parameters:
productId -
languageId -
Returns:
Return an array of category objects
Throws:
java.lang.Exception

getProductsPerCategory

protected java.util.HashMap<java.lang.Integer,java.lang.Integer> getProductsPerCategory()
                                                                                 throws org.apache.torque.TorqueException,
                                                                                        com.workingdogs.village.DataSetException,
                                                                                        KKException
Returns a HashMap with CategoryId as the key and Number of Products for that category as the value. The products need to have a non 0 status and not be invisible to be considered.

Returns:
HashMap Contains number of products per category
Throws:
org.apache.torque.TorqueException
com.workingdogs.village.DataSetException
KKException

getNumProductsPerCategory

protected int getNumProductsPerCategory(int categoryId)
                                 throws org.apache.torque.TorqueException,
                                        com.workingdogs.village.DataSetException,
                                        KKException
Returns the number of products for a leaf category by doing a direct query on the database. The products need to have a non 0 status to be considered.

Parameters:
categoryId -
Returns:
Return an int defining the number of products per category
Throws:
org.apache.torque.TorqueException
com.workingdogs.village.DataSetException
KKException

getLastModifiedData

public CategoryStats getLastModifiedData()
                                  throws org.apache.torque.TorqueException,
                                         com.workingdogs.village.DataSetException
Retrieves the date of the last modified category and the number of categories in the database. It will be used to identify whether any category has been changed. If the last_modified column doesn't contain any valid dates, then we return the current date since we have to assume worst case that some category has been modified.

Returns:
CategoryStats An object containing last modification date and number of categories
Throws:
org.apache.torque.TorqueException
com.workingdogs.village.DataSetException

fillCatTreeWithProductNumbers

protected void fillCatTreeWithProductNumbers(Category[] catTree)
                                      throws org.apache.torque.TorqueException,
                                             com.workingdogs.village.DataSetException,
                                             KKException
Receives an array of Categories as input and compiles the numberOfProducts field for each Category

Parameters:
catTree -
Throws:
com.workingdogs.village.DataSetException
org.apache.torque.TorqueException
KKException

setChildrenProductNumbers

protected void setChildrenProductNumbers(Category parent,
                                         java.util.HashMap<java.lang.Integer,java.lang.Integer> hm)
                                  throws com.workingdogs.village.DataSetException
Recurses through all of the category tree setting the numberOfProducts attribute.

Parameters:
parent - The parent category.
hm -
Throws:
com.workingdogs.village.DataSetException

getChildren

public int[] getChildren(int categoryId)
                  throws java.lang.Exception
Returns an array of categoryId describing the children of the given category. Returns null if there are no children.

Specified by:
getChildren in interface CategoryMgrIf
Parameters:
categoryId -
Returns:
Return an array of categoryId
Throws:
java.lang.Exception

getParents

public int[] getParents(int categoryId)
                 throws java.lang.Exception
Returns an array of categoryId describing the given category and its parents. Returns just the given category id in the array if there are no parents (i.e. It is a top level node).

Specified by:
getParents in interface CategoryMgrIf
Parameters:
categoryId -
Returns:
Return an array of categoryId
Throws:
java.lang.Exception

getCategory

public Category getCategory(int categoryId,
                            int languageId)
                     throws java.lang.Exception
Specified by:
getCategory in interface CategoryMgrIf
Parameters:
categoryId -
languageId -
Returns:
Return a fully populated single category object (no children)
Throws:
java.lang.Exception

setCriteriaWithStandardAttributes

protected void setCriteriaWithStandardAttributes(KKCriteria c,
                                                 int languageId)
Sets the criteria with the standard attributes so as not to have to repeat this code many times.

Parameters:
c -
languageId -

setCriteriaWithStandardAttributes

protected void setCriteriaWithStandardAttributes(KKCriteria c,
                                                 int languageId,
                                                 boolean addDescription)
Sets the criteria with the standard attributes so as not to have to repeat this code many times.

Parameters:
c -
languageId -
addDescription -

getCategoriesFromIds

public Category[] getCategoriesFromIds(java.util.ArrayList<java.lang.Integer> catIdList,
                                       int languageId)
                                throws java.lang.Exception
Return an array of categories for the ids passed in through the catIdList parameter.

Specified by:
getCategoriesFromIds in interface CategoryMgrIf
Parameters:
catIdList - An array list containing ids of categories
languageId -
Returns:
An array of categories for the ids passed in
Throws:
java.lang.Exception


Copyright © 2011 DS Data Systems UK Ltd.