1 16 package com.blandware.atleap.service.core.impl; 17 18 import com.blandware.atleap.common.util.PartialCollection; 19 import com.blandware.atleap.common.util.QueryInfo; 20 import com.blandware.atleap.model.core.Localizable; 21 import com.blandware.atleap.model.core.MenuItem; 22 import com.blandware.atleap.persistence.core.LocalizableDAO; 23 import com.blandware.atleap.persistence.core.MenuDAO; 24 import com.blandware.atleap.service.core.MenuManager; 25 import com.blandware.atleap.service.exception.BeanNotFoundException; 26 import com.blandware.atleap.service.exception.OwnerNotFoundException; 27 import com.blandware.atleap.service.exception.ParentItemNotFoundException; 28 29 import java.util.List ; 30 31 39 public class MenuManagerImpl extends BaseManagerImpl implements MenuManager { 40 41 44 protected MenuDAO menuDAO; 45 46 49 protected LocalizableDAO localizableDAO; 50 51 54 public MenuManagerImpl() { 55 } 56 57 62 public void setMenuDAO(MenuDAO menuDAO) { 63 this.menuDAO = menuDAO; 64 } 65 66 71 public void setLocalizableDAO(LocalizableDAO localizableDAO) { 72 this.localizableDAO = localizableDAO; 73 } 74 75 78 public Long createMenuItem(MenuItem menuItem, Long parentItemId, Long ownerId) throws BeanNotFoundException { 79 80 if ( log.isDebugEnabled() ) { 81 log.debug("Creating new menu item..."); 82 } 83 84 MenuItem parentItem = null; 86 if ( parentItemId != null ) { 87 parentItem = menuDAO.retrieveMenuItem(parentItemId); 88 if ( parentItem == null ) { 89 String errorMessage = "MenuItem with ID=" + parentItemId + " does not exist"; 90 if ( log.isErrorEnabled() ) { 91 log.error(errorMessage); 92 } 93 throw new ParentItemNotFoundException(errorMessage); 94 } 95 } 96 97 Localizable owner = null; 98 if ( ownerId != null ) { 99 owner = localizableDAO.retrieveLocalizable(ownerId); 100 if ( owner == null ) { 101 String errorMessage = "Localizable with ID=" + ownerId + " does not exist"; 102 if ( log.isErrorEnabled() ) { 103 log.error(errorMessage); 104 } 105 throw new OwnerNotFoundException(errorMessage); 106 } 107 } 108 109 Long menuItemId = menuDAO.createMenuItem(menuItem, parentItem, owner); 111 112 if ( (menuItem.getIdentifier() == null || menuItem.getIdentifier().trim().length() == 0) && !menuItem.isRedefinition() ) { 114 menuItem.setIdentifier("MenuItem-" + menuItemId); 115 menuDAO.updateMenuItem(menuItem, parentItem, owner); 116 } 117 118 if ( log.isDebugEnabled() ) { 119 log.debug("New menu item has been created succesfully. Its ID is " + menuItemId); 120 } 121 122 return menuItemId; 123 } 124 125 128 public MenuItem retrieveMenuItem(Long menuItemId) { 129 return menuDAO.retrieveMenuItem(menuItemId); 130 } 131 132 135 public void updateMenuItem(MenuItem menuItem, Long parentItemId, Long ownerId) throws BeanNotFoundException { 136 137 menuDAO.removeFromCache(menuItem); 139 140 if ( log.isDebugEnabled() ) { 141 log.debug("Updating menu item with ID=" + menuItem.getId() + "..."); 142 } 143 144 MenuItem parentItem = null; 146 if ( parentItemId != null ) { 147 parentItem = menuDAO.retrieveMenuItem(parentItemId); 148 if ( parentItem == null ) { 149 String errorMessage = "MenuItem with ID=" + parentItemId + " does not exist"; 150 if ( log.isErrorEnabled() ) { 151 log.error(errorMessage); 152 } 153 throw new ParentItemNotFoundException(errorMessage); 154 } 155 } 156 157 Localizable owner = null; 158 if ( ownerId != null ) { 159 owner = localizableDAO.retrieveLocalizable(ownerId); 160 if ( owner == null ) { 161 String errorMessage = "Localizable with ID=" + ownerId + " does not exist"; 162 if ( log.isErrorEnabled() ) { 163 log.error(errorMessage); 164 } 165 throw new OwnerNotFoundException(errorMessage); 166 } 167 } 168 169 menuDAO.updateMenuItem(menuItem, parentItem, owner); 171 172 if ( log.isDebugEnabled() ) { 173 log.debug("Menu item has been updated successfully."); 174 } 175 176 } 177 178 181 public void deleteMenuItem(Long menuItemId) throws BeanNotFoundException { 182 MenuItem menuItem = menuDAO.retrieveMenuItem(menuItemId); 183 if ( menuItem == null ) { 184 String errorMessage = "No content resource with ID=" + menuItem + "could be found"; 185 throw new BeanNotFoundException(errorMessage); 186 } 187 menuDAO.deleteMenuItem(menuItem); 188 } 189 190 193 public PartialCollection listMenuItems(QueryInfo queryInfo) { 194 return menuDAO.listMenuItems(queryInfo); 195 } 196 197 200 public MenuItem findMenuItemByIdentifierAndParentAndOwner(String identifier, Long parentItemId, Long ownerId) { 201 return menuDAO.findMenuItemByIdentifierAndParentAndOwner(identifier, parentItemId, ownerId); 202 } 203 204 205 208 public MenuItem findMenuItemByPositionAndParentAndOwner(Integer position, Long parentItemId, Long ownerId) { 209 return menuDAO.findMenuItemByPositionAndParentAndOwner(position, parentItemId, ownerId); 210 } 211 212 215 public List findMenuItemsByParentAndOwner(Long parentItemId, Long ownerId) { 216 return menuDAO.findMenuItemsByParentAndOwner(parentItemId, ownerId); 217 } 218 219 222 public MenuItem findRedefinitionItem(Long origItemId, Long ownerId) { 223 return menuDAO.findRedefinitionItem(origItemId, ownerId); 224 } 225 226 } 227 | Popular Tags |