KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > service > core > impl > PageManagerImpl


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.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 JavaDoc;
34
35 /**
36  * <p>Implementation of PageManager</p>
37  * <p><a HREF="PageManagerImpl.java.htm"><i>View Source</i></a>
38  * </p>
39  *
40  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
41  * @version $Revision: 1.16 $ $Date: 2005/10/10 08:30:01 $
42  */

43 public class PageManagerImpl extends BaseManagerImpl implements PageManager {
44
45     /**
46      * Action page DAO
47      */

48     protected ActionPageDAO actionPageDAO;
49     /**
50      * Content page DAO
51      */

52     protected ContentPageDAO contentPageDAO;
53     /**
54      * Page DAO
55      */

56     protected PageDAO pageDAO;
57     /**
58      * Layout DAO
59      */

60     protected LayoutDAO layoutDAO;
61
62     /**
63      * Util manager to use
64      */

65     protected UtilManager utilManager;
66
67     /**
68      * Creates new instance of PageManagerImpl
69      */

70     public PageManagerImpl() {
71     }
72
73     /**
74      * Sets DAO to operate with action pages
75      *
76      * @param actionPageDAO the DAO to set
77      */

78     public void setActionPageDAO(ActionPageDAO actionPageDAO) {
79         this.actionPageDAO = actionPageDAO;
80     }
81
82     /**
83      * Sets DAO to operate with content pages
84      *
85      * @param contentPageDAO the DAO to set
86      */

87     public void setContentPageDAO(ContentPageDAO contentPageDAO) {
88         this.contentPageDAO = contentPageDAO;
89     }
90
91     /**
92      * Sets DAO to operate with pages
93      *
94      * @param pageDAO the DAO to set
95      */

96     public void setPageDAO(PageDAO pageDAO) {
97         this.pageDAO = pageDAO;
98     }
99
100     /**
101      * Sets DAO for operating with layouts
102      *
103      * @param layoutDAO the DAO to set
104      */

105     public void setLayoutDAO(LayoutDAO layoutDAO) {
106         this.layoutDAO = layoutDAO;
107     }
108
109     /**
110      * Sets util manager to use
111      *
112      * @param utilManager manager to set
113      */

114     public void setUtilManager(UtilManager utilManager) {
115         this.utilManager = utilManager;
116     }
117
118
119     // L I N K A B L E I T E M S
120

121     /**
122      * @see com.blandware.atleap.service.core.PageManager#createContentPage(com.blandware.atleap.model.core.ContentPage, java.lang.Long)
123      */

124     public PartialCollection listLinkableItems(QueryInfo queryInfo) {
125         return pageDAO.listLinkableItems(queryInfo);
126     }
127
128     // C O N T E N T P A G E S
129

130     //~ CRUD Methods ================================================================
131

132     /**
133      * @see com.blandware.atleap.service.core.PageManager#createContentPage(com.blandware.atleap.model.core.ContentPage, java.lang.Long)
134      */

135     public Long JavaDoc createContentPage(ContentPage contentPage, Long JavaDoc 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             // layout does not exist
146
String JavaDoc 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         // page does not exist so create it
158
Long JavaDoc 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     /**
167      * @see com.blandware.atleap.service.core.PageManager#retrieveContentPage(java.lang.Long)
168      */

169     public ContentPage retrieveContentPage(Long JavaDoc contentPageId) {
170         ContentPage contentPage = null;
171         contentPage = contentPageDAO.retrieveContentPage(contentPageId);
172         return contentPage;
173     }
174
175     /**
176      * @see com.blandware.atleap.service.core.PageManager#updateContentPage(com.blandware.atleap.model.core.ContentPage, Long layoutId)
177      */

178     public void updateContentPage(ContentPage contentPage, Long JavaDoc layoutId) throws BeanAlreadyExistsException, BeanNotFoundException {
179
180         // remove page from cache in order to prevent Hibernate from assigning new version number
181
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             // layout does not exist
191
String JavaDoc 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         // page with given URI does not exist
203
ContentPage oldContentPage = contentPageDAO.retrieveContentPage(contentPage.getId());
204         if (oldContentPage != null) {
205             String JavaDoc oldUri = oldContentPage.getUri();
206             String JavaDoc 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     /**
221      * @see com.blandware.atleap.service.core.PageManager#deleteContentPage(java.lang.Long)
222      */

223     public void deleteContentPage(Long JavaDoc contentPageId) throws BeanNotFoundException, DeleteException {
224
225         ContentPage contentPage = contentPageDAO.retrieveContentPage(contentPageId);
226         if ( contentPage == null ) {
227             // content page does not exist
228
String JavaDoc 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     // ~ Additional methods ================================================================
239

240     /**
241      * @see com.blandware.atleap.service.core.PageManager#listContentPages(com.blandware.atleap.common.util.QueryInfo)
242      */

243     public PartialCollection listContentPages(QueryInfo queryInfo) {
244         return contentPageDAO.listContentPages(queryInfo);
245     }
246
247     // ~ Finders ================================================================
248

249     /**
250      * @see com.blandware.atleap.service.core.PageManager#findContentPageByUri(java.lang.String)
251      */

252     public ContentPage findContentPageByUri(String JavaDoc contentPageUri) {
253         ContentPage contentPage = null;
254         contentPage = contentPageDAO.findContentPageByUri(contentPageUri);
255         return contentPage;
256     }
257
258     // A C T I O N P A G E S
259

260     //~ CRUD Methods ================================================================
261

262     /**
263      * @see com.blandware.atleap.service.core.PageManager#createActionPage(com.blandware.atleap.model.core.ActionPage)
264      */

265     public Long JavaDoc 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         // page does not exist
276
Long JavaDoc 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     /**
284      * @see com.blandware.atleap.service.core.PageManager#retrieveActionPage(java.lang.Long)
285      */

286     public ActionPage retrieveActionPage(Long JavaDoc actionPageId) {
287         return actionPageDAO.retrieveActionPage(actionPageId);
288     }
289
290     /**
291      * @see com.blandware.atleap.service.core.PageManager#updateActionPage(com.blandware.atleap.model.core.ActionPage)
292      */

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         // page with that URI does not exist
306
ActionPage oldActionPage = actionPageDAO.retrieveActionPage(actionPage.getId());
307         if (oldActionPage != null) {
308             String JavaDoc oldUri = oldActionPage.getUri();
309             String JavaDoc 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     /**
324      * @see com.blandware.atleap.service.core.PageManager#deleteActionPage(java.lang.Long)
325      */

326     public void deleteActionPage(Long JavaDoc actionPageId) throws DeleteException, BeanNotFoundException {
327         ActionPage actionPage = actionPageDAO.retrieveActionPage(actionPageId);
328         if ( actionPage == null ) {
329             String JavaDoc 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     // ~ Additional methods ================================================================
341

342     /**
343      * @see com.blandware.atleap.service.core.PageManager#listActionPages(com.blandware.atleap.common.util.QueryInfo)
344      */

345     public PartialCollection listActionPages(QueryInfo queryInfo) {
346         return actionPageDAO.listActionPages(queryInfo);
347     }
348
349     // ~ Finders ================================================================
350

351     /**
352      * @see com.blandware.atleap.service.core.PageManager#findActionPageByUri(java.lang.String)
353      */

354     public ActionPage findActionPageByUri(String JavaDoc actionPageUri) {
355         ActionPage actionPage = null;
356         actionPage = actionPageDAO.findActionPageByUri(actionPageUri);
357         return actionPage;
358     }
359
360
361     // P A G E S
362

363     /**
364      * @see com.blandware.atleap.service.core.PageManager#findPageByUri(java.lang.String)
365      */

366     public Page findPageByUri(String JavaDoc pageUri) {
367         Page page = null;
368         page = pageDAO.findPageByUri(pageUri);
369         return page;
370     }
371
372     /**
373      * @see com.blandware.atleap.service.core.PageManager#retrievePage(java.lang.Long)
374      */

375     public Page retrievePage(Long JavaDoc pageId) {
376         Page page = null;
377         page = pageDAO.retrievePage(pageId);
378         return page;
379     }
380
381     /**
382      * @see com.blandware.atleap.service.core.PageManager#listPagesFetching()
383      */

384     public Collection listPagesFetching() {
385         return pageDAO.listPagesFetching();
386     }
387
388     /**
389      * @see com.blandware.atleap.service.core.PageManager#increaseUsageCounter(java.lang.Long, java.lang.Integer)
390      */

391     public void increaseUsageCounter(Long JavaDoc pageId, Integer JavaDoc value) throws BeanNotFoundException {
392         Page page = pageDAO.retrievePage(pageId);
393
394         if ( page == null ) {
395             // page does not exist
396
String JavaDoc 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 JavaDoc(page.getUsageCounter().intValue() + value.intValue()));
404         pageDAO.updatePage(page);
405     }
406 }
407
Popular Tags