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.common.Constants; 21 import com.blandware.atleap.model.core.ActionPage; 22 import com.blandware.atleap.model.core.ContentPage; 23 import com.blandware.atleap.model.core.Layout; 24 import com.blandware.atleap.model.core.Page; 25 import com.blandware.atleap.persistence.core.*; 26 import com.blandware.atleap.persistence.exception.DeleteException; 27 import com.blandware.atleap.service.core.PageManager; 28 import com.blandware.atleap.service.core.UtilManager; 29 import com.blandware.atleap.service.exception.BeanAlreadyExistsException; 30 import com.blandware.atleap.service.exception.BeanNotFoundException; 31 import com.blandware.atleap.service.exception.OwnerNotFoundException; 32 33 import java.util.Collection ; 34 35 43 public class PageManagerImpl extends BaseManagerImpl implements PageManager { 44 45 48 protected ActionPageDAO actionPageDAO; 49 52 protected ContentPageDAO contentPageDAO; 53 56 protected PageDAO pageDAO; 57 60 protected LayoutDAO layoutDAO; 61 62 65 protected UtilManager utilManager; 66 67 70 public PageManagerImpl() { 71 } 72 73 78 public void setActionPageDAO(ActionPageDAO actionPageDAO) { 79 this.actionPageDAO = actionPageDAO; 80 } 81 82 87 public void setContentPageDAO(ContentPageDAO contentPageDAO) { 88 this.contentPageDAO = contentPageDAO; 89 } 90 91 96 public void setPageDAO(PageDAO pageDAO) { 97 this.pageDAO = pageDAO; 98 } 99 100 105 public void setLayoutDAO(LayoutDAO layoutDAO) { 106 this.layoutDAO = layoutDAO; 107 } 108 109 114 public void setUtilManager(UtilManager utilManager) { 115 this.utilManager = utilManager; 116 } 117 118 119 121 124 public PartialCollection listLinkableItems(QueryInfo queryInfo) { 125 return pageDAO.listLinkableItems(queryInfo); 126 } 127 128 130 132 135 public Long createContentPage(ContentPage contentPage, Long layoutId) throws BeanAlreadyExistsException, BeanNotFoundException { 136 137 if ( log.isDebugEnabled() ) { 138 log.debug("Creating new content page..."); 139 } 140 141 Layout layout = null; 142 layout = layoutDAO.retrieveLayout(layoutId); 143 144 if ( layout == null ) { 145 String errorMessage = "Layout with ID=" + layoutId + " does not exist"; 147 if ( log.isErrorEnabled() ) { 148 log.error(errorMessage); 149 } 150 throw new OwnerNotFoundException(errorMessage); 151 } 152 153 if ( pageDAO.hasDuplicates(contentPage) ) { 154 throw new BeanAlreadyExistsException("Content page with the same URI already exists"); 155 } 156 157 Long contentPageId = contentPageDAO.createContentPage(contentPage, layout); 159 160 if ( log.isDebugEnabled() ) { 161 log.debug("New content page has been created successfully. Its ID is " + contentPageId); 162 } 163 return contentPageId; 164 } 165 166 169 public ContentPage retrieveContentPage(Long contentPageId) { 170 ContentPage contentPage = null; 171 contentPage = contentPageDAO.retrieveContentPage(contentPageId); 172 return contentPage; 173 } 174 175 178 public void updateContentPage(ContentPage contentPage, Long layoutId) throws BeanAlreadyExistsException, BeanNotFoundException { 179 180 contentPageDAO.removeFromCache(contentPage); 182 183 if ( log.isDebugEnabled() ) { 184 log.debug("Updating content page..."); 185 } 186 187 Layout layout = layoutDAO.retrieveLayout(layoutId); 188 189 if ( layout == null ) { 190 String errorMessage = "Layout with ID=" + layoutId + " does not exist"; 192 if ( log.isErrorEnabled() ) { 193 log.error(errorMessage); 194 } 195 throw new OwnerNotFoundException(errorMessage); 196 } 197 198 if ( pageDAO.hasDuplicates(contentPage) ) { 199 throw new BeanAlreadyExistsException("Content page with the same URI already exists"); 200 } 201 202 ContentPage oldContentPage = contentPageDAO.retrieveContentPage(contentPage.getId()); 204 if (oldContentPage != null) { 205 String oldUri = oldContentPage.getUri(); 206 String newUri = contentPage.getUri(); 207 if (!newUri.equals(oldUri)) { 208 utilManager.replaceLinkableObjectUriInLinkedObjects(oldUri, newUri, oldContentPage.getLinkedContentFieldValues(), oldContentPage.getLinkedMenuItems(), Constants.LOCALIZED_URI_PREFIX, false); 209 } 210 contentPageDAO.removeFromCache(oldContentPage); 211 } 212 213 contentPageDAO.updateContentPage(contentPage, layout); 214 215 if ( log.isDebugEnabled() ) { 216 log.debug("Content page was updated successfully."); 217 } 218 } 219 220 223 public void deleteContentPage(Long contentPageId) throws BeanNotFoundException, DeleteException { 224 225 ContentPage contentPage = contentPageDAO.retrieveContentPage(contentPageId); 226 if ( contentPage == null ) { 227 String errorMessage = "Content page with ID=" + contentPageId + " does not exist"; 229 throw new BeanNotFoundException(errorMessage); 230 } 231 232 contentPageDAO.deleteContentPage(contentPage); 233 if ( log.isDebugEnabled() ) { 234 log.debug("Deleted content page: ID=" + contentPageId); 235 } 236 } 237 238 240 243 public PartialCollection listContentPages(QueryInfo queryInfo) { 244 return contentPageDAO.listContentPages(queryInfo); 245 } 246 247 249 252 public ContentPage findContentPageByUri(String contentPageUri) { 253 ContentPage contentPage = null; 254 contentPage = contentPageDAO.findContentPageByUri(contentPageUri); 255 return contentPage; 256 } 257 258 260 262 265 public Long createActionPage(ActionPage actionPage) throws BeanAlreadyExistsException { 266 267 if ( log.isDebugEnabled() ) { 268 log.debug("Creating new action page..."); 269 } 270 271 if ( pageDAO.hasDuplicates(actionPage) ) { 272 throw new BeanAlreadyExistsException("Action page with the same URI already exists"); 273 } 274 275 Long actionPageId = actionPageDAO.createActionPage(actionPage); 277 if ( log.isDebugEnabled() ) { 278 log.debug("New action page has been created successfully. Its ID is " + actionPageId); 279 } 280 return actionPageId; 281 } 282 283 286 public ActionPage retrieveActionPage(Long actionPageId) { 287 return actionPageDAO.retrieveActionPage(actionPageId); 288 } 289 290 293 public void updateActionPage(ActionPage actionPage) throws BeanAlreadyExistsException { 294 295 actionPageDAO.removeFromCache(actionPage); 296 297 if ( log.isDebugEnabled() ) { 298 log.debug("Updating action page..."); 299 } 300 301 if ( pageDAO.hasDuplicates(actionPage) ) { 302 throw new BeanAlreadyExistsException("Action page with the same URI already exists"); 303 } 304 305 ActionPage oldActionPage = actionPageDAO.retrieveActionPage(actionPage.getId()); 307 if (oldActionPage != null) { 308 String oldUri = oldActionPage.getUri(); 309 String newUri = actionPage.getUri(); 310 if (!newUri.equals(oldUri)) { 311 utilManager.replaceLinkableObjectUriInLinkedObjects(oldUri, newUri, oldActionPage.getLinkedContentFieldValues(), oldActionPage.getLinkedMenuItems(), Constants.LOCALIZED_URI_PREFIX, false); 312 } 313 contentPageDAO.removeFromCache(oldActionPage); 314 } 315 316 actionPageDAO.updateActionPage(actionPage); 317 318 if ( log.isDebugEnabled() ) { 319 log.debug("Action page was updated successfully."); 320 } 321 } 322 323 326 public void deleteActionPage(Long actionPageId) throws DeleteException, BeanNotFoundException { 327 ActionPage actionPage = actionPageDAO.retrieveActionPage(actionPageId); 328 if ( actionPage == null ) { 329 String errorMessage = "No content resource with ID=" + actionPage + "could be found"; 330 throw new BeanNotFoundException(errorMessage); 331 } 332 333 actionPageDAO.deleteActionPage(actionPage); 334 335 if ( log.isDebugEnabled() ) { 336 log.debug("Deleted action page: ID=" + actionPageId); 337 } 338 } 339 340 342 345 public PartialCollection listActionPages(QueryInfo queryInfo) { 346 return actionPageDAO.listActionPages(queryInfo); 347 } 348 349 351 354 public ActionPage findActionPageByUri(String actionPageUri) { 355 ActionPage actionPage = null; 356 actionPage = actionPageDAO.findActionPageByUri(actionPageUri); 357 return actionPage; 358 } 359 360 361 363 366 public Page findPageByUri(String pageUri) { 367 Page page = null; 368 page = pageDAO.findPageByUri(pageUri); 369 return page; 370 } 371 372 375 public Page retrievePage(Long pageId) { 376 Page page = null; 377 page = pageDAO.retrievePage(pageId); 378 return page; 379 } 380 381 384 public Collection listPagesFetching() { 385 return pageDAO.listPagesFetching(); 386 } 387 388 391 public void increaseUsageCounter(Long pageId, Integer value) throws BeanNotFoundException { 392 Page page = pageDAO.retrievePage(pageId); 393 394 if ( page == null ) { 395 String errorMessage = "Page with ID=" + pageId + " does not exist"; 397 if ( log.isErrorEnabled() ) { 398 log.error(errorMessage); 399 } 400 throw new BeanNotFoundException(errorMessage); 401 } 402 403 page.setUsageCounter(new Integer (page.getUsageCounter().intValue() + value.intValue())); 404 pageDAO.updatePage(page); 405 } 406 } 407 | Popular Tags |