1 16 package com.blandware.atleap.service.testimonials.impl; 17 18 import com.blandware.atleap.common.util.PartialCollection; 19 import com.blandware.atleap.common.util.QueryInfo; 20 import com.blandware.atleap.model.testimonials.Testimonial; 21 import com.blandware.atleap.persistence.core.PageDAO; 22 import com.blandware.atleap.persistence.exception.DeleteException; 23 import com.blandware.atleap.persistence.testimonials.TestimonialDAO; 24 import com.blandware.atleap.service.core.impl.PageManagerImpl; 25 import com.blandware.atleap.service.exception.BeanAlreadyExistsException; 26 import com.blandware.atleap.service.exception.BeanNotFoundException; 27 import com.blandware.atleap.service.testimonials.TestimonialManager; 28 29 import java.util.Map ; 30 31 39 public class TestimonialManagerImpl extends PageManagerImpl implements TestimonialManager { 40 41 44 protected TestimonialDAO testimonialDAO; 45 48 protected PageDAO pageDAO; 49 50 53 public TestimonialManagerImpl() { 54 } 55 56 61 public void setTestimonialDAO(TestimonialDAO testimonialDAO) { 62 this.testimonialDAO = testimonialDAO; 63 } 64 65 70 public void setPageDAO(PageDAO pageDAO) { 71 this.pageDAO = pageDAO; 72 } 73 74 76 79 public Long createTestimonial(Testimonial testimonial, Map linkedObjects) throws BeanAlreadyExistsException { 80 81 if ( log.isDebugEnabled() ) { 82 log.debug("Creating new testimonial item..."); 83 } 84 85 if ( pageDAO.hasDuplicates(testimonial) ) { 86 String errorMessage = "Linkable item with URI '" + testimonial.getUri() + "' already exists"; 88 if ( log.isErrorEnabled() ) { 89 log.error(errorMessage); 90 } 91 throw new BeanAlreadyExistsException(errorMessage); 92 } 93 94 Long testimonialId = testimonialDAO.createTestimonial(testimonial, linkedObjects); 96 if ( log.isDebugEnabled() ) { 97 log.debug("New testimonial item has been created successfully. Its ID is " + testimonialId); 98 } 99 return testimonialId; 100 } 101 102 105 public Testimonial retrieveTestimonial(Long testimonialId) { 106 Testimonial testimonial = null; 107 testimonial = testimonialDAO.retrieveTestimonial(testimonialId); 108 109 return testimonial; 110 } 111 112 115 public Testimonial retrieveTestimonialLite(Long testimonialId) { 116 return testimonialDAO.retrieveTestimonialLite(testimonialId); 117 } 118 119 122 public void updateTestimonial(Testimonial testimonial, Map linkedObjects) throws BeanAlreadyExistsException { 123 124 testimonialDAO.removeFromCache(testimonial); 126 127 if ( log.isDebugEnabled() ) { 128 log.debug("Updating testimonial item..."); 129 } 130 131 if ( pageDAO.hasDuplicates(testimonial) ) { 132 String errorMessage = "Linkable item with URI '" + testimonial.getUri() + "' already exists"; 134 if ( log.isErrorEnabled() ) { 135 log.error(errorMessage); 136 } 137 throw new BeanAlreadyExistsException(errorMessage); 138 } 139 140 testimonialDAO.updateTestimonial(testimonial, linkedObjects); 142 143 if ( log.isDebugEnabled() ) { 144 log.debug("Testimonial item was updated successfully."); 145 } 146 } 147 148 151 public void updateTestimonial(Testimonial testimonial) throws BeanAlreadyExistsException { 152 updateTestimonial(testimonial, null); 153 } 154 155 158 public void deleteTestimonial(Long testimonialId) throws DeleteException, BeanNotFoundException { 159 Testimonial testimonial = testimonialDAO.retrieveTestimonial(testimonialId); 160 if ( testimonial == null ) { 161 String errorMessage = "Testimonial item with ID=" + testimonialId + " does not exist"; 162 throw new BeanNotFoundException(errorMessage); 163 } 164 testimonialDAO.deleteTestimonial(testimonial); 165 if ( log.isDebugEnabled() ) { 166 log.debug("Deleted testimonial item: ID=" + testimonialId); 167 } 168 } 169 170 172 175 public PartialCollection listTestimonials(QueryInfo queryInfo) { 176 return testimonialDAO.listTestimonials(queryInfo); 177 } 178 179 182 public Testimonial getRandomTestimonial() { 183 return testimonialDAO.getRandomTestimonial(); 184 } 185 186 } 187 | Popular Tags |