KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > service > testimonials > impl > TestimonialManagerImpl


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
30
31 /**
32  * <p>Implementation of TestimonialManager</p>
33  * <p><a HREF="TestimonialManagerImpl.java.htm"><i>View Source</i></a>
34  * </p>
35  *
36  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
37  * @version $Revision: 1.2 $ $Date: 2005/08/02 14:53:43 $
38  */

39 public class TestimonialManagerImpl extends PageManagerImpl implements TestimonialManager {
40
41     /**
42      * Testimonial DAO
43      */

44     protected TestimonialDAO testimonialDAO;
45     /**
46      * Page DAO
47      */

48     protected PageDAO pageDAO;
49
50     /**
51      * Creates new instance of PageManagerImpl
52      */

53     public TestimonialManagerImpl() {
54     }
55
56     /**
57      * Sets DAO for operations with testimonials
58      *
59      * @param testimonialDAO the DAO to set
60      */

61     public void setTestimonialDAO(TestimonialDAO testimonialDAO) {
62         this.testimonialDAO = testimonialDAO;
63     }
64
65     /**
66      * Sets DAO for operations with pages
67      *
68      * @param pageDAO the DAO to set
69      */

70     public void setPageDAO(PageDAO pageDAO) {
71         this.pageDAO = pageDAO;
72     }
73
74     //~ CRUD Methods ================================================================
75

76     /**
77      * @see com.blandware.atleap.service.testimonials.TestimonialManager#createTestimonial(com.blandware.atleap.model.testimonials.Testimonial, java.util.Map)
78      */

79     public Long JavaDoc createTestimonial(Testimonial testimonial, Map JavaDoc linkedObjects) throws BeanAlreadyExistsException {
80
81         if ( log.isDebugEnabled() ) {
82             log.debug("Creating new testimonial item...");
83         }
84
85         if ( pageDAO.hasDuplicates(testimonial) ) {
86             // linkable item already exists
87
String JavaDoc 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         // linkable item does not exist
95
Long JavaDoc 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     /**
103      * @see com.blandware.atleap.service.testimonials.TestimonialManager#retrieveTestimonial(Long)
104      */

105     public Testimonial retrieveTestimonial(Long JavaDoc testimonialId) {
106         Testimonial testimonial = null;
107         testimonial = testimonialDAO.retrieveTestimonial(testimonialId);
108
109         return testimonial;
110     }
111
112     /**
113      * @see com.blandware.atleap.service.testimonials.TestimonialManager#retrieveTestimonialLite(Long)
114      */

115     public Testimonial retrieveTestimonialLite(Long JavaDoc testimonialId) {
116         return testimonialDAO.retrieveTestimonialLite(testimonialId);
117     }
118
119     /**
120      * @see com.blandware.atleap.service.testimonials.TestimonialManager#updateTestimonial(com.blandware.atleap.model.testimonials.Testimonial, java.util.Map)
121      */

122     public void updateTestimonial(Testimonial testimonial, Map JavaDoc linkedObjects) throws BeanAlreadyExistsException {
123
124         // remove testimonial from cache in order to prevent Hibernate from assigning new version number
125
testimonialDAO.removeFromCache(testimonial);
126
127         if ( log.isDebugEnabled() ) {
128             log.debug("Updating testimonial item...");
129         }
130
131         if ( pageDAO.hasDuplicates(testimonial) ) {
132             // linkable item already exists
133
String JavaDoc 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         // linkable item does not exist
141
testimonialDAO.updateTestimonial(testimonial, linkedObjects);
142
143         if ( log.isDebugEnabled() ) {
144             log.debug("Testimonial item was updated successfully.");
145         }
146     }
147
148     /**
149      * @see com.blandware.atleap.service.testimonials.TestimonialManager#updateTestimonial(com.blandware.atleap.model.testimonials.Testimonial)
150      */

151     public void updateTestimonial(Testimonial testimonial) throws BeanAlreadyExistsException {
152         updateTestimonial(testimonial, null);
153     }
154
155     /**
156      * @see com.blandware.atleap.service.testimonials.TestimonialManager#deleteTestimonial(Long)
157      */

158     public void deleteTestimonial(Long JavaDoc testimonialId) throws DeleteException, BeanNotFoundException {
159         Testimonial testimonial = testimonialDAO.retrieveTestimonial(testimonialId);
160         if ( testimonial == null ) {
161             String JavaDoc 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     // ~ Additional methods ================================================================
171

172     /**
173      * @see com.blandware.atleap.service.testimonials.TestimonialManager#listTestimonials(com.blandware.atleap.common.util.QueryInfo)
174      */

175     public PartialCollection listTestimonials(QueryInfo queryInfo) {
176         return testimonialDAO.listTestimonials(queryInfo);
177     }
178
179     /**
180      * @see com.blandware.atleap.service.testimonials.TestimonialManager#getRandomTestimonial()
181      */

182     public Testimonial getRandomTestimonial() {
183         return testimonialDAO.getRandomTestimonial();
184     }
185
186 }
187
Popular Tags