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.Layout; 21 import com.blandware.atleap.persistence.core.LayoutDAO; 22 import com.blandware.atleap.persistence.exception.DeleteException; 23 import com.blandware.atleap.persistence.exception.UpdateException; 24 import com.blandware.atleap.service.core.LayoutManager; 25 import com.blandware.atleap.service.exception.BeanAlreadyExistsException; 26 import com.blandware.atleap.service.exception.BeanNotFoundException; 27 28 36 public class LayoutManagerImpl extends BaseManagerImpl implements LayoutManager { 37 38 40 41 44 protected LayoutDAO layoutDAO; 45 46 48 53 public void setLayoutDAO(LayoutDAO layoutDAO) { 54 this.layoutDAO = layoutDAO; 55 } 56 57 60 public Long createLayout(Layout layout) throws BeanAlreadyExistsException { 61 if ( log.isDebugEnabled() ) { 62 log.debug("Creating new layout..."); 63 } 64 65 if ( layoutDAO.hasDuplicates(layout) ) { 66 throw new BeanAlreadyExistsException("Layout with the same name or definition already exists"); 67 } 68 69 Long layoutId = layoutDAO.createLayout(layout); 70 if ( log.isDebugEnabled() ) { 71 log.debug("Layout has been created successfully. Its ID is " + layoutId); 72 } 73 return layoutId; 74 } 75 76 79 public Layout retrieveLayout(Long layoutId) { 80 Layout layout = null; 81 layout = layoutDAO.retrieveLayout(layoutId); 82 return layout; 83 } 84 85 88 public void updateLayout(Layout layout) throws BeanAlreadyExistsException, BeanNotFoundException, UpdateException { 89 layoutDAO.removeFromCache(layout); 91 if ( log.isDebugEnabled() ) { 92 log.debug("Updating layout with ID=" + layout.getId()); 93 } 94 95 if ( layoutDAO.hasDuplicates(layout) ) { 96 throw new BeanAlreadyExistsException("Layout with the same name or definition already exists"); 97 } 98 99 layoutDAO.updateLayout(layout); 101 102 103 } 104 105 108 public void deleteLayout(Long layoutId) throws DeleteException, BeanNotFoundException { 109 Layout layout = layoutDAO.retrieveLayout(layoutId); 110 if ( layout == null ) { 111 String errorMessage = "No content resource with ID=" + layout + "could be found"; 112 throw new BeanNotFoundException(errorMessage); 113 } 114 layoutDAO.deleteLayout(layout); 115 } 116 117 119 122 public PartialCollection listLayouts(QueryInfo queryInfo) { 123 return layoutDAO.listLayouts(queryInfo); 124 } 125 126 128 131 public Layout findLayoutByContentPageUri(String contentPageUri) { 132 133 135 if ( log.isDebugEnabled() ) { 136 log.debug("Looking for layout by content page uri: " + contentPageUri); 137 } 138 Layout layout = null; 139 layout = layoutDAO.findLayoutByContentPageUri(contentPageUri); 140 return layout; 141 } 142 143 146 public Layout findLayoutByDefinition(String definitionName) { 147 Layout layout = null; 148 layout = layoutDAO.findLayoutByDefinition(definitionName); 149 return layout; 150 } 151 152 155 public Layout findLayoutByName(String name) { 156 Layout layout = null; 157 layout = layoutDAO.findLayoutByName(name); 158 return layout; 159 } 160 } 161 | Popular Tags |