1 23 24 package org.infoglue.cms.controllers.usecases.structuretool.impl.simple; 25 26 import java.util.Collection ; 27 import java.util.List ; 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 54 55 public SiteNodeVO getRootSiteNode(Integer 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 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 (true)); 84 rootSiteNodeVO.setMetaInfoContentId(new Integer (-1)); 85 SiteNode siteNode = SiteNodeController.getController().create(db, null, null, infoGluePrincipal, repositoryId, rootSiteNodeVO); 86 siteNodeVO = siteNode.getValueObject(); 89 SiteNodeVO newSiteNodeVO = siteNodeVO; 90 91 SiteNodeController.getController().createSiteNodeMetaInfoContent(db, siteNode, repositoryId, infoGluePrincipal, null); 93 } 94 95 results.close(); 96 oql.close(); 97 98 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 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 siteNodeId) throws ConstraintException, SystemException 120 { 121 return SiteNodeController.getSiteNodeVOWithId(siteNodeId); 122 154 } 155 156 157 public List getSiteNodeChildren(Integer parentSiteNodeId) throws ConstraintException, SystemException 158 { 159 Database db = CastorDatabaseService.getDatabase(); 160 ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); 161 162 List childrenVOList = null; 163 164 beginTransaction(db); 165 166 try 167 { 168 SiteNode siteNode = SiteNodeController.getSiteNodeWithId(parentSiteNodeId, db, true); 169 Collection children = siteNode.getChildSiteNodes(); 170 childrenVOList = SiteNodeController.toVOList(children); 171 172 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 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 |