KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > controllers > usecases > structuretool > impl > simple > ViewSiteNodeTreeUCCImpl


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.controllers.usecases.structuretool.impl.simple;
25
26 import java.util.Collection JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.apache.log4j.Logger;
30 import org.exolab.castor.jdo.Database;
31 import org.exolab.castor.jdo.OQLQuery;
32 import org.exolab.castor.jdo.QueryResults;
33 import org.infoglue.cms.controllers.kernel.impl.simple.BaseUCCController;
34 import org.infoglue.cms.controllers.kernel.impl.simple.CastorDatabaseService;
35 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController;
36 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController;
37 import org.infoglue.cms.controllers.usecases.structuretool.ViewSiteNodeTreeUCC;
38 import org.infoglue.cms.entities.management.Repository;
39 import org.infoglue.cms.entities.structure.SiteNode;
40 import org.infoglue.cms.entities.structure.SiteNodeVO;
41 import org.infoglue.cms.exception.ConstraintException;
42 import org.infoglue.cms.exception.SystemException;
43 import org.infoglue.cms.security.InfoGluePrincipal;
44 import org.infoglue.cms.util.ConstraintExceptionBuffer;
45
46 public class ViewSiteNodeTreeUCCImpl extends BaseUCCController implements ViewSiteNodeTreeUCC
47 {
48     private final static Logger logger = Logger.getLogger(ViewSiteNodeTreeUCCImpl.class.getName());
49
50     /**
51      * This method fetches the root siteNode for a particular repository.
52      * If there is no such siteNode we create one as all repositories need one to work.
53      */

54             
55     public SiteNodeVO getRootSiteNode(Integer JavaDoc repositoryId, InfoGluePrincipal infoGluePrincipal) throws ConstraintException, SystemException
56     {
57         Database db = CastorDatabaseService.getDatabase();
58         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
59
60         SiteNodeVO siteNodeVO = null;
61
62         beginTransaction(db);
63
64         try
65         {
66             logger.info("Fetching the root siteNode for the repository " + repositoryId);
67             OQLQuery oql = db.getOQLQuery( "SELECT c FROM org.infoglue.cms.entities.structure.impl.simple.SiteNodeImpl c WHERE is_undefined(c.parentSiteNode) AND c.repository.repositoryId = $1");
68             oql.bind(repositoryId);
69             
70             QueryResults results = oql.execute(Database.ReadOnly);
71             
72             if (results.hasMore())
73             {
74                 siteNodeVO = ((SiteNode)results.next()).getValueObject();
75             }
76             else
77             {
78                 //None found - we create it and give it the name of the repository.
79
logger.info("Found no rootSiteNode so we create a new....");
80                 SiteNodeVO rootSiteNodeVO = new SiteNodeVO();
81                 Repository repository = RepositoryController.getController().getRepositoryWithId(repositoryId, db);
82                 rootSiteNodeVO.setName(repository.getName());
83                 rootSiteNodeVO.setIsBranch(new Boolean JavaDoc(true));
84                 rootSiteNodeVO.setMetaInfoContentId(new Integer JavaDoc(-1));
85                 SiteNode siteNode = SiteNodeController.getController().create(db, null, null, infoGluePrincipal, repositoryId, rootSiteNodeVO);
86                 //siteNodeVO = SiteNodeController.getController().create(null, null, infoGluePrincipal, repositoryId, siteNodeVO);
87
//siteNodeVO = SiteNodeControllerProxy.getSiteNodeControllerProxy().acCreate(infoGluePrincipal, null, null, repositoryId, rootSiteNodeVO);
88
siteNodeVO = siteNode.getValueObject();
89                 SiteNodeVO newSiteNodeVO = siteNodeVO;
90                 
91                 //Also creates an initial meta info for the sitenode.
92
SiteNodeController.getController().createSiteNodeMetaInfoContent(db, siteNode, repositoryId, infoGluePrincipal, null);
93             }
94             
95             results.close();
96             oql.close();
97             
98             //If any of the validations or setMethods reported an error, we throw them up now before create.
99
ceb.throwIfNotEmpty();
100             
101             commitTransaction(db);
102         }
103         catch(ConstraintException ce)
104         {
105             logger.warn("An error occurred so we should not complete the transaction:" + ce, ce);
106             rollbackTransaction(db);
107             throw ce;
108         }
109         catch(Exception JavaDoc e)
110         {
111             logger.error("An error occurred so we should not complete the transaction:" + e, e);
112             rollbackTransaction(db);
113             throw new SystemException(e.getMessage());
114         }
115
116         return siteNodeVO;
117     }
118     
119     public SiteNodeVO getSiteNode(Integer JavaDoc siteNodeId) throws ConstraintException, SystemException
120     {
121         return SiteNodeController.getSiteNodeVOWithId(siteNodeId);
122         /*
123         Database db = CastorDatabaseService.getDatabase();
124         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
125
126         SiteNode siteNode = null;
127
128         beginTransaction(db);
129
130         try
131         {
132             siteNode = SiteNodeController.getSiteNodeVOWithId(siteNodeId);
133         
134             //If any of the validations or setMethods reported an error, we throw them up now before create.
135             ceb.throwIfNotEmpty();
136             
137             commitTransaction(db);
138         }
139         catch(ConstraintException ce)
140         {
141             logger.warn("An error occurred so we should not complete the transaction:" + ce, ce);
142             rollbackTransaction(db);
143             throw ce;
144         }
145         catch(Exception e)
146         {
147             logger.error("An error occurred so we should not complete the transaction:" + e, e);
148             rollbackTransaction(db);
149             throw new SystemException(e.getMessage());
150         }
151
152         return siteNode.getValueObject();
153         */

154     }
155
156
157     public List JavaDoc getSiteNodeChildren(Integer JavaDoc parentSiteNodeId) throws ConstraintException, SystemException
158     {
159         Database db = CastorDatabaseService.getDatabase();
160         ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
161
162         List JavaDoc childrenVOList = null;
163
164         beginTransaction(db);
165
166         try
167         {
168             SiteNode siteNode = SiteNodeController.getSiteNodeWithId(parentSiteNodeId, db, true);
169             Collection JavaDoc children = siteNode.getChildSiteNodes();
170             childrenVOList = SiteNodeController.toVOList(children);
171             
172             //If any of the validations or setMethods reported an error, we throw them up now before create.
173
ceb.throwIfNotEmpty();
174             
175             commitTransaction(db);
176         }
177         catch(ConstraintException ce)
178         {
179             logger.warn("An error occurred so we should not complete the transaction:" + ce, ce);
180             rollbackTransaction(db);
181             throw ce;
182         }
183         catch(Exception JavaDoc e)
184         {
185             logger.error("An error occurred so we should not complete the transaction:" + e, e);
186             rollbackTransaction(db);
187             throw new SystemException(e.getMessage());
188         }
189         
190         return childrenVOList;
191     }
192 }
193         
194
Popular Tags