logger.info("We want to create a list of categories if not existing under the parent category " + parentCategory);
Iterator categoryIterator = categories.iterator();
while(categoryIterator.hasNext())
{
CategoryVO categoryVO = (CategoryVO)categoryIterator.next();
Category newParentCategory = null;
List existingCategories = null;
if(parentCategory != null)
existingCategories = CategoryController.getController().findByParent(parentCategory.getCategoryId(), db);
else
existingCategories = CategoryController.getController().findRootCategories(db);
Iterator existingCategoriesIterator = existingCategories.iterator();
while(existingCategoriesIterator.hasNext())
{
Category existingCategory = (Category)existingCategoriesIterator.next();
logger.info("existingCategory:" + existingCategory.getName());
if(existingCategory.getName().equals(categoryVO.getName()))
{
logger.info("Existed... setting " + existingCategory.getName() + " to new parent category.");
newParentCategory = existingCategory;
break;
}
}
if(newParentCategory == null)
{
logger.info("No existing category - we create it.");
Integer oldId = categoryVO.getId();
categoryVO.setCategoryId(null);
if(parentCategory != null)
categoryVO.setParentId(parentCategory.getCategoryId());
else
categoryVO.setParentId(null);
Category newCategory = CategoryController.getController().save(categoryVO, db);
categoryIdMap.put(oldId, newCategory.getCategoryId());
newParentCategory = newCategory;
}
else
{
categoryIdMap.put(categoryVO.getId(), newParentCategory.getCategoryId());